@nanocollective/nanocoder 1.11.3
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/LICENSE.md +23 -0
- package/README.md +366 -0
- package/dist/app/hooks/useAppInitialization.d.ts +26 -0
- package/dist/app/hooks/useAppInitialization.d.ts.map +1 -0
- package/dist/app/hooks/useAppInitialization.js +151 -0
- package/dist/app/hooks/useAppInitialization.js.map +1 -0
- package/dist/app/hooks/useAppState.d.ts +84 -0
- package/dist/app/hooks/useAppState.d.ts.map +1 -0
- package/dist/app/hooks/useAppState.js +162 -0
- package/dist/app/hooks/useAppState.js.map +1 -0
- package/dist/app/hooks/useChatHandler.d.ts +26 -0
- package/dist/app/hooks/useChatHandler.d.ts.map +1 -0
- package/dist/app/hooks/useChatHandler.js +532 -0
- package/dist/app/hooks/useChatHandler.js.map +1 -0
- package/dist/app/hooks/useDirectoryTrust.d.ts +15 -0
- package/dist/app/hooks/useDirectoryTrust.d.ts.map +1 -0
- package/dist/app/hooks/useDirectoryTrust.js +77 -0
- package/dist/app/hooks/useDirectoryTrust.js.map +1 -0
- package/dist/app/hooks/useModeHandlers.d.ts +31 -0
- package/dist/app/hooks/useModeHandlers.d.ts.map +1 -0
- package/dist/app/hooks/useModeHandlers.js +98 -0
- package/dist/app/hooks/useModeHandlers.js.map +1 -0
- package/dist/app/hooks/useToolHandler.d.ts +32 -0
- package/dist/app/hooks/useToolHandler.d.ts.map +1 -0
- package/dist/app/hooks/useToolHandler.js +154 -0
- package/dist/app/hooks/useToolHandler.js.map +1 -0
- package/dist/app/utils/appUtils.d.ts +4 -0
- package/dist/app/utils/appUtils.d.ts.map +1 -0
- package/dist/app/utils/appUtils.js +147 -0
- package/dist/app/utils/appUtils.js.map +1 -0
- package/dist/app/utils/conversationState.d.ts +68 -0
- package/dist/app/utils/conversationState.d.ts.map +1 -0
- package/dist/app/utils/conversationState.js +199 -0
- package/dist/app/utils/conversationState.js.map +1 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +193 -0
- package/dist/app.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-factory.d.ts +6 -0
- package/dist/client-factory.d.ts.map +1 -0
- package/dist/client-factory.js +111 -0
- package/dist/client-factory.js.map +1 -0
- package/dist/command-parser.d.ts +5 -0
- package/dist/command-parser.d.ts.map +1 -0
- package/dist/command-parser.js +36 -0
- package/dist/command-parser.js.map +1 -0
- package/dist/commands/clear.d.ts +3 -0
- package/dist/commands/clear.d.ts.map +1 -0
- package/dist/commands/clear.js +17 -0
- package/dist/commands/clear.js.map +1 -0
- package/dist/commands/custom-commands.d.ts +3 -0
- package/dist/commands/custom-commands.d.ts.map +1 -0
- package/dist/commands/custom-commands.js +41 -0
- package/dist/commands/custom-commands.js.map +1 -0
- package/dist/commands/debug.d.ts +3 -0
- package/dist/commands/debug.d.ts.map +1 -0
- package/dist/commands/debug.js +86 -0
- package/dist/commands/debug.js.map +1 -0
- package/dist/commands/exit.d.ts +3 -0
- package/dist/commands/exit.d.ts.map +1 -0
- package/dist/commands/exit.js +17 -0
- package/dist/commands/exit.js.map +1 -0
- package/dist/commands/export.d.ts +3 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +63 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +31 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/index.d.ts +13 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +13 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +214 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +9 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +41 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/model.d.ts +3 -0
- package/dist/commands/model.d.ts.map +1 -0
- package/dist/commands/model.js +11 -0
- package/dist/commands/model.js.map +1 -0
- package/dist/commands/provider.d.ts +3 -0
- package/dist/commands/provider.d.ts.map +1 -0
- package/dist/commands/provider.js +11 -0
- package/dist/commands/provider.js.map +1 -0
- package/dist/commands/theme.d.ts +3 -0
- package/dist/commands/theme.d.ts.map +1 -0
- package/dist/commands/theme.js +11 -0
- package/dist/commands/theme.js.map +1 -0
- package/dist/commands/update.d.ts +3 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +10 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands.d.ts +16 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +46 -0
- package/dist/commands.js.map +1 -0
- package/dist/components/assistant-message.d.ts +4 -0
- package/dist/components/assistant-message.d.ts.map +1 -0
- package/dist/components/assistant-message.js +43 -0
- package/dist/components/assistant-message.js.map +1 -0
- package/dist/components/bash-execution-indicator.d.ts +4 -0
- package/dist/components/bash-execution-indicator.d.ts.map +1 -0
- package/dist/components/bash-execution-indicator.js +9 -0
- package/dist/components/bash-execution-indicator.js.map +1 -0
- package/dist/components/cancelling-indicator.d.ts +3 -0
- package/dist/components/cancelling-indicator.d.ts.map +1 -0
- package/dist/components/cancelling-indicator.js +10 -0
- package/dist/components/cancelling-indicator.js.map +1 -0
- package/dist/components/chat-queue.d.ts +4 -0
- package/dist/components/chat-queue.d.ts.map +1 -0
- package/dist/components/chat-queue.js +23 -0
- package/dist/components/chat-queue.js.map +1 -0
- package/dist/components/custom-commands.d.ts +7 -0
- package/dist/components/custom-commands.d.ts.map +1 -0
- package/dist/components/custom-commands.js +27 -0
- package/dist/components/custom-commands.js.map +1 -0
- package/dist/components/error-message.d.ts +7 -0
- package/dist/components/error-message.d.ts.map +1 -0
- package/dist/components/error-message.js +12 -0
- package/dist/components/error-message.js.map +1 -0
- package/dist/components/info-message.d.ts +6 -0
- package/dist/components/info-message.d.ts.map +1 -0
- package/dist/components/info-message.js +11 -0
- package/dist/components/info-message.js.map +1 -0
- package/dist/components/model-selector.d.ts +10 -0
- package/dist/components/model-selector.d.ts.map +1 -0
- package/dist/components/model-selector.js +59 -0
- package/dist/components/model-selector.js.map +1 -0
- package/dist/components/provider-selector.d.ts +9 -0
- package/dist/components/provider-selector.d.ts.map +1 -0
- package/dist/components/provider-selector.js +36 -0
- package/dist/components/provider-selector.js.map +1 -0
- package/dist/components/security-disclaimer.d.ts +7 -0
- package/dist/components/security-disclaimer.d.ts.map +1 -0
- package/dist/components/security-disclaimer.js +36 -0
- package/dist/components/security-disclaimer.js.map +1 -0
- package/dist/components/status.d.ts +6 -0
- package/dist/components/status.d.ts.map +1 -0
- package/dist/components/status.js +35 -0
- package/dist/components/status.js.map +1 -0
- package/dist/components/success-message.d.ts +6 -0
- package/dist/components/success-message.d.ts.map +1 -0
- package/dist/components/success-message.js +11 -0
- package/dist/components/success-message.js.map +1 -0
- package/dist/components/theme-selector.d.ts +8 -0
- package/dist/components/theme-selector.d.ts.map +1 -0
- package/dist/components/theme-selector.js +40 -0
- package/dist/components/theme-selector.js.map +1 -0
- package/dist/components/thinking-indicator.d.ts +4 -0
- package/dist/components/thinking-indicator.d.ts.map +1 -0
- package/dist/components/thinking-indicator.js +32 -0
- package/dist/components/thinking-indicator.js.map +1 -0
- package/dist/components/tool-confirmation.d.ts +9 -0
- package/dist/components/tool-confirmation.d.ts.map +1 -0
- package/dist/components/tool-confirmation.js +72 -0
- package/dist/components/tool-confirmation.js.map +1 -0
- package/dist/components/tool-execution-indicator.d.ts +3 -0
- package/dist/components/tool-execution-indicator.d.ts.map +1 -0
- package/dist/components/tool-execution-indicator.js +9 -0
- package/dist/components/tool-execution-indicator.js.map +1 -0
- package/dist/components/tool-message.d.ts +10 -0
- package/dist/components/tool-message.d.ts.map +1 -0
- package/dist/components/tool-message.js +16 -0
- package/dist/components/tool-message.js.map +1 -0
- package/dist/components/update-message.d.ts +7 -0
- package/dist/components/update-message.d.ts.map +1 -0
- package/dist/components/update-message.js +93 -0
- package/dist/components/update-message.js.map +1 -0
- package/dist/components/user-input.d.ts +10 -0
- package/dist/components/user-input.d.ts.map +1 -0
- package/dist/components/user-input.js +188 -0
- package/dist/components/user-input.js.map +1 -0
- package/dist/components/user-message.d.ts +4 -0
- package/dist/components/user-message.d.ts.map +1 -0
- package/dist/components/user-message.js +15 -0
- package/dist/components/user-message.js.map +1 -0
- package/dist/components/welcome-message.d.ts +3 -0
- package/dist/components/welcome-message.d.ts.map +1 -0
- package/dist/components/welcome-message.js +21 -0
- package/dist/components/welcome-message.js.map +1 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +44 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/logging.d.ts +14 -0
- package/dist/config/logging.d.ts.map +1 -0
- package/dist/config/logging.js +58 -0
- package/dist/config/logging.js.map +1 -0
- package/dist/config/preferences.d.ts +7 -0
- package/dist/config/preferences.d.ts.map +1 -0
- package/dist/config/preferences.js +46 -0
- package/dist/config/preferences.js.map +1 -0
- package/dist/config/themes.d.ts +6 -0
- package/dist/config/themes.d.ts.map +1 -0
- package/dist/config/themes.js +295 -0
- package/dist/config/themes.js.map +1 -0
- package/dist/custom-commands/executor.d.ts +12 -0
- package/dist/custom-commands/executor.d.ts.map +1 -0
- package/dist/custom-commands/executor.js +45 -0
- package/dist/custom-commands/executor.js.map +1 -0
- package/dist/custom-commands/index.d.ts +4 -0
- package/dist/custom-commands/index.d.ts.map +1 -0
- package/dist/custom-commands/index.js +4 -0
- package/dist/custom-commands/index.js.map +1 -0
- package/dist/custom-commands/loader.d.ts +41 -0
- package/dist/custom-commands/loader.d.ts.map +1 -0
- package/dist/custom-commands/loader.js +129 -0
- package/dist/custom-commands/loader.js.map +1 -0
- package/dist/custom-commands/parser.d.ts +10 -0
- package/dist/custom-commands/parser.d.ts.map +1 -0
- package/dist/custom-commands/parser.js +181 -0
- package/dist/custom-commands/parser.js.map +1 -0
- package/dist/hooks/useInputState.d.ts +14 -0
- package/dist/hooks/useInputState.d.ts.map +1 -0
- package/dist/hooks/useInputState.js +66 -0
- package/dist/hooks/useInputState.js.map +1 -0
- package/dist/hooks/useTerminalWidth.d.ts +2 -0
- package/dist/hooks/useTerminalWidth.d.ts.map +1 -0
- package/dist/hooks/useTerminalWidth.js +20 -0
- package/dist/hooks/useTerminalWidth.js.map +1 -0
- package/dist/hooks/useTheme.d.ts +9 -0
- package/dist/hooks/useTheme.d.ts.map +1 -0
- package/dist/hooks/useTheme.js +10 -0
- package/dist/hooks/useTheme.js.map +1 -0
- package/dist/hooks/useUIState.d.ts +19 -0
- package/dist/hooks/useUIState.d.ts.map +1 -0
- package/dist/hooks/useUIState.js +46 -0
- package/dist/hooks/useUIState.js.map +1 -0
- package/dist/init/agents-template-generator.d.ts +29 -0
- package/dist/init/agents-template-generator.d.ts.map +1 -0
- package/dist/init/agents-template-generator.js +340 -0
- package/dist/init/agents-template-generator.js.map +1 -0
- package/dist/init/existing-rules-extractor.d.ts +43 -0
- package/dist/init/existing-rules-extractor.d.ts.map +1 -0
- package/dist/init/existing-rules-extractor.js +226 -0
- package/dist/init/existing-rules-extractor.js.map +1 -0
- package/dist/init/file-scanner.d.ts +40 -0
- package/dist/init/file-scanner.d.ts.map +1 -0
- package/dist/init/file-scanner.js +153 -0
- package/dist/init/file-scanner.js.map +1 -0
- package/dist/init/framework-detector.d.ts +57 -0
- package/dist/init/framework-detector.d.ts.map +1 -0
- package/dist/init/framework-detector.js +277 -0
- package/dist/init/framework-detector.js.map +1 -0
- package/dist/init/language-detector.d.ts +31 -0
- package/dist/init/language-detector.d.ts.map +1 -0
- package/dist/init/language-detector.js +205 -0
- package/dist/init/language-detector.js.map +1 -0
- package/dist/init/project-analyzer.d.ts +62 -0
- package/dist/init/project-analyzer.d.ts.map +1 -0
- package/dist/init/project-analyzer.js +294 -0
- package/dist/init/project-analyzer.js.map +1 -0
- package/dist/langgraph-client.d.ts +20 -0
- package/dist/langgraph-client.d.ts.map +1 -0
- package/dist/langgraph-client.js +245 -0
- package/dist/langgraph-client.js.map +1 -0
- package/dist/mcp/mcp-client.d.ts +23 -0
- package/dist/mcp/mcp-client.d.ts.map +1 -0
- package/dist/mcp/mcp-client.js +194 -0
- package/dist/mcp/mcp-client.js.map +1 -0
- package/dist/mcp/mcp-tool-adapter.d.ts +22 -0
- package/dist/mcp/mcp-tool-adapter.d.ts.map +1 -0
- package/dist/mcp/mcp-tool-adapter.js +49 -0
- package/dist/mcp/mcp-tool-adapter.js.map +1 -0
- package/dist/message-handler.d.ts +7 -0
- package/dist/message-handler.d.ts.map +1 -0
- package/dist/message-handler.js +53 -0
- package/dist/message-handler.js.map +1 -0
- package/dist/prompt-history.d.ts +14 -0
- package/dist/prompt-history.d.ts.map +1 -0
- package/dist/prompt-history.js +88 -0
- package/dist/prompt-history.js.map +1 -0
- package/dist/tool-calling/index.d.ts +6 -0
- package/dist/tool-calling/index.d.ts.map +1 -0
- package/dist/tool-calling/index.js +5 -0
- package/dist/tool-calling/index.js.map +1 -0
- package/dist/tool-calling/json-parser.d.ts +7 -0
- package/dist/tool-calling/json-parser.d.ts.map +1 -0
- package/dist/tool-calling/json-parser.js +168 -0
- package/dist/tool-calling/json-parser.js.map +1 -0
- package/dist/tool-calling/xml-parser.d.ts +34 -0
- package/dist/tool-calling/xml-parser.d.ts.map +1 -0
- package/dist/tool-calling/xml-parser.js +113 -0
- package/dist/tool-calling/xml-parser.js.map +1 -0
- package/dist/tools/create-file.d.ts +3 -0
- package/dist/tools/create-file.d.ts.map +1 -0
- package/dist/tools/create-file.js +66 -0
- package/dist/tools/create-file.js.map +1 -0
- package/dist/tools/delete-lines.d.ts +3 -0
- package/dist/tools/delete-lines.d.ts.map +1 -0
- package/dist/tools/delete-lines.js +218 -0
- package/dist/tools/delete-lines.js.map +1 -0
- package/dist/tools/execute-bash.d.ts +3 -0
- package/dist/tools/execute-bash.d.ts.map +1 -0
- package/dist/tools/execute-bash.js +107 -0
- package/dist/tools/execute-bash.js.map +1 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +23 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/insert-lines.d.ts +3 -0
- package/dist/tools/insert-lines.d.ts.map +1 -0
- package/dist/tools/insert-lines.js +185 -0
- package/dist/tools/insert-lines.js.map +1 -0
- package/dist/tools/read-file.d.ts +3 -0
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +81 -0
- package/dist/tools/read-file.js.map +1 -0
- package/dist/tools/read-many-files.d.ts +3 -0
- package/dist/tools/read-many-files.d.ts.map +1 -0
- package/dist/tools/read-many-files.js +109 -0
- package/dist/tools/read-many-files.js.map +1 -0
- package/dist/tools/replace-lines.d.ts +3 -0
- package/dist/tools/replace-lines.d.ts.map +1 -0
- package/dist/tools/replace-lines.js +220 -0
- package/dist/tools/replace-lines.js.map +1 -0
- package/dist/tools/tool-manager.d.ts +54 -0
- package/dist/tools/tool-manager.d.ts.map +1 -0
- package/dist/tools/tool-manager.js +108 -0
- package/dist/tools/tool-manager.js.map +1 -0
- package/dist/types/app.d.ts +46 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/app.js +2 -0
- package/dist/types/app.js.map +1 -0
- package/dist/types/commands.d.ts +36 -0
- package/dist/types/commands.d.ts.map +1 -0
- package/dist/types/commands.js +2 -0
- package/dist/types/commands.js.map +1 -0
- package/dist/types/components.d.ts +87 -0
- package/dist/types/components.d.ts.map +1 -0
- package/dist/types/components.js +2 -0
- package/dist/types/components.js.map +1 -0
- package/dist/types/config.d.ts +35 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/core.d.ts +57 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +2 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/hooks.d.ts +26 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/hooks.js +2 -0
- package/dist/types/hooks.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/mcp.d.ts +19 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +2 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/tools.d.ts +31 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +2 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/ui.d.ts +22 -0
- package/dist/types/ui.d.ts.map +1 -0
- package/dist/types/ui.js +2 -0
- package/dist/types/ui.js.map +1 -0
- package/dist/types/utils.d.ts +19 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +2 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/utils/message-queue.d.ts +8 -0
- package/dist/utils/message-queue.d.ts.map +1 -0
- package/dist/utils/message-queue.js +50 -0
- package/dist/utils/message-queue.js.map +1 -0
- package/dist/utils/programming-language-helper.d.ts +2 -0
- package/dist/utils/programming-language-helper.d.ts.map +1 -0
- package/dist/utils/programming-language-helper.js +32 -0
- package/dist/utils/programming-language-helper.js.map +1 -0
- package/dist/utils/prompt-processor.d.ts +6 -0
- package/dist/utils/prompt-processor.d.ts.map +1 -0
- package/dist/utils/prompt-processor.js +103 -0
- package/dist/utils/prompt-processor.js.map +1 -0
- package/dist/utils/update-checker.d.ts +6 -0
- package/dist/utils/update-checker.d.ts.map +1 -0
- package/dist/utils/update-checker.js +120 -0
- package/dist/utils/update-checker.js.map +1 -0
- package/package.json +97 -0
- package/source/app/prompts/main-prompt.md +107 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { loadPreferences, savePreferences } from '../../config/preferences.js';
|
|
4
|
+
import { logError } from '../../utils/message-queue.js';
|
|
5
|
+
import { shouldLog } from '../../config/logging.js';
|
|
6
|
+
/**
|
|
7
|
+
* Custom hook for managing directory trust functionality.
|
|
8
|
+
* Handles checking if a directory is trusted and adding it to trusted directories.
|
|
9
|
+
*
|
|
10
|
+
* @param directory - The directory path to check trust for (defaults to current working directory)
|
|
11
|
+
* @returns Object containing trust state and handler functions
|
|
12
|
+
*/
|
|
13
|
+
export function useDirectoryTrust(directory = process.cwd()) {
|
|
14
|
+
const [isTrusted, setIsTrusted] = useState(false);
|
|
15
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
16
|
+
const [error, setError] = useState(null);
|
|
17
|
+
// Check if directory is trusted on mount and when directory changes
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const checkTrustStatus = async () => {
|
|
20
|
+
try {
|
|
21
|
+
setIsLoading(true);
|
|
22
|
+
setError(null);
|
|
23
|
+
const preferences = loadPreferences();
|
|
24
|
+
const trustedDirectories = preferences.trustedDirectories || [];
|
|
25
|
+
// Normalize paths for comparison (resolve any relative path components)
|
|
26
|
+
const normalizedDirectory = path.resolve(directory);
|
|
27
|
+
const isTrustedDir = trustedDirectories.some(trustedDir => path.resolve(trustedDir) === normalizedDirectory);
|
|
28
|
+
setIsTrusted(isTrustedDir);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
|
32
|
+
setError(`Failed to check directory trust status: ${errorMessage}`);
|
|
33
|
+
if (shouldLog('warn')) {
|
|
34
|
+
logError(`useDirectoryTrust: ${errorMessage}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
setIsLoading(false);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
checkTrustStatus();
|
|
42
|
+
}, [directory]);
|
|
43
|
+
// Handler to confirm trust for the current directory
|
|
44
|
+
const handleConfirmTrust = useCallback(() => {
|
|
45
|
+
try {
|
|
46
|
+
setError(null);
|
|
47
|
+
const preferences = loadPreferences();
|
|
48
|
+
const trustedDirectories = preferences.trustedDirectories || [];
|
|
49
|
+
// Normalize the directory path before storing and checking
|
|
50
|
+
const normalizedDirectory = path.resolve(directory);
|
|
51
|
+
// Only add if not already trusted (check using normalized paths)
|
|
52
|
+
if (!trustedDirectories.some(trustedDir => path.resolve(trustedDir) === normalizedDirectory)) {
|
|
53
|
+
trustedDirectories.push(normalizedDirectory);
|
|
54
|
+
preferences.trustedDirectories = trustedDirectories;
|
|
55
|
+
savePreferences(preferences);
|
|
56
|
+
if (shouldLog('info')) {
|
|
57
|
+
logError(`useDirectoryTrust (info): Directory added to trusted list: ${normalizedDirectory}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
setIsTrusted(true);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
|
64
|
+
setError(`Failed to save directory trust: ${errorMessage}`);
|
|
65
|
+
if (shouldLog('warn')) {
|
|
66
|
+
logError(`useDirectoryTrust: ${errorMessage}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [directory]);
|
|
70
|
+
return {
|
|
71
|
+
isTrusted,
|
|
72
|
+
handleConfirmTrust,
|
|
73
|
+
isTrustLoading: isLoading,
|
|
74
|
+
isTrustedError: error,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=useDirectoryTrust.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDirectoryTrust.js","sourceRoot":"","sources":["../../../source/app/hooks/useDirectoryTrust.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAC,MAAM,OAAO,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OA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CAAmC,YAAY,EAAE,CAAC,CAAC;YAE5D,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpB,QAAQ,CAAC,sBAAsB,YAAY,EAAE,CAAC,CAAC;YACnD,CAAC;QACL,CAAC;IACL,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO;QACH,SAAS;QACT,kBAAkB;QAClB,cAAc,EAAE,SAAS;QACzB,cAAc,EAAE,KAAK;KACxB,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LLMClient, Message, ProviderType } from '../../types/core.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { ThemePreset } from '../../types/ui.js';
|
|
4
|
+
interface UseModeHandlersProps {
|
|
5
|
+
client: LLMClient | null;
|
|
6
|
+
currentModel: string;
|
|
7
|
+
currentProvider: ProviderType;
|
|
8
|
+
setClient: (client: LLMClient | null) => void;
|
|
9
|
+
setCurrentModel: (model: string) => void;
|
|
10
|
+
setCurrentProvider: (provider: ProviderType) => void;
|
|
11
|
+
setCurrentTheme: (theme: ThemePreset) => void;
|
|
12
|
+
setMessages: (messages: Message[]) => void;
|
|
13
|
+
setIsModelSelectionMode: (mode: boolean) => void;
|
|
14
|
+
setIsProviderSelectionMode: (mode: boolean) => void;
|
|
15
|
+
setIsThemeSelectionMode: (mode: boolean) => void;
|
|
16
|
+
addToChatQueue: (component: React.ReactNode) => void;
|
|
17
|
+
componentKeyCounter: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function useModeHandlers({ client, currentModel, currentProvider, setClient, setCurrentModel, setCurrentProvider, setCurrentTheme, setMessages, setIsModelSelectionMode, setIsProviderSelectionMode, setIsThemeSelectionMode, addToChatQueue, componentKeyCounter, }: UseModeHandlersProps): {
|
|
20
|
+
enterModelSelectionMode: () => void;
|
|
21
|
+
enterProviderSelectionMode: () => void;
|
|
22
|
+
enterThemeSelectionMode: () => void;
|
|
23
|
+
handleModelSelect: (selectedModel: string) => Promise<void>;
|
|
24
|
+
handleModelSelectionCancel: () => void;
|
|
25
|
+
handleProviderSelect: (selectedProvider: ProviderType) => Promise<void>;
|
|
26
|
+
handleProviderSelectionCancel: () => void;
|
|
27
|
+
handleThemeSelect: (selectedTheme: ThemePreset) => void;
|
|
28
|
+
handleThemeSelectionCancel: () => void;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=useModeHandlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModeHandlers.d.ts","sourceRoot":"","sources":["../../../source/app/hooks/useModeHandlers.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAKrE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAEnD,UAAU,oBAAoB;IAC7B,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,YAAY,CAAC;IAC9B,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,kBAAkB,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IACrD,eAAe,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC9C,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3C,uBAAuB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,0BAA0B,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,uBAAuB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,cAAc,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;IACrD,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,eAAe,CAAC,EAC/B,MAAM,EACN,YAAY,EACZ,eAAe,EACf,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,0BAA0B,EAC1B,uBAAuB,EACvB,cAAc,EACd,mBAAmB,GACnB,EAAE,oBAAoB;;;;uCAa0B,MAAM;;6CA0BA,YAAY;;uCAoExB,WAAW;;EAoCrD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createLLMClient } from '../../client-factory.js';
|
|
3
|
+
import { updateLastUsed, savePreferences, loadPreferences } from '../../config/preferences.js';
|
|
4
|
+
import SuccessMessage from '../../components/success-message.js';
|
|
5
|
+
import ErrorMessage from '../../components/error-message.js';
|
|
6
|
+
export function useModeHandlers({ client, currentModel, currentProvider, setClient, setCurrentModel, setCurrentProvider, setCurrentTheme, setMessages, setIsModelSelectionMode, setIsProviderSelectionMode, setIsThemeSelectionMode, addToChatQueue, componentKeyCounter, }) {
|
|
7
|
+
// Helper function to enter model selection mode
|
|
8
|
+
const enterModelSelectionMode = () => {
|
|
9
|
+
setIsModelSelectionMode(true);
|
|
10
|
+
};
|
|
11
|
+
// Helper function to enter provider selection mode
|
|
12
|
+
const enterProviderSelectionMode = () => {
|
|
13
|
+
setIsProviderSelectionMode(true);
|
|
14
|
+
};
|
|
15
|
+
// Handle model selection
|
|
16
|
+
const handleModelSelect = async (selectedModel) => {
|
|
17
|
+
if (client && selectedModel !== currentModel) {
|
|
18
|
+
client.setModel(selectedModel);
|
|
19
|
+
setCurrentModel(selectedModel);
|
|
20
|
+
// Update preferences
|
|
21
|
+
updateLastUsed(currentProvider, selectedModel);
|
|
22
|
+
// Add success message to chat queue
|
|
23
|
+
addToChatQueue(_jsx(SuccessMessage, { message: `Model changed to: ${selectedModel}`, hideBox: true }, `model-changed-${componentKeyCounter}`));
|
|
24
|
+
}
|
|
25
|
+
setIsModelSelectionMode(false);
|
|
26
|
+
};
|
|
27
|
+
// Handle model selection cancel
|
|
28
|
+
const handleModelSelectionCancel = () => {
|
|
29
|
+
setIsModelSelectionMode(false);
|
|
30
|
+
};
|
|
31
|
+
// Handle provider selection
|
|
32
|
+
const handleProviderSelect = async (selectedProvider) => {
|
|
33
|
+
if (selectedProvider !== currentProvider) {
|
|
34
|
+
try {
|
|
35
|
+
// Create new client for the selected provider
|
|
36
|
+
const { client: newClient, actualProvider } = await createLLMClient(selectedProvider);
|
|
37
|
+
// Check if we got the provider we requested
|
|
38
|
+
if (actualProvider !== selectedProvider) {
|
|
39
|
+
// Provider was forced to a different one (likely due to missing config)
|
|
40
|
+
addToChatQueue(_jsx(ErrorMessage, { message: `${selectedProvider} is not available. Please ensure it's properly configured in agents.config.json.`, hideBox: true }, `provider-forced-${componentKeyCounter}`));
|
|
41
|
+
return; // Don't change anything
|
|
42
|
+
}
|
|
43
|
+
setClient(newClient);
|
|
44
|
+
setCurrentProvider(actualProvider);
|
|
45
|
+
// Set the model from the new client
|
|
46
|
+
const newModel = newClient.getCurrentModel();
|
|
47
|
+
setCurrentModel(newModel);
|
|
48
|
+
// Clear message history when switching providers
|
|
49
|
+
setMessages([]);
|
|
50
|
+
await newClient.clearContext();
|
|
51
|
+
// Update preferences - use the actualProvider (which is what was successfully created)
|
|
52
|
+
updateLastUsed(actualProvider, newModel);
|
|
53
|
+
// Add success message to chat queue
|
|
54
|
+
addToChatQueue(_jsx(SuccessMessage, { message: `Provider changed to: ${actualProvider}, model: ${newModel}. Chat history cleared.`, hideBox: true }, `provider-changed-${componentKeyCounter}`));
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
// Add error message if provider change fails
|
|
58
|
+
addToChatQueue(_jsx(ErrorMessage, { message: `Failed to change provider to ${selectedProvider}: ${error}`, hideBox: true }, `provider-error-${componentKeyCounter}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
setIsProviderSelectionMode(false);
|
|
62
|
+
};
|
|
63
|
+
// Handle provider selection cancel
|
|
64
|
+
const handleProviderSelectionCancel = () => {
|
|
65
|
+
setIsProviderSelectionMode(false);
|
|
66
|
+
};
|
|
67
|
+
// Helper function to enter theme selection mode
|
|
68
|
+
const enterThemeSelectionMode = () => {
|
|
69
|
+
setIsThemeSelectionMode(true);
|
|
70
|
+
};
|
|
71
|
+
// Handle theme selection
|
|
72
|
+
const handleThemeSelect = (selectedTheme) => {
|
|
73
|
+
const preferences = loadPreferences();
|
|
74
|
+
preferences.selectedTheme = selectedTheme;
|
|
75
|
+
savePreferences(preferences);
|
|
76
|
+
// Update the theme state immediately for real-time switching
|
|
77
|
+
setCurrentTheme(selectedTheme);
|
|
78
|
+
// Add success message to chat queue
|
|
79
|
+
addToChatQueue(_jsx(SuccessMessage, { message: `Theme changed to: ${selectedTheme}.`, hideBox: true }, `theme-changed-${componentKeyCounter}`));
|
|
80
|
+
setIsThemeSelectionMode(false);
|
|
81
|
+
};
|
|
82
|
+
// Handle theme selection cancel
|
|
83
|
+
const handleThemeSelectionCancel = () => {
|
|
84
|
+
setIsThemeSelectionMode(false);
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
enterModelSelectionMode,
|
|
88
|
+
enterProviderSelectionMode,
|
|
89
|
+
enterThemeSelectionMode,
|
|
90
|
+
handleModelSelect,
|
|
91
|
+
handleModelSelectionCancel,
|
|
92
|
+
handleProviderSelect,
|
|
93
|
+
handleProviderSelectionCancel,
|
|
94
|
+
handleThemeSelect,
|
|
95
|
+
handleThemeSelectionCancel,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=useModeHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModeHandlers.js","sourceRoot":"","sources":["../../../source/app/hooks/useModeHandlers.tsx"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BAAkB,mBAAmB,EAAE,CAG3C,CACF,CAAC;YACH,CAAC;QACF,CAAC;QACD,0BAA0B,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,mCAAmC;IACnC,MAAM,6BAA6B,GAAG,GAAG,EAAE;QAC1C,0BAA0B,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,gDAAgD;IAChD,MAAM,uBAAuB,GAAG,GAAG,EAAE;QACpC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC;IAEF,yBAAyB;IACzB,MAAM,iBAAiB,GAAG,CAAC,aAA0B,EAAE,EAAE;QACxD,MAAM,WAAW,GAAG,eAAe,EAAE,CAAC;QACtC,WAAW,CAAC,aAAa,GAAG,aAAa,CAAC;QAC1C,eAAe,CAAC,WAAW,CAAC,CAAC;QAE7B,6DAA6D;QAC7D,eAAe,CAAC,aAAa,CAAC,CAAC;QAE/B,oCAAoC;QACpC,cAAc,CACb,KAAC,cAAc,IAEd,OAAO,EAAE,qBAAqB,aAAa,GAAG,EAC9C,OAAO,EAAE,IAAI,IAFR,iBAAiB,mBAAmB,EAAE,CAG1C,CACF,CAAC;QAEF,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,gCAAgC;IAChC,MAAM,0BAA0B,GAAG,GAAG,EAAE;QACvC,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO;QACN,uBAAuB;QACvB,0BAA0B;QAC1B,uBAAuB;QACvB,iBAAiB;QACjB,0BAA0B;QAC1B,oBAAoB;QACpB,6BAA6B;QAC7B,iBAAiB;QACjB,0BAA0B;KAC1B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Message, LLMClient, ProviderType } from '../../types/core.js';
|
|
2
|
+
import { ConversationContext } from './useAppState.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
interface UseToolHandlerProps {
|
|
5
|
+
pendingToolCalls: any[];
|
|
6
|
+
currentToolIndex: number;
|
|
7
|
+
completedToolResults: any[];
|
|
8
|
+
currentConversationContext: ConversationContext | null;
|
|
9
|
+
setPendingToolCalls: (calls: any[]) => void;
|
|
10
|
+
setCurrentToolIndex: (index: number) => void;
|
|
11
|
+
setCompletedToolResults: (results: any[]) => void;
|
|
12
|
+
setCurrentConversationContext: (context: ConversationContext | null) => void;
|
|
13
|
+
setIsToolConfirmationMode: (mode: boolean) => void;
|
|
14
|
+
setIsToolExecuting: (executing: boolean) => void;
|
|
15
|
+
setMessages: (messages: Message[]) => void;
|
|
16
|
+
addToChatQueue: (component: React.ReactNode) => void;
|
|
17
|
+
componentKeyCounter: number;
|
|
18
|
+
resetToolConfirmationState: () => void;
|
|
19
|
+
onProcessAssistantResponse: (systemMessage: Message, messages: Message[]) => Promise<void>;
|
|
20
|
+
client?: LLMClient | null;
|
|
21
|
+
currentProvider?: ProviderType;
|
|
22
|
+
}
|
|
23
|
+
export declare function useToolHandler({ pendingToolCalls, currentToolIndex, completedToolResults, currentConversationContext, setPendingToolCalls, setCurrentToolIndex, setCompletedToolResults, setCurrentConversationContext, setIsToolConfirmationMode, setIsToolExecuting, setMessages, addToChatQueue, componentKeyCounter, resetToolConfirmationState, onProcessAssistantResponse, client, currentProvider, }: UseToolHandlerProps): {
|
|
24
|
+
handleToolConfirmation: (confirmed: boolean) => Promise<void>;
|
|
25
|
+
handleToolConfirmationCancel: () => void;
|
|
26
|
+
startToolConfirmationFlow: (toolCalls: any[], updatedMessages: Message[], assistantMsg: Message, systemMessage: Message) => void;
|
|
27
|
+
displayToolResult: (toolCall: any, result: any) => Promise<void>;
|
|
28
|
+
continueConversationWithToolResults: (toolResults?: any[]) => Promise<void>;
|
|
29
|
+
executeCurrentTool: () => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=useToolHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AAY,CAAC;CAC/B;AAED,wBAAgB,cAAc,CAAC,EAC9B,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,yBAAyB,EACzB,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,MAAM,EACN,eAAe,GACf,EAAE,mBAAmB;wCAyG4B,OAAO;;2CAyF5C,GAAG,EAAE,mBACC,OAAO,EAAE,gBACZ,OAAO,iBACN,OAAO;kCAlMoB,GAAG,UAAU,GAAG;wDAgEM,GAAG,EAAE;;EAuJtE"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { processToolUse, getToolManager } from '../../message-handler.js';
|
|
3
|
+
import InfoMessage from '../../components/info-message.js';
|
|
4
|
+
import ErrorMessage from '../../components/error-message.js';
|
|
5
|
+
import ToolMessage from '../../components/tool-message.js';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
export function useToolHandler({ pendingToolCalls, currentToolIndex, completedToolResults, currentConversationContext, setPendingToolCalls, setCurrentToolIndex, setCompletedToolResults, setCurrentConversationContext, setIsToolConfirmationMode, setIsToolExecuting, setMessages, addToChatQueue, componentKeyCounter, resetToolConfirmationState, onProcessAssistantResponse, client, currentProvider, }) {
|
|
8
|
+
// Display tool result with proper formatting
|
|
9
|
+
const displayToolResult = async (toolCall, result) => {
|
|
10
|
+
const toolManager = getToolManager();
|
|
11
|
+
if (toolManager) {
|
|
12
|
+
const formatter = toolManager.getToolFormatter(result.name);
|
|
13
|
+
if (formatter) {
|
|
14
|
+
try {
|
|
15
|
+
// Parse arguments if they're a JSON string
|
|
16
|
+
let parsedArgs = toolCall.function.arguments;
|
|
17
|
+
if (typeof parsedArgs === 'string') {
|
|
18
|
+
try {
|
|
19
|
+
parsedArgs = JSON.parse(parsedArgs);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
// If parsing fails, use as-is
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const formattedResult = await formatter(parsedArgs, result.content);
|
|
26
|
+
if (React.isValidElement(formattedResult)) {
|
|
27
|
+
addToChatQueue(React.cloneElement(formattedResult, {
|
|
28
|
+
key: `tool-result-${result.tool_call_id}-${componentKeyCounter}-${Date.now()}`,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: String(formattedResult), hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}-${Date.now()}`));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (formatterError) {
|
|
36
|
+
// If formatter fails, show raw result
|
|
37
|
+
addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: result.content, hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}`));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// No formatter, show raw result
|
|
42
|
+
addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: result.content, hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}`));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// Continue conversation with tool results - maintains the proper loop
|
|
47
|
+
const continueConversationWithToolResults = async (toolResults) => {
|
|
48
|
+
if (!currentConversationContext) {
|
|
49
|
+
resetToolConfirmationState();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Use passed results or fallback to state (for backwards compatibility)
|
|
53
|
+
const resultsToUse = toolResults || completedToolResults;
|
|
54
|
+
const { updatedMessages, assistantMsg, systemMessage } = currentConversationContext;
|
|
55
|
+
// Format tool results as standard tool messages
|
|
56
|
+
const toolMessages = resultsToUse.map(result => ({
|
|
57
|
+
role: 'tool',
|
|
58
|
+
content: result.content || '',
|
|
59
|
+
tool_call_id: result.tool_call_id,
|
|
60
|
+
name: result.name,
|
|
61
|
+
}));
|
|
62
|
+
// Update conversation history with tool results
|
|
63
|
+
// The assistantMsg is NOT included in updatedMessages (updatedMessages is the state before adding assistantMsg)
|
|
64
|
+
// We need to add both the assistant message and the tool results
|
|
65
|
+
const updatedMessagesWithTools = [
|
|
66
|
+
...updatedMessages,
|
|
67
|
+
assistantMsg, // Add the assistant message with tool_calls intact for proper tool_call_id matching
|
|
68
|
+
...toolMessages,
|
|
69
|
+
];
|
|
70
|
+
setMessages(updatedMessagesWithTools);
|
|
71
|
+
// Reset tool confirmation state since we're continuing the conversation
|
|
72
|
+
resetToolConfirmationState();
|
|
73
|
+
// Continue the main conversation loop with tool results as context
|
|
74
|
+
await onProcessAssistantResponse(systemMessage, updatedMessagesWithTools);
|
|
75
|
+
};
|
|
76
|
+
// Handle tool confirmation
|
|
77
|
+
const handleToolConfirmation = async (confirmed) => {
|
|
78
|
+
if (!confirmed) {
|
|
79
|
+
// User cancelled - show message and reset state
|
|
80
|
+
addToChatQueue(_jsx(InfoMessage, { message: "Tool execution cancelled by user", hideBox: true }, `tool-cancelled-${componentKeyCounter}`));
|
|
81
|
+
resetToolConfirmationState();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Move to tool execution state - this allows UI to update immediately
|
|
85
|
+
setIsToolConfirmationMode(false);
|
|
86
|
+
setIsToolExecuting(true);
|
|
87
|
+
// Execute tools asynchronously
|
|
88
|
+
setImmediate(() => {
|
|
89
|
+
executeCurrentTool();
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
// Execute the current tool asynchronously
|
|
93
|
+
const executeCurrentTool = async () => {
|
|
94
|
+
const currentTool = pendingToolCalls[currentToolIndex];
|
|
95
|
+
// Check if this is an MCP tool and show appropriate messaging
|
|
96
|
+
const toolManager = getToolManager();
|
|
97
|
+
if (toolManager) {
|
|
98
|
+
const mcpInfo = toolManager.getMCPToolInfo(currentTool.function.name);
|
|
99
|
+
if (mcpInfo.isMCPTool) {
|
|
100
|
+
addToChatQueue(_jsx(InfoMessage, { message: `Executing MCP tool "${currentTool.function.name}" from server "${mcpInfo.serverName}"`, hideBox: true }, `mcp-tool-executing-${componentKeyCounter}-${Date.now()}`));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const result = await processToolUse(currentTool);
|
|
105
|
+
const newResults = [...completedToolResults, result];
|
|
106
|
+
setCompletedToolResults(newResults);
|
|
107
|
+
// Display the tool result
|
|
108
|
+
await displayToolResult(currentTool, result);
|
|
109
|
+
// Move to next tool or complete the process
|
|
110
|
+
if (currentToolIndex + 1 < pendingToolCalls.length) {
|
|
111
|
+
setCurrentToolIndex(currentToolIndex + 1);
|
|
112
|
+
// Return to confirmation mode for next tool
|
|
113
|
+
setIsToolExecuting(false);
|
|
114
|
+
setIsToolConfirmationMode(true);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// All tools executed, continue conversation loop with the updated results
|
|
118
|
+
setIsToolExecuting(false);
|
|
119
|
+
await continueConversationWithToolResults(newResults);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
setIsToolExecuting(false);
|
|
124
|
+
addToChatQueue(_jsx(ErrorMessage, { message: `Tool execution error: ${error}` }, `tool-exec-error-${componentKeyCounter}`));
|
|
125
|
+
resetToolConfirmationState();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// Handle tool confirmation cancel
|
|
129
|
+
const handleToolConfirmationCancel = () => {
|
|
130
|
+
addToChatQueue(_jsx(InfoMessage, { message: "Tool execution cancelled by user", hideBox: true }, `tool-cancelled-${componentKeyCounter}`));
|
|
131
|
+
resetToolConfirmationState();
|
|
132
|
+
};
|
|
133
|
+
// Start tool confirmation flow
|
|
134
|
+
const startToolConfirmationFlow = (toolCalls, updatedMessages, assistantMsg, systemMessage) => {
|
|
135
|
+
setPendingToolCalls(toolCalls);
|
|
136
|
+
setCurrentToolIndex(0);
|
|
137
|
+
setCompletedToolResults([]);
|
|
138
|
+
setCurrentConversationContext({
|
|
139
|
+
updatedMessages,
|
|
140
|
+
assistantMsg,
|
|
141
|
+
systemMessage,
|
|
142
|
+
});
|
|
143
|
+
setIsToolConfirmationMode(true);
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
handleToolConfirmation,
|
|
147
|
+
handleToolConfirmationCancel,
|
|
148
|
+
startToolConfirmationFlow,
|
|
149
|
+
displayToolResult,
|
|
150
|
+
continueConversationWithToolResults,
|
|
151
|
+
executeCurrentTool,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=useToolHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolHandler.js","sourceRoot":"","sources":["../../../source/app/hooks/useToolHandler.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAExE,OAAO,WAAW,MAAM,kCAAkC,CAAC;AAC3D,OAAO,YAAY,MAAM,mCAAmC,CAAC;AAC7D,OAAO,WAAW,MAAM,kCAAkC,CAAC;AAC3D,OAAO,KAAK,MAAM,OAAO,CAAC;AAyB1B,MAAM,UAAU,cAAc,CAAC,EAC9B,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,yBAAyB,EACzB,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,MAAM,EACN,eAAe,GACM;IAErB,6CAA6C;IAC7C,MAAM,iBAAiB,GAAG,KAAK,EAAE,QAAa,EAAE,MAAW,EAAE,EAAE;QAC9D,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;QACrC,IAAI,WAAW,EAAE,CAAC;YACjB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;YACf,YAAY;YACZ,aAAa;SACb,CAAC,CAAC;QACH,yBAAyB,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,OAAO;QACN,sBAAsB;QACtB,4BAA4B;QAC5B,yBAAyB;QACzB,iBAAiB;QACjB,mCAAmC;QACnC,kBAAkB;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MessageSubmissionOptions } from '../../types/index.js';
|
|
2
|
+
export declare function handleMessageSubmission(message: string, options: MessageSubmissionOptions): Promise<void>;
|
|
3
|
+
export declare function createClearMessagesHandler(setMessages: (messages: any[]) => void, client: any): () => Promise<void>;
|
|
4
|
+
//# sourceMappingURL=appUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appUtils.d.ts","sourceRoot":"","sources":["../../../source/app/utils/appUtils.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,sBAAsB,CAAC;AAEnE,wBAAsB,uBAAuB,CAC5C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,wBAAwB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAyKf;AAED,wBAAgB,0BAA0B,CACzC,WAAW,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,IAAI,EACtC,MAAM,EAAE,GAAG,uBASX"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { commandRegistry } from '../../commands.js';
|
|
3
|
+
import { parseInput } from '../../command-parser.js';
|
|
4
|
+
import { toolRegistry } from '../../tools/index.js';
|
|
5
|
+
import InfoMessage from '../../components/info-message.js';
|
|
6
|
+
import ToolMessage from '../../components/tool-message.js';
|
|
7
|
+
import ErrorMessage from '../../components/error-message.js';
|
|
8
|
+
export async function handleMessageSubmission(message, options) {
|
|
9
|
+
const { customCommandCache, customCommandLoader, customCommandExecutor, onClearMessages, onEnterModelSelectionMode, onEnterProviderSelectionMode, onEnterThemeSelectionMode, onHandleChatMessage, onAddToChatQueue, componentKeyCounter, setMessages, messages, setIsBashExecuting, setCurrentBashCommand, } = options;
|
|
10
|
+
// Parse the input to determine its type
|
|
11
|
+
const parsedInput = parseInput(message);
|
|
12
|
+
// Handle bash commands (prefixed with !)
|
|
13
|
+
if (parsedInput.isBashCommand && parsedInput.bashCommand) {
|
|
14
|
+
const bashCommand = parsedInput.bashCommand;
|
|
15
|
+
// Set bash execution state to show spinner
|
|
16
|
+
setCurrentBashCommand(bashCommand);
|
|
17
|
+
setIsBashExecuting(true);
|
|
18
|
+
try {
|
|
19
|
+
// Execute the bash command
|
|
20
|
+
const resultString = await toolRegistry.execute_bash({
|
|
21
|
+
command: bashCommand,
|
|
22
|
+
});
|
|
23
|
+
// Parse the result
|
|
24
|
+
let result;
|
|
25
|
+
try {
|
|
26
|
+
result = JSON.parse(resultString);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
// If parsing fails, treat as plain string
|
|
30
|
+
result = {
|
|
31
|
+
fullOutput: resultString,
|
|
32
|
+
llmContext: resultString.length > 4000
|
|
33
|
+
? resultString.substring(0, 4000)
|
|
34
|
+
: resultString,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Create a proper display of the command and its full output
|
|
38
|
+
const commandOutput = `$ ${bashCommand}
|
|
39
|
+
${result.fullOutput || '(No output)'}`;
|
|
40
|
+
// Add the command and its output to the chat queue
|
|
41
|
+
onAddToChatQueue(React.createElement(ToolMessage, {
|
|
42
|
+
key: `bash-result-${componentKeyCounter}`,
|
|
43
|
+
message: commandOutput,
|
|
44
|
+
hideBox: true,
|
|
45
|
+
isBashMode: true,
|
|
46
|
+
}));
|
|
47
|
+
// Add the truncated output to the LLM context for future interactions
|
|
48
|
+
if (result.llmContext) {
|
|
49
|
+
const toolMessage = {
|
|
50
|
+
role: 'tool',
|
|
51
|
+
content: result.llmContext,
|
|
52
|
+
name: 'execute_bash',
|
|
53
|
+
};
|
|
54
|
+
setMessages([...messages, toolMessage]);
|
|
55
|
+
}
|
|
56
|
+
// Clear bash execution state
|
|
57
|
+
setIsBashExecuting(false);
|
|
58
|
+
setCurrentBashCommand('');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// Show error message if command fails
|
|
63
|
+
onAddToChatQueue(React.createElement(ErrorMessage, {
|
|
64
|
+
key: `bash-error-${componentKeyCounter}`,
|
|
65
|
+
message: `Error executing command: ${error.message}`,
|
|
66
|
+
}));
|
|
67
|
+
// Clear bash execution state
|
|
68
|
+
setIsBashExecuting(false);
|
|
69
|
+
setCurrentBashCommand('');
|
|
70
|
+
// Don't send to LLM - just return here
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Handle regular commands (prefixed with /)
|
|
75
|
+
if (message.startsWith('/')) {
|
|
76
|
+
const commandName = message.slice(1).split(' ')[0];
|
|
77
|
+
// Check for custom command first
|
|
78
|
+
const customCommand = customCommandCache.get(commandName) ||
|
|
79
|
+
customCommandLoader?.getCommand(commandName);
|
|
80
|
+
if (customCommand) {
|
|
81
|
+
// Execute custom command with any arguments
|
|
82
|
+
const args = message
|
|
83
|
+
.slice(commandName.length + 1)
|
|
84
|
+
.trim()
|
|
85
|
+
.split(/\s+/)
|
|
86
|
+
.filter(arg => arg);
|
|
87
|
+
const processedPrompt = await customCommandExecutor?.execute(customCommand, args);
|
|
88
|
+
// Send the processed prompt to the AI
|
|
89
|
+
if (processedPrompt) {
|
|
90
|
+
await onHandleChatMessage(processedPrompt);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Handle special commands that need app state access
|
|
95
|
+
if (commandName === 'clear') {
|
|
96
|
+
await onClearMessages();
|
|
97
|
+
// Still show the clear command result
|
|
98
|
+
}
|
|
99
|
+
else if (commandName === 'model') {
|
|
100
|
+
onEnterModelSelectionMode();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
else if (commandName === 'provider') {
|
|
104
|
+
onEnterProviderSelectionMode();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
else if (commandName === 'theme') {
|
|
108
|
+
onEnterThemeSelectionMode();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// Execute built-in command
|
|
112
|
+
const totalTokens = messages.reduce((sum, msg) => sum + options.getMessageTokens(msg), 0);
|
|
113
|
+
const result = await commandRegistry.execute(message.slice(1), messages, {
|
|
114
|
+
provider: options.provider,
|
|
115
|
+
model: options.model,
|
|
116
|
+
tokens: totalTokens,
|
|
117
|
+
});
|
|
118
|
+
if (result) {
|
|
119
|
+
// Check if result is JSX (React element)
|
|
120
|
+
if (React.isValidElement(result)) {
|
|
121
|
+
onAddToChatQueue(result);
|
|
122
|
+
}
|
|
123
|
+
else if (typeof result === 'string' && result.trim()) {
|
|
124
|
+
onAddToChatQueue(React.createElement(InfoMessage, {
|
|
125
|
+
key: `command-result-${componentKeyCounter}`,
|
|
126
|
+
message: result,
|
|
127
|
+
hideBox: true,
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Return here to avoid sending to LLM
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Regular chat message - process with AI
|
|
136
|
+
await onHandleChatMessage(message);
|
|
137
|
+
}
|
|
138
|
+
export function createClearMessagesHandler(setMessages, client) {
|
|
139
|
+
return async () => {
|
|
140
|
+
// Clear message history and client context
|
|
141
|
+
setMessages([]);
|
|
142
|
+
if (client) {
|
|
143
|
+
await client.clearContext();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=appUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appUtils.js","sourceRoot":"","sources":["../../../source/app/utils/appUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OA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