snow-ai 0.4.16 → 0.4.18
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/bundle/cli.mjs +477445 -0
- package/bundle/sql-wasm.wasm +0 -0
- package/bundle/tiktoken_bg.wasm +0 -0
- package/package.json +31 -26
- package/dist/agents/codebaseIndexAgent.d.ts +0 -102
- package/dist/agents/codebaseIndexAgent.js +0 -641
- package/dist/agents/codebaseReviewAgent.d.ts +0 -61
- package/dist/agents/codebaseReviewAgent.js +0 -301
- package/dist/agents/compactAgent.d.ts +0 -55
- package/dist/agents/compactAgent.js +0 -306
- package/dist/agents/promptOptimizeAgent.d.ts +0 -54
- package/dist/agents/promptOptimizeAgent.js +0 -268
- package/dist/agents/reviewAgent.d.ts +0 -50
- package/dist/agents/reviewAgent.js +0 -265
- package/dist/agents/summaryAgent.d.ts +0 -57
- package/dist/agents/summaryAgent.js +0 -260
- package/dist/api/anthropic.d.ts +0 -44
- package/dist/api/anthropic.js +0 -598
- package/dist/api/chat.d.ts +0 -73
- package/dist/api/chat.js +0 -386
- package/dist/api/embedding.d.ts +0 -34
- package/dist/api/embedding.js +0 -80
- package/dist/api/gemini.d.ts +0 -31
- package/dist/api/gemini.js +0 -445
- package/dist/api/models.d.ts +0 -15
- package/dist/api/models.js +0 -139
- package/dist/api/responses.d.ts +0 -38
- package/dist/api/responses.js +0 -515
- package/dist/api/systemPrompt.d.ts +0 -4
- package/dist/api/systemPrompt.js +0 -408
- package/dist/api/types.d.ts +0 -53
- package/dist/api/types.js +0 -4
- package/dist/app.d.ts +0 -8
- package/dist/app.js +0 -112
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -199
- package/dist/hooks/useAgentPicker.d.ts +0 -14
- package/dist/hooks/useAgentPicker.js +0 -119
- package/dist/hooks/useClipboard.d.ts +0 -4
- package/dist/hooks/useClipboard.js +0 -175
- package/dist/hooks/useCommandHandler.d.ts +0 -35
- package/dist/hooks/useCommandHandler.js +0 -346
- package/dist/hooks/useCommandPanel.d.ts +0 -17
- package/dist/hooks/useCommandPanel.js +0 -114
- package/dist/hooks/useConversation.d.ts +0 -49
- package/dist/hooks/useConversation.js +0 -1052
- package/dist/hooks/useFilePicker.d.ts +0 -18
- package/dist/hooks/useFilePicker.js +0 -224
- package/dist/hooks/useGlobalExit.d.ts +0 -5
- package/dist/hooks/useGlobalExit.js +0 -34
- package/dist/hooks/useGlobalNavigation.d.ts +0 -6
- package/dist/hooks/useGlobalNavigation.js +0 -17
- package/dist/hooks/useHistoryNavigation.d.ts +0 -35
- package/dist/hooks/useHistoryNavigation.js +0 -133
- package/dist/hooks/useInputBuffer.d.ts +0 -6
- package/dist/hooks/useInputBuffer.js +0 -45
- package/dist/hooks/useKeyboardInput.d.ts +0 -80
- package/dist/hooks/useKeyboardInput.js +0 -608
- package/dist/hooks/useSessionManagement.d.ts +0 -10
- package/dist/hooks/useSessionManagement.js +0 -43
- package/dist/hooks/useSessionSave.d.ts +0 -8
- package/dist/hooks/useSessionSave.js +0 -63
- package/dist/hooks/useSnapshotState.d.ts +0 -26
- package/dist/hooks/useSnapshotState.js +0 -28
- package/dist/hooks/useStreamingState.d.ts +0 -33
- package/dist/hooks/useStreamingState.js +0 -105
- package/dist/hooks/useTerminalFocus.d.ts +0 -28
- package/dist/hooks/useTerminalFocus.js +0 -87
- package/dist/hooks/useTerminalSize.d.ts +0 -4
- package/dist/hooks/useTerminalSize.js +0 -20
- package/dist/hooks/useTodoPicker.d.ts +0 -16
- package/dist/hooks/useTodoPicker.js +0 -94
- package/dist/hooks/useToolConfirmation.d.ts +0 -19
- package/dist/hooks/useToolConfirmation.js +0 -61
- package/dist/hooks/useVSCodeState.d.ts +0 -8
- package/dist/hooks/useVSCodeState.js +0 -81
- package/dist/i18n/I18nContext.d.ts +0 -14
- package/dist/i18n/I18nContext.js +0 -24
- package/dist/i18n/index.d.ts +0 -3
- package/dist/i18n/index.js +0 -2
- package/dist/i18n/lang/en.d.ts +0 -2
- package/dist/i18n/lang/en.js +0 -502
- package/dist/i18n/lang/es.d.ts +0 -2
- package/dist/i18n/lang/es.js +0 -502
- package/dist/i18n/lang/ja.d.ts +0 -2
- package/dist/i18n/lang/ja.js +0 -502
- package/dist/i18n/lang/ko.d.ts +0 -2
- package/dist/i18n/lang/ko.js +0 -502
- package/dist/i18n/lang/zh-TW.d.ts +0 -2
- package/dist/i18n/lang/zh-TW.js +0 -502
- package/dist/i18n/lang/zh.d.ts +0 -2
- package/dist/i18n/lang/zh.js +0 -502
- package/dist/i18n/translations.d.ts +0 -2
- package/dist/i18n/translations.js +0 -14
- package/dist/i18n/types.d.ts +0 -478
- package/dist/i18n/types.js +0 -1
- package/dist/mcp/aceCodeSearch.d.ts +0 -247
- package/dist/mcp/aceCodeSearch.js +0 -1058
- package/dist/mcp/bash.d.ts +0 -50
- package/dist/mcp/bash.js +0 -153
- package/dist/mcp/codebaseSearch.d.ts +0 -44
- package/dist/mcp/codebaseSearch.js +0 -275
- package/dist/mcp/filesystem.d.ts +0 -392
- package/dist/mcp/filesystem.js +0 -1445
- package/dist/mcp/ideDiagnostics.d.ts +0 -36
- package/dist/mcp/ideDiagnostics.js +0 -90
- package/dist/mcp/notebook.d.ts +0 -10
- package/dist/mcp/notebook.js +0 -367
- package/dist/mcp/subagent.d.ts +0 -37
- package/dist/mcp/subagent.js +0 -113
- package/dist/mcp/todo.d.ts +0 -46
- package/dist/mcp/todo.js +0 -511
- package/dist/mcp/types/aceCodeSearch.types.d.ts +0 -92
- package/dist/mcp/types/aceCodeSearch.types.js +0 -4
- package/dist/mcp/types/bash.types.d.ts +0 -13
- package/dist/mcp/types/bash.types.js +0 -4
- package/dist/mcp/types/filesystem.types.d.ts +0 -210
- package/dist/mcp/types/filesystem.types.js +0 -27
- package/dist/mcp/types/todo.types.d.ts +0 -27
- package/dist/mcp/types/todo.types.js +0 -4
- package/dist/mcp/types/websearch.types.d.ts +0 -30
- package/dist/mcp/types/websearch.types.js +0 -4
- package/dist/mcp/utils/aceCodeSearch/filesystem.utils.d.ts +0 -34
- package/dist/mcp/utils/aceCodeSearch/filesystem.utils.js +0 -146
- package/dist/mcp/utils/aceCodeSearch/language.utils.d.ts +0 -14
- package/dist/mcp/utils/aceCodeSearch/language.utils.js +0 -418
- package/dist/mcp/utils/aceCodeSearch/search.utils.d.ts +0 -31
- package/dist/mcp/utils/aceCodeSearch/search.utils.js +0 -136
- package/dist/mcp/utils/aceCodeSearch/symbol.utils.d.ts +0 -20
- package/dist/mcp/utils/aceCodeSearch/symbol.utils.js +0 -141
- package/dist/mcp/utils/bash/security.utils.d.ts +0 -20
- package/dist/mcp/utils/bash/security.utils.js +0 -34
- package/dist/mcp/utils/filesystem/batch-operations.utils.d.ts +0 -39
- package/dist/mcp/utils/filesystem/batch-operations.utils.js +0 -182
- package/dist/mcp/utils/filesystem/code-analysis.utils.d.ts +0 -18
- package/dist/mcp/utils/filesystem/code-analysis.utils.js +0 -165
- package/dist/mcp/utils/filesystem/match-finder.utils.d.ts +0 -16
- package/dist/mcp/utils/filesystem/match-finder.utils.js +0 -85
- package/dist/mcp/utils/filesystem/office-parser.utils.d.ts +0 -43
- package/dist/mcp/utils/filesystem/office-parser.utils.js +0 -163
- package/dist/mcp/utils/filesystem/path-fixer.utils.d.ts +0 -7
- package/dist/mcp/utils/filesystem/path-fixer.utils.js +0 -60
- package/dist/mcp/utils/filesystem/similarity.utils.d.ts +0 -22
- package/dist/mcp/utils/filesystem/similarity.utils.js +0 -75
- package/dist/mcp/utils/todo/date.utils.d.ts +0 -9
- package/dist/mcp/utils/todo/date.utils.js +0 -14
- package/dist/mcp/utils/websearch/browser.utils.d.ts +0 -8
- package/dist/mcp/utils/websearch/browser.utils.js +0 -58
- package/dist/mcp/utils/websearch/text.utils.d.ts +0 -16
- package/dist/mcp/utils/websearch/text.utils.js +0 -39
- package/dist/mcp/websearch.d.ts +0 -88
- package/dist/mcp/websearch.js +0 -375
- package/dist/test/logger-test.d.ts +0 -1
- package/dist/test/logger-test.js +0 -7
- package/dist/types/index.d.ts +0 -15
- package/dist/types/index.js +0 -1
- package/dist/ui/components/AgentPickerPanel.d.ts +0 -10
- package/dist/ui/components/AgentPickerPanel.js +0 -74
- package/dist/ui/components/ChatInput.d.ts +0 -46
- package/dist/ui/components/ChatInput.js +0 -384
- package/dist/ui/components/CommandPanel.d.ts +0 -15
- package/dist/ui/components/CommandPanel.js +0 -80
- package/dist/ui/components/DiffViewer.d.ts +0 -11
- package/dist/ui/components/DiffViewer.js +0 -178
- package/dist/ui/components/FileList.d.ts +0 -15
- package/dist/ui/components/FileList.js +0 -360
- package/dist/ui/components/FileRollbackConfirmation.d.ts +0 -8
- package/dist/ui/components/FileRollbackConfirmation.js +0 -108
- package/dist/ui/components/HelpPanel.d.ts +0 -2
- package/dist/ui/components/HelpPanel.js +0 -67
- package/dist/ui/components/MCPInfoPanel.d.ts +0 -2
- package/dist/ui/components/MCPInfoPanel.js +0 -108
- package/dist/ui/components/MCPInfoScreen.d.ts +0 -7
- package/dist/ui/components/MCPInfoScreen.js +0 -115
- package/dist/ui/components/MarkdownRenderer.d.ts +0 -6
- package/dist/ui/components/MarkdownRenderer.js +0 -70
- package/dist/ui/components/Menu.d.ts +0 -17
- package/dist/ui/components/Menu.js +0 -88
- package/dist/ui/components/MessageList.d.ts +0 -56
- package/dist/ui/components/MessageList.js +0 -97
- package/dist/ui/components/PendingMessages.d.ts +0 -13
- package/dist/ui/components/PendingMessages.js +0 -29
- package/dist/ui/components/PendingToolCalls.d.ts +0 -11
- package/dist/ui/components/PendingToolCalls.js +0 -35
- package/dist/ui/components/ScrollableSelectInput.d.ts +0 -29
- package/dist/ui/components/ScrollableSelectInput.js +0 -157
- package/dist/ui/components/SessionListPanel.d.ts +0 -7
- package/dist/ui/components/SessionListPanel.js +0 -175
- package/dist/ui/components/SessionListScreen.d.ts +0 -7
- package/dist/ui/components/SessionListScreen.js +0 -217
- package/dist/ui/components/SessionListScreenWrapper.d.ts +0 -7
- package/dist/ui/components/SessionListScreenWrapper.js +0 -14
- package/dist/ui/components/ShimmerText.d.ts +0 -9
- package/dist/ui/components/ShimmerText.js +0 -30
- package/dist/ui/components/TodoPickerPanel.d.ts +0 -14
- package/dist/ui/components/TodoPickerPanel.js +0 -119
- package/dist/ui/components/TodoTree.d.ts +0 -15
- package/dist/ui/components/TodoTree.js +0 -60
- package/dist/ui/components/ToolConfirmation.d.ts +0 -21
- package/dist/ui/components/ToolConfirmation.js +0 -204
- package/dist/ui/components/ToolResultPreview.d.ts +0 -13
- package/dist/ui/components/ToolResultPreview.js +0 -337
- package/dist/ui/components/UsagePanel.d.ts +0 -2
- package/dist/ui/components/UsagePanel.js +0 -394
- package/dist/ui/contexts/ThemeContext.d.ts +0 -13
- package/dist/ui/contexts/ThemeContext.js +0 -28
- package/dist/ui/pages/ChatScreen.d.ts +0 -6
- package/dist/ui/pages/ChatScreen.js +0 -1519
- package/dist/ui/pages/CodeBaseConfigScreen.d.ts +0 -8
- package/dist/ui/pages/CodeBaseConfigScreen.js +0 -350
- package/dist/ui/pages/ConfigScreen.d.ts +0 -8
- package/dist/ui/pages/ConfigScreen.js +0 -1101
- package/dist/ui/pages/CustomHeadersScreen.d.ts +0 -6
- package/dist/ui/pages/CustomHeadersScreen.js +0 -502
- package/dist/ui/pages/HeadlessModeScreen.d.ts +0 -7
- package/dist/ui/pages/HeadlessModeScreen.js +0 -381
- package/dist/ui/pages/LanguageSettingsScreen.d.ts +0 -7
- package/dist/ui/pages/LanguageSettingsScreen.js +0 -91
- package/dist/ui/pages/MCPConfigScreen.d.ts +0 -6
- package/dist/ui/pages/MCPConfigScreen.js +0 -55
- package/dist/ui/pages/ProxyConfigScreen.d.ts +0 -8
- package/dist/ui/pages/ProxyConfigScreen.js +0 -149
- package/dist/ui/pages/SensitiveCommandConfigScreen.d.ts +0 -7
- package/dist/ui/pages/SensitiveCommandConfigScreen.js +0 -271
- package/dist/ui/pages/SubAgentConfigScreen.d.ts +0 -9
- package/dist/ui/pages/SubAgentConfigScreen.js +0 -435
- package/dist/ui/pages/SubAgentListScreen.d.ts +0 -9
- package/dist/ui/pages/SubAgentListScreen.js +0 -131
- package/dist/ui/pages/SystemPromptConfigScreen.d.ts +0 -6
- package/dist/ui/pages/SystemPromptConfigScreen.js +0 -326
- package/dist/ui/pages/ThemeSettingsScreen.d.ts +0 -7
- package/dist/ui/pages/ThemeSettingsScreen.js +0 -106
- package/dist/ui/pages/WelcomeScreen.d.ts +0 -7
- package/dist/ui/pages/WelcomeScreen.js +0 -217
- package/dist/ui/themes/index.d.ts +0 -23
- package/dist/ui/themes/index.js +0 -140
- package/dist/utils/apiConfig.d.ts +0 -126
- package/dist/utils/apiConfig.js +0 -423
- package/dist/utils/autoCompress.d.ts +0 -15
- package/dist/utils/autoCompress.js +0 -24
- package/dist/utils/chatExporter.d.ts +0 -9
- package/dist/utils/chatExporter.js +0 -118
- package/dist/utils/checkpointManager.d.ts +0 -74
- package/dist/utils/checkpointManager.js +0 -181
- package/dist/utils/codebaseConfig.d.ts +0 -16
- package/dist/utils/codebaseConfig.js +0 -67
- package/dist/utils/codebaseDatabase.d.ts +0 -102
- package/dist/utils/codebaseDatabase.js +0 -333
- package/dist/utils/codebaseSearchEvents.d.ts +0 -16
- package/dist/utils/codebaseSearchEvents.js +0 -13
- package/dist/utils/commandExecutor.d.ts +0 -13
- package/dist/utils/commandExecutor.js +0 -26
- package/dist/utils/commands/agent.d.ts +0 -2
- package/dist/utils/commands/agent.js +0 -12
- package/dist/utils/commands/clear.d.ts +0 -2
- package/dist/utils/commands/clear.js +0 -12
- package/dist/utils/commands/compact.d.ts +0 -2
- package/dist/utils/commands/compact.js +0 -12
- package/dist/utils/commands/export.d.ts +0 -2
- package/dist/utils/commands/export.js +0 -12
- package/dist/utils/commands/help.d.ts +0 -2
- package/dist/utils/commands/help.js +0 -11
- package/dist/utils/commands/home.d.ts +0 -2
- package/dist/utils/commands/home.js +0 -34
- package/dist/utils/commands/ide.d.ts +0 -2
- package/dist/utils/commands/ide.js +0 -32
- package/dist/utils/commands/init.d.ts +0 -2
- package/dist/utils/commands/init.js +0 -93
- package/dist/utils/commands/mcp.d.ts +0 -2
- package/dist/utils/commands/mcp.js +0 -12
- package/dist/utils/commands/resume.d.ts +0 -2
- package/dist/utils/commands/resume.js +0 -12
- package/dist/utils/commands/review.d.ts +0 -2
- package/dist/utils/commands/review.js +0 -81
- package/dist/utils/commands/role.d.ts +0 -2
- package/dist/utils/commands/role.js +0 -37
- package/dist/utils/commands/todoPicker.d.ts +0 -2
- package/dist/utils/commands/todoPicker.js +0 -12
- package/dist/utils/commands/usage.d.ts +0 -2
- package/dist/utils/commands/usage.js +0 -12
- package/dist/utils/commands/yolo.d.ts +0 -2
- package/dist/utils/commands/yolo.js +0 -12
- package/dist/utils/configManager.d.ts +0 -45
- package/dist/utils/configManager.js +0 -303
- package/dist/utils/contextCompressor.d.ts +0 -16
- package/dist/utils/contextCompressor.js +0 -334
- package/dist/utils/devMode.d.ts +0 -13
- package/dist/utils/devMode.js +0 -54
- package/dist/utils/escapeHandler.d.ts +0 -79
- package/dist/utils/escapeHandler.js +0 -153
- package/dist/utils/fileDialog.d.ts +0 -9
- package/dist/utils/fileDialog.js +0 -74
- package/dist/utils/fileUtils.d.ts +0 -40
- package/dist/utils/fileUtils.js +0 -185
- package/dist/utils/historyManager.d.ts +0 -45
- package/dist/utils/historyManager.js +0 -159
- package/dist/utils/incrementalSnapshot.d.ts +0 -109
- package/dist/utils/incrementalSnapshot.js +0 -383
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -18
- package/dist/utils/languageConfig.d.ts +0 -21
- package/dist/utils/languageConfig.js +0 -61
- package/dist/utils/logger.d.ts +0 -37
- package/dist/utils/logger.js +0 -122
- package/dist/utils/mcpToolsManager.d.ts +0 -52
- package/dist/utils/mcpToolsManager.js +0 -878
- package/dist/utils/messageFormatter.d.ts +0 -12
- package/dist/utils/messageFormatter.js +0 -115
- package/dist/utils/notebookManager.d.ts +0 -59
- package/dist/utils/notebookManager.js +0 -213
- package/dist/utils/patch-highlight.d.ts +0 -5
- package/dist/utils/patch-highlight.js +0 -23
- package/dist/utils/processManager.d.ts +0 -27
- package/dist/utils/processManager.js +0 -75
- package/dist/utils/proxyUtils.d.ts +0 -15
- package/dist/utils/proxyUtils.js +0 -50
- package/dist/utils/resourceMonitor.d.ts +0 -65
- package/dist/utils/resourceMonitor.js +0 -175
- package/dist/utils/retryUtils.d.ts +0 -49
- package/dist/utils/retryUtils.js +0 -303
- package/dist/utils/sensitiveCommandManager.d.ts +0 -53
- package/dist/utils/sensitiveCommandManager.js +0 -308
- package/dist/utils/sessionConverter.d.ts +0 -7
- package/dist/utils/sessionConverter.js +0 -306
- package/dist/utils/sessionManager.d.ts +0 -53
- package/dist/utils/sessionManager.js +0 -371
- package/dist/utils/subAgentConfig.d.ts +0 -50
- package/dist/utils/subAgentConfig.js +0 -221
- package/dist/utils/subAgentExecutor.d.ts +0 -40
- package/dist/utils/subAgentExecutor.js +0 -434
- package/dist/utils/terminal.d.ts +0 -5
- package/dist/utils/terminal.js +0 -13
- package/dist/utils/textBuffer.d.ts +0 -99
- package/dist/utils/textBuffer.js +0 -547
- package/dist/utils/textUtils.d.ts +0 -37
- package/dist/utils/textUtils.js +0 -102
- package/dist/utils/themeConfig.d.ts +0 -21
- package/dist/utils/themeConfig.js +0 -61
- package/dist/utils/todoPreprocessor.d.ts +0 -5
- package/dist/utils/todoPreprocessor.js +0 -18
- package/dist/utils/todoScanner.d.ts +0 -8
- package/dist/utils/todoScanner.js +0 -148
- package/dist/utils/toolDisplayConfig.d.ts +0 -16
- package/dist/utils/toolDisplayConfig.js +0 -47
- package/dist/utils/toolExecutor.d.ts +0 -37
- package/dist/utils/toolExecutor.js +0 -224
- package/dist/utils/usageLogger.d.ts +0 -11
- package/dist/utils/usageLogger.js +0 -114
- package/dist/utils/vscodeConnection.d.ts +0 -76
- package/dist/utils/vscodeConnection.js +0 -430
- package/dist/utils/workspaceSnapshot.d.ts +0 -63
- package/dist/utils/workspaceSnapshot.js +0 -300
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type ChatMessage } from '../api/chat.js';
|
|
2
|
-
/**
|
|
3
|
-
* Prompt Optimization Agent Service
|
|
4
|
-
*
|
|
5
|
-
* Optimizes user prompts for better AI understanding and response quality.
|
|
6
|
-
* This service operates using the basic model for efficient, low-cost optimization.
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - Uses basicModel for efficient prompt optimization
|
|
10
|
-
* - Follows the same API routing as main flow (chat, responses, gemini, anthropic)
|
|
11
|
-
* - Filters context to only include user->assistant pairs without tool calls
|
|
12
|
-
* - Returns optimized prompt that preserves user intent while improving clarity
|
|
13
|
-
* - Silent execution with error handling to prevent main flow disruption
|
|
14
|
-
*/
|
|
15
|
-
export declare class PromptOptimizeAgent {
|
|
16
|
-
private modelName;
|
|
17
|
-
private requestMethod;
|
|
18
|
-
private initialized;
|
|
19
|
-
/**
|
|
20
|
-
* Initialize the prompt optimization agent with current configuration
|
|
21
|
-
* @returns true if initialized successfully, false otherwise
|
|
22
|
-
*/
|
|
23
|
-
private initialize;
|
|
24
|
-
/**
|
|
25
|
-
* Check if prompt optimization agent is available
|
|
26
|
-
*/
|
|
27
|
-
isAvailable(): Promise<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
* Call the model with streaming API and assemble complete response
|
|
30
|
-
* Uses the same routing logic as main flow for consistency
|
|
31
|
-
*
|
|
32
|
-
* @param messages - Chat messages
|
|
33
|
-
* @param abortSignal - Optional abort signal to cancel the request
|
|
34
|
-
*/
|
|
35
|
-
private callModel;
|
|
36
|
-
/**
|
|
37
|
-
* Filter conversation history to only include user->assistant pairs without tool calls
|
|
38
|
-
* This creates a lightweight context for prompt optimization
|
|
39
|
-
*
|
|
40
|
-
* @param messages - Full conversation history
|
|
41
|
-
* @returns Filtered messages containing only user->assistant exchanges
|
|
42
|
-
*/
|
|
43
|
-
private filterContextMessages;
|
|
44
|
-
/**
|
|
45
|
-
* Optimize user prompt for better AI understanding
|
|
46
|
-
*
|
|
47
|
-
* @param userPrompt - Original user prompt
|
|
48
|
-
* @param conversationHistory - Full conversation history for context
|
|
49
|
-
* @param abortSignal - Optional abort signal to cancel optimization
|
|
50
|
-
* @returns Optimized prompt, or original prompt if optimization fails
|
|
51
|
-
*/
|
|
52
|
-
optimizePrompt(userPrompt: string, conversationHistory: ChatMessage[], abortSignal?: AbortSignal): Promise<string>;
|
|
53
|
-
}
|
|
54
|
-
export declare const promptOptimizeAgent: PromptOptimizeAgent;
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { getOpenAiConfig } from '../utils/apiConfig.js';
|
|
2
|
-
import { logger } from '../utils/logger.js';
|
|
3
|
-
import { createStreamingChatCompletion } from '../api/chat.js';
|
|
4
|
-
import { createStreamingResponse } from '../api/responses.js';
|
|
5
|
-
import { createStreamingGeminiCompletion } from '../api/gemini.js';
|
|
6
|
-
import { createStreamingAnthropicCompletion } from '../api/anthropic.js';
|
|
7
|
-
/**
|
|
8
|
-
* Prompt Optimization Agent Service
|
|
9
|
-
*
|
|
10
|
-
* Optimizes user prompts for better AI understanding and response quality.
|
|
11
|
-
* This service operates using the basic model for efficient, low-cost optimization.
|
|
12
|
-
*
|
|
13
|
-
* Features:
|
|
14
|
-
* - Uses basicModel for efficient prompt optimization
|
|
15
|
-
* - Follows the same API routing as main flow (chat, responses, gemini, anthropic)
|
|
16
|
-
* - Filters context to only include user->assistant pairs without tool calls
|
|
17
|
-
* - Returns optimized prompt that preserves user intent while improving clarity
|
|
18
|
-
* - Silent execution with error handling to prevent main flow disruption
|
|
19
|
-
*/
|
|
20
|
-
export class PromptOptimizeAgent {
|
|
21
|
-
constructor() {
|
|
22
|
-
Object.defineProperty(this, "modelName", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: ''
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(this, "requestMethod", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: 'chat'
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(this, "initialized", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true,
|
|
38
|
-
value: false
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Initialize the prompt optimization agent with current configuration
|
|
43
|
-
* @returns true if initialized successfully, false otherwise
|
|
44
|
-
*/
|
|
45
|
-
async initialize() {
|
|
46
|
-
try {
|
|
47
|
-
const config = getOpenAiConfig();
|
|
48
|
-
// Check if basic model is configured
|
|
49
|
-
if (!config.basicModel) {
|
|
50
|
-
logger.warn('Prompt optimize agent: Basic model not configured');
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
this.modelName = config.basicModel;
|
|
54
|
-
this.requestMethod = config.requestMethod;
|
|
55
|
-
this.initialized = true;
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
logger.warn('Prompt optimize agent: Failed to initialize:', error);
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Check if prompt optimization agent is available
|
|
65
|
-
*/
|
|
66
|
-
async isAvailable() {
|
|
67
|
-
if (!this.initialized) {
|
|
68
|
-
return await this.initialize();
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Call the model with streaming API and assemble complete response
|
|
74
|
-
* Uses the same routing logic as main flow for consistency
|
|
75
|
-
*
|
|
76
|
-
* @param messages - Chat messages
|
|
77
|
-
* @param abortSignal - Optional abort signal to cancel the request
|
|
78
|
-
*/
|
|
79
|
-
async callModel(messages, abortSignal) {
|
|
80
|
-
let streamGenerator;
|
|
81
|
-
// Route to appropriate streaming API based on request method
|
|
82
|
-
switch (this.requestMethod) {
|
|
83
|
-
case 'anthropic':
|
|
84
|
-
streamGenerator = createStreamingAnthropicCompletion({
|
|
85
|
-
model: this.modelName,
|
|
86
|
-
messages,
|
|
87
|
-
max_tokens: 1000, // Limited tokens for prompt optimization
|
|
88
|
-
includeBuiltinSystemPrompt: false,
|
|
89
|
-
disableThinking: true, // Agents don't use Extended Thinking
|
|
90
|
-
}, abortSignal);
|
|
91
|
-
break;
|
|
92
|
-
case 'gemini':
|
|
93
|
-
streamGenerator = createStreamingGeminiCompletion({
|
|
94
|
-
model: this.modelName,
|
|
95
|
-
messages,
|
|
96
|
-
includeBuiltinSystemPrompt: false,
|
|
97
|
-
}, abortSignal);
|
|
98
|
-
break;
|
|
99
|
-
case 'responses':
|
|
100
|
-
streamGenerator = createStreamingResponse({
|
|
101
|
-
model: this.modelName,
|
|
102
|
-
messages,
|
|
103
|
-
stream: true,
|
|
104
|
-
includeBuiltinSystemPrompt: false,
|
|
105
|
-
}, abortSignal);
|
|
106
|
-
break;
|
|
107
|
-
case 'chat':
|
|
108
|
-
default:
|
|
109
|
-
streamGenerator = createStreamingChatCompletion({
|
|
110
|
-
model: this.modelName,
|
|
111
|
-
messages,
|
|
112
|
-
stream: true,
|
|
113
|
-
includeBuiltinSystemPrompt: false,
|
|
114
|
-
}, abortSignal);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
// Assemble complete content from streaming response
|
|
118
|
-
let completeContent = '';
|
|
119
|
-
try {
|
|
120
|
-
for await (const chunk of streamGenerator) {
|
|
121
|
-
// Check abort signal
|
|
122
|
-
if (abortSignal?.aborted) {
|
|
123
|
-
throw new Error('Request aborted');
|
|
124
|
-
}
|
|
125
|
-
// Handle different chunk formats based on request method
|
|
126
|
-
if (this.requestMethod === 'chat') {
|
|
127
|
-
// Chat API uses standard OpenAI format
|
|
128
|
-
if (chunk.choices && chunk.choices[0]?.delta?.content) {
|
|
129
|
-
completeContent += chunk.choices[0].delta.content;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
// Responses, Gemini, and Anthropic APIs use unified format
|
|
134
|
-
if (chunk.type === 'content' && chunk.content) {
|
|
135
|
-
completeContent += chunk.content;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
catch (streamError) {
|
|
141
|
-
logger.error('Prompt optimize agent: Streaming error:', streamError);
|
|
142
|
-
throw streamError;
|
|
143
|
-
}
|
|
144
|
-
return completeContent;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Filter conversation history to only include user->assistant pairs without tool calls
|
|
148
|
-
* This creates a lightweight context for prompt optimization
|
|
149
|
-
*
|
|
150
|
-
* @param messages - Full conversation history
|
|
151
|
-
* @returns Filtered messages containing only user->assistant exchanges
|
|
152
|
-
*/
|
|
153
|
-
filterContextMessages(messages) {
|
|
154
|
-
const filtered = [];
|
|
155
|
-
for (const msg of messages) {
|
|
156
|
-
// Only include user and assistant messages
|
|
157
|
-
if (msg.role === 'user' || msg.role === 'assistant') {
|
|
158
|
-
// For assistant messages, skip if they contain tool calls
|
|
159
|
-
if (msg.role === 'assistant') {
|
|
160
|
-
// Check if message has tool_calls (OpenAI format) or tool_use content (Anthropic format)
|
|
161
|
-
const hasToolCalls = !!msg.tool_calls;
|
|
162
|
-
const hasToolUseContent = Array.isArray(msg.content) &&
|
|
163
|
-
msg.content.some((c) => c.type === 'tool_use' || c.type === 'tool_call');
|
|
164
|
-
if (hasToolCalls || hasToolUseContent) {
|
|
165
|
-
continue; // Skip assistant messages with tool calls
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// Add message to filtered list
|
|
169
|
-
filtered.push(msg);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return filtered;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Optimize user prompt for better AI understanding
|
|
176
|
-
*
|
|
177
|
-
* @param userPrompt - Original user prompt
|
|
178
|
-
* @param conversationHistory - Full conversation history for context
|
|
179
|
-
* @param abortSignal - Optional abort signal to cancel optimization
|
|
180
|
-
* @returns Optimized prompt, or original prompt if optimization fails
|
|
181
|
-
*/
|
|
182
|
-
async optimizePrompt(userPrompt, conversationHistory, abortSignal) {
|
|
183
|
-
const available = await this.isAvailable();
|
|
184
|
-
if (!available) {
|
|
185
|
-
return userPrompt;
|
|
186
|
-
}
|
|
187
|
-
try {
|
|
188
|
-
// Check word count - if prompt > 100 words, skip optimization
|
|
189
|
-
// User likely provided detailed/important original text that should be preserved as-is
|
|
190
|
-
const wordCount = userPrompt.trim().split(/\s+/).length;
|
|
191
|
-
if (wordCount > 100) {
|
|
192
|
-
return userPrompt;
|
|
193
|
-
}
|
|
194
|
-
// Filter conversation history to lightweight context (only user<->assistant, no tool calls)
|
|
195
|
-
const contextMessages = this.filterContextMessages(conversationHistory);
|
|
196
|
-
// Build context summary if there's conversation history
|
|
197
|
-
let contextSummary = '';
|
|
198
|
-
if (contextMessages.length > 0) {
|
|
199
|
-
// Take last 8 messages to keep context focused, but use full content (no truncation)
|
|
200
|
-
const recentContext = contextMessages.slice(-8);
|
|
201
|
-
contextSummary =
|
|
202
|
-
'\n\nRecent conversation context:\n' +
|
|
203
|
-
recentContext
|
|
204
|
-
.map((msg) => {
|
|
205
|
-
const content = typeof msg.content === 'string'
|
|
206
|
-
? msg.content
|
|
207
|
-
: JSON.stringify(msg.content);
|
|
208
|
-
// Use full message content (no truncation)
|
|
209
|
-
return `${msg.role}: ${content}`;
|
|
210
|
-
})
|
|
211
|
-
.join('\n');
|
|
212
|
-
}
|
|
213
|
-
const optimizationPrompt = `You are a prompt optimization assistant. Your task is to improve user prompts for better AI understanding while maintaining HIGH FIDELITY to the original content.
|
|
214
|
-
|
|
215
|
-
User's original prompt:
|
|
216
|
-
${userPrompt}${contextSummary}
|
|
217
|
-
|
|
218
|
-
Your optimization goals (in priority order):
|
|
219
|
-
1. **HIGH FIDELITY REQUIREMENT**: Preserve ALL important information, details, and requirements from the user's original prompt - DO NOT lose or omit any critical content
|
|
220
|
-
2. Preserve the EXACT SAME LANGUAGE as the user (if Chinese, stay Chinese; if English, stay English)
|
|
221
|
-
3. Keep the core intent and meaning unchanged
|
|
222
|
-
4. Make the prompt clearer and more specific ONLY if vague - if already clear, keep it as-is
|
|
223
|
-
5. Add relevant context if the user is asking follow-up questions
|
|
224
|
-
6. Break down complex requests into clear requirements without losing details
|
|
225
|
-
7. Keep the tone natural and conversational
|
|
226
|
-
8. DO NOT add unnecessary formality or change the user's communication style
|
|
227
|
-
9. If the prompt is already clear and specific, return it as-is
|
|
228
|
-
|
|
229
|
-
CRITICAL RULES:
|
|
230
|
-
- NEVER remove important details, specific requirements, file paths, code snippets, or technical specifications
|
|
231
|
-
- NEVER simplify the prompt if it means losing user-provided information
|
|
232
|
-
- When in doubt, prefer preserving the original over optimizing
|
|
233
|
-
- The goal is CLARITY, not BREVITY - keep all important content
|
|
234
|
-
|
|
235
|
-
IMPORTANT: Output ONLY the optimized prompt text. No explanations, no meta-commentary, no JSON format. Just the optimized prompt itself.`;
|
|
236
|
-
const messages = [
|
|
237
|
-
{
|
|
238
|
-
role: 'user',
|
|
239
|
-
content: optimizationPrompt,
|
|
240
|
-
},
|
|
241
|
-
];
|
|
242
|
-
const optimizedPrompt = await this.callModel(messages, abortSignal);
|
|
243
|
-
if (!optimizedPrompt || optimizedPrompt.trim().length === 0) {
|
|
244
|
-
logger.warn('Prompt optimize agent: Empty response, using original prompt');
|
|
245
|
-
return userPrompt;
|
|
246
|
-
}
|
|
247
|
-
// Clean up the response (remove any markdown formatting if present)
|
|
248
|
-
let cleanedPrompt = optimizedPrompt.trim();
|
|
249
|
-
// Remove markdown code blocks if present
|
|
250
|
-
const codeBlockMatch = cleanedPrompt.match(/```[\s\S]*?\n([\s\S]*?)```/);
|
|
251
|
-
if (codeBlockMatch) {
|
|
252
|
-
cleanedPrompt = codeBlockMatch[1].trim();
|
|
253
|
-
}
|
|
254
|
-
// If optimized prompt is suspiciously short or looks like it failed, use original
|
|
255
|
-
if (cleanedPrompt.length < userPrompt.length * 0.3) {
|
|
256
|
-
logger.warn('Prompt optimize agent: Optimized prompt too short, using original');
|
|
257
|
-
return userPrompt;
|
|
258
|
-
}
|
|
259
|
-
return cleanedPrompt;
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
logger.error('Prompt optimize agent: Failed to optimize prompt', error);
|
|
263
|
-
return userPrompt;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
// Export singleton instance
|
|
268
|
-
export const promptOptimizeAgent = new PromptOptimizeAgent();
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export declare class ReviewAgent {
|
|
2
|
-
private modelName;
|
|
3
|
-
private requestMethod;
|
|
4
|
-
private initialized;
|
|
5
|
-
/**
|
|
6
|
-
* Initialize the review agent with current configuration
|
|
7
|
-
* Uses advanced model (same as main flow)
|
|
8
|
-
*/
|
|
9
|
-
private initialize;
|
|
10
|
-
/**
|
|
11
|
-
* Check if review agent is available
|
|
12
|
-
*/
|
|
13
|
-
isAvailable(): Promise<boolean>;
|
|
14
|
-
/**
|
|
15
|
-
* Check if current directory or any parent directory is a git repository
|
|
16
|
-
* @param startDir - Starting directory to check
|
|
17
|
-
* @returns Path to git root directory, or null if not found
|
|
18
|
-
*/
|
|
19
|
-
private findGitRoot;
|
|
20
|
-
/**
|
|
21
|
-
* Check if git is available and current directory is in a git repository
|
|
22
|
-
* @returns Object with isGitRepo flag and optional error message
|
|
23
|
-
*/
|
|
24
|
-
checkGitRepository(): {
|
|
25
|
-
isGitRepo: boolean;
|
|
26
|
-
gitRoot?: string;
|
|
27
|
-
error?: string;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Get git diff for uncommitted changes
|
|
31
|
-
* @param gitRoot - Git repository root directory
|
|
32
|
-
* @returns Git diff output
|
|
33
|
-
*/
|
|
34
|
-
getGitDiff(gitRoot: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Generate code review prompt
|
|
37
|
-
*/
|
|
38
|
-
private generateReviewPrompt;
|
|
39
|
-
/**
|
|
40
|
-
* Call the advanced model with streaming (same routing as main flow)
|
|
41
|
-
*/
|
|
42
|
-
private callAdvancedModel;
|
|
43
|
-
/**
|
|
44
|
-
* Review git changes and return streaming generator
|
|
45
|
-
* @param abortSignal - Optional abort signal
|
|
46
|
-
* @returns Async generator for streaming response
|
|
47
|
-
*/
|
|
48
|
-
reviewChanges(abortSignal?: AbortSignal): AsyncGenerator<any, void, unknown>;
|
|
49
|
-
}
|
|
50
|
-
export declare const reviewAgent: ReviewAgent;
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { getOpenAiConfig, getCustomSystemPrompt } from '../utils/apiConfig.js';
|
|
2
|
-
import { logger } from '../utils/logger.js';
|
|
3
|
-
import { createStreamingChatCompletion } from '../api/chat.js';
|
|
4
|
-
import { createStreamingResponse } from '../api/responses.js';
|
|
5
|
-
import { createStreamingGeminiCompletion } from '../api/gemini.js';
|
|
6
|
-
import { createStreamingAnthropicCompletion } from '../api/anthropic.js';
|
|
7
|
-
import { execSync } from 'child_process';
|
|
8
|
-
import * as path from 'path';
|
|
9
|
-
import * as fs from 'fs';
|
|
10
|
-
export class ReviewAgent {
|
|
11
|
-
constructor() {
|
|
12
|
-
Object.defineProperty(this, "modelName", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: ''
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "requestMethod", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: 'chat'
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "initialized", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: false
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Initialize the review agent with current configuration
|
|
33
|
-
* Uses advanced model (same as main flow)
|
|
34
|
-
*/
|
|
35
|
-
async initialize() {
|
|
36
|
-
try {
|
|
37
|
-
const config = getOpenAiConfig();
|
|
38
|
-
if (!config.advancedModel) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
this.modelName = config.advancedModel;
|
|
42
|
-
this.requestMethod = config.requestMethod;
|
|
43
|
-
this.initialized = true;
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
logger.warn('Failed to initialize review agent:', error);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Check if review agent is available
|
|
53
|
-
*/
|
|
54
|
-
async isAvailable() {
|
|
55
|
-
if (!this.initialized) {
|
|
56
|
-
return await this.initialize();
|
|
57
|
-
}
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Check if current directory or any parent directory is a git repository
|
|
62
|
-
* @param startDir - Starting directory to check
|
|
63
|
-
* @returns Path to git root directory, or null if not found
|
|
64
|
-
*/
|
|
65
|
-
findGitRoot(startDir) {
|
|
66
|
-
let currentDir = path.resolve(startDir);
|
|
67
|
-
const root = path.parse(currentDir).root;
|
|
68
|
-
while (currentDir !== root) {
|
|
69
|
-
const gitDir = path.join(currentDir, '.git');
|
|
70
|
-
if (fs.existsSync(gitDir)) {
|
|
71
|
-
return currentDir;
|
|
72
|
-
}
|
|
73
|
-
currentDir = path.dirname(currentDir);
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Check if git is available and current directory is in a git repository
|
|
79
|
-
* @returns Object with isGitRepo flag and optional error message
|
|
80
|
-
*/
|
|
81
|
-
checkGitRepository() {
|
|
82
|
-
try {
|
|
83
|
-
// Check if git command is available
|
|
84
|
-
try {
|
|
85
|
-
execSync('git --version', { stdio: 'ignore' });
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return {
|
|
89
|
-
isGitRepo: false,
|
|
90
|
-
error: 'Git is not installed or not available in PATH',
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
// Find git root directory (check current and parent directories)
|
|
94
|
-
const gitRoot = this.findGitRoot(process.cwd());
|
|
95
|
-
if (!gitRoot) {
|
|
96
|
-
return {
|
|
97
|
-
isGitRepo: false,
|
|
98
|
-
error: 'Current directory is not in a git repository. Please run this command from within a git repository.',
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return { isGitRepo: true, gitRoot };
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
return {
|
|
105
|
-
isGitRepo: false,
|
|
106
|
-
error: error instanceof Error
|
|
107
|
-
? error.message
|
|
108
|
-
: 'Failed to check git repository',
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get git diff for uncommitted changes
|
|
114
|
-
* @param gitRoot - Git repository root directory
|
|
115
|
-
* @returns Git diff output
|
|
116
|
-
*/
|
|
117
|
-
getGitDiff(gitRoot) {
|
|
118
|
-
try {
|
|
119
|
-
// Get staged changes
|
|
120
|
-
const stagedDiff = execSync('git diff --cached', {
|
|
121
|
-
cwd: gitRoot,
|
|
122
|
-
encoding: 'utf-8',
|
|
123
|
-
maxBuffer: 10 * 1024 * 1024, // 10MB buffer
|
|
124
|
-
});
|
|
125
|
-
// Get unstaged changes
|
|
126
|
-
const unstagedDiff = execSync('git diff', {
|
|
127
|
-
cwd: gitRoot,
|
|
128
|
-
encoding: 'utf-8',
|
|
129
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
130
|
-
});
|
|
131
|
-
// Combine both diffs
|
|
132
|
-
let combinedDiff = '';
|
|
133
|
-
if (stagedDiff) {
|
|
134
|
-
combinedDiff += '# Staged Changes\n\n' + stagedDiff + '\n\n';
|
|
135
|
-
}
|
|
136
|
-
if (unstagedDiff) {
|
|
137
|
-
combinedDiff += '# Unstaged Changes\n\n' + unstagedDiff;
|
|
138
|
-
}
|
|
139
|
-
if (!combinedDiff) {
|
|
140
|
-
return 'No changes detected in the repository.';
|
|
141
|
-
}
|
|
142
|
-
return combinedDiff;
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
logger.error('Failed to get git diff:', error);
|
|
146
|
-
throw new Error('Failed to get git changes: ' +
|
|
147
|
-
(error instanceof Error ? error.message : 'Unknown error'));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Generate code review prompt
|
|
152
|
-
*/
|
|
153
|
-
generateReviewPrompt(gitDiff) {
|
|
154
|
-
return `You are a senior code reviewer. Please review the following git changes and provide feedback.
|
|
155
|
-
|
|
156
|
-
**Your task:**
|
|
157
|
-
1. Identify potential bugs, security issues, or logic errors
|
|
158
|
-
2. Suggest performance optimizations
|
|
159
|
-
3. Point out code quality issues (readability, maintainability)
|
|
160
|
-
4. Check for best practices violations
|
|
161
|
-
5. Highlight any breaking changes or compatibility issues
|
|
162
|
-
|
|
163
|
-
**Important:**
|
|
164
|
-
- DO NOT modify the code yourself
|
|
165
|
-
- Focus on finding issues and suggesting improvements
|
|
166
|
-
- Ask the user if they want to fix any issues you find
|
|
167
|
-
- Be constructive and specific in your feedback
|
|
168
|
-
- Prioritize critical issues over minor style preferences
|
|
169
|
-
|
|
170
|
-
**Git Changes:**
|
|
171
|
-
|
|
172
|
-
\`\`\`diff
|
|
173
|
-
${gitDiff}
|
|
174
|
-
\`\`\`
|
|
175
|
-
|
|
176
|
-
Please provide your review in a clear, structured format.`;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Call the advanced model with streaming (same routing as main flow)
|
|
180
|
-
*/
|
|
181
|
-
async *callAdvancedModel(messages, abortSignal) {
|
|
182
|
-
const config = getOpenAiConfig();
|
|
183
|
-
if (!config.advancedModel) {
|
|
184
|
-
throw new Error('Advanced model not configured');
|
|
185
|
-
}
|
|
186
|
-
// Get custom system prompt if configured
|
|
187
|
-
const customSystemPrompt = getCustomSystemPrompt();
|
|
188
|
-
// If custom system prompt exists, prepend it to messages
|
|
189
|
-
let processedMessages = messages;
|
|
190
|
-
if (customSystemPrompt) {
|
|
191
|
-
processedMessages = [
|
|
192
|
-
{
|
|
193
|
-
role: 'system',
|
|
194
|
-
content: customSystemPrompt,
|
|
195
|
-
},
|
|
196
|
-
...messages,
|
|
197
|
-
];
|
|
198
|
-
}
|
|
199
|
-
// Route to appropriate streaming API based on request method
|
|
200
|
-
switch (this.requestMethod) {
|
|
201
|
-
case 'anthropic':
|
|
202
|
-
yield* createStreamingAnthropicCompletion({
|
|
203
|
-
model: this.modelName,
|
|
204
|
-
messages: processedMessages,
|
|
205
|
-
max_tokens: 4096,
|
|
206
|
-
disableThinking: true, // Agents 不使用 Extended Thinking
|
|
207
|
-
}, abortSignal);
|
|
208
|
-
break;
|
|
209
|
-
case 'gemini':
|
|
210
|
-
yield* createStreamingGeminiCompletion({
|
|
211
|
-
model: this.modelName,
|
|
212
|
-
messages: processedMessages,
|
|
213
|
-
}, abortSignal);
|
|
214
|
-
break;
|
|
215
|
-
case 'responses':
|
|
216
|
-
yield* createStreamingResponse({
|
|
217
|
-
model: this.modelName,
|
|
218
|
-
messages: processedMessages,
|
|
219
|
-
stream: true,
|
|
220
|
-
}, abortSignal);
|
|
221
|
-
break;
|
|
222
|
-
case 'chat':
|
|
223
|
-
default:
|
|
224
|
-
yield* createStreamingChatCompletion({
|
|
225
|
-
model: this.modelName,
|
|
226
|
-
messages: processedMessages,
|
|
227
|
-
stream: true,
|
|
228
|
-
}, abortSignal);
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Review git changes and return streaming generator
|
|
234
|
-
* @param abortSignal - Optional abort signal
|
|
235
|
-
* @returns Async generator for streaming response
|
|
236
|
-
*/
|
|
237
|
-
async *reviewChanges(abortSignal) {
|
|
238
|
-
const available = await this.isAvailable();
|
|
239
|
-
if (!available) {
|
|
240
|
-
throw new Error('Review agent is not available');
|
|
241
|
-
}
|
|
242
|
-
// Check git repository
|
|
243
|
-
const gitCheck = this.checkGitRepository();
|
|
244
|
-
if (!gitCheck.isGitRepo) {
|
|
245
|
-
throw new Error(gitCheck.error || 'Not a git repository');
|
|
246
|
-
}
|
|
247
|
-
// Get git diff
|
|
248
|
-
const gitDiff = this.getGitDiff(gitCheck.gitRoot);
|
|
249
|
-
if (gitDiff === 'No changes detected in the repository.') {
|
|
250
|
-
throw new Error('No changes detected. Please make some changes before running code review.');
|
|
251
|
-
}
|
|
252
|
-
// Generate review prompt
|
|
253
|
-
const reviewPrompt = this.generateReviewPrompt(gitDiff);
|
|
254
|
-
const messages = [
|
|
255
|
-
{
|
|
256
|
-
role: 'user',
|
|
257
|
-
content: reviewPrompt,
|
|
258
|
-
},
|
|
259
|
-
];
|
|
260
|
-
// Stream the response
|
|
261
|
-
yield* this.callAdvancedModel(messages, abortSignal);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
// Export singleton instance
|
|
265
|
-
export const reviewAgent = new ReviewAgent();
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Summary Agent Service
|
|
3
|
-
*
|
|
4
|
-
* Generates concise summaries for conversations after the first user-assistant exchange.
|
|
5
|
-
* This service operates in the background without blocking the main conversation flow.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Uses basicModel for efficient, low-cost summarization
|
|
9
|
-
* - Follows the same API routing as main flow (chat, responses, gemini, anthropic)
|
|
10
|
-
* - Generates title (max 50 chars) and summary (max 150 chars)
|
|
11
|
-
* - Only runs once after the first complete conversation exchange
|
|
12
|
-
* - Silent execution with error handling to prevent main flow disruption
|
|
13
|
-
*/
|
|
14
|
-
export declare class SummaryAgent {
|
|
15
|
-
private modelName;
|
|
16
|
-
private requestMethod;
|
|
17
|
-
private initialized;
|
|
18
|
-
/**
|
|
19
|
-
* Initialize the summary agent with current configuration
|
|
20
|
-
* @returns true if initialized successfully, false otherwise
|
|
21
|
-
*/
|
|
22
|
-
private initialize;
|
|
23
|
-
/**
|
|
24
|
-
* Check if summary agent is available
|
|
25
|
-
*/
|
|
26
|
-
isAvailable(): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Call the model with streaming API and assemble complete response
|
|
29
|
-
* Uses the same routing logic as main flow for consistency
|
|
30
|
-
*
|
|
31
|
-
* @param messages - Chat messages
|
|
32
|
-
* @param abortSignal - Optional abort signal to cancel the request
|
|
33
|
-
*/
|
|
34
|
-
private callModel;
|
|
35
|
-
/**
|
|
36
|
-
* Generate title and summary for a conversation
|
|
37
|
-
*
|
|
38
|
-
* @param userMessage - User's first message content
|
|
39
|
-
* @param assistantMessage - Assistant's first response content
|
|
40
|
-
* @param abortSignal - Optional abort signal to cancel generation
|
|
41
|
-
* @returns Object containing title and summary, or null if generation fails
|
|
42
|
-
*/
|
|
43
|
-
generateSummary(userMessage: string, assistantMessage: string, abortSignal?: AbortSignal): Promise<{
|
|
44
|
-
title: string;
|
|
45
|
-
summary: string;
|
|
46
|
-
} | null>;
|
|
47
|
-
/**
|
|
48
|
-
* Generate fallback summary when AI generation fails
|
|
49
|
-
* Simply truncates the user message for title and summary
|
|
50
|
-
*/
|
|
51
|
-
private generateFallbackSummary;
|
|
52
|
-
/**
|
|
53
|
-
* Truncate string to specified length, adding ellipsis if truncated
|
|
54
|
-
*/
|
|
55
|
-
private truncateString;
|
|
56
|
-
}
|
|
57
|
-
export declare const summaryAgent: SummaryAgent;
|