centaurus-cli 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/types.js +0 -1
- package/dist/ai/types.js.map +1 -1
- package/dist/cli-adapter.js +5047 -5037
- package/dist/cli-adapter.js.map +1 -1
- package/dist/commands/CommandParser.js +372 -315
- package/dist/commands/CommandParser.js.map +1 -1
- package/dist/config/build-config.js +11 -42
- package/dist/config/build-config.js.map +1 -1
- package/dist/config/defaultConfig.js +94 -82
- package/dist/config/defaultConfig.js.map +1 -1
- package/dist/config/manager.js +144 -160
- package/dist/config/manager.js.map +1 -1
- package/dist/config/mcp-config-manager.js +411 -364
- package/dist/config/mcp-config-manager.js.map +1 -1
- package/dist/config/models.js +118 -185
- package/dist/config/models.js.map +1 -1
- package/dist/config/slash-commands.js +186 -184
- package/dist/config/slash-commands.js.map +1 -1
- package/dist/config/types.js +33 -26
- package/dist/config/types.js.map +1 -1
- package/dist/context/command-detector.js +63 -67
- package/dist/context/command-detector.js.map +1 -1
- package/dist/context/context-manager.js +533 -518
- package/dist/context/context-manager.js.map +1 -1
- package/dist/context/handlers/docker-handler.js +518 -576
- package/dist/context/handlers/docker-handler.js.map +1 -1
- package/dist/context/handlers/ssh-handler.js +1050 -1109
- package/dist/context/handlers/ssh-handler.js.map +1 -1
- package/dist/context/handlers/wsl-handler.js +558 -630
- package/dist/context/handlers/wsl-handler.js.map +1 -1
- package/dist/context/index.js +42 -6
- package/dist/context/index.js.map +1 -1
- package/dist/context/subshell-handler.js +0 -4
- package/dist/context/subshell-handler.js.map +1 -1
- package/dist/context/types.js +20 -31
- package/dist/context/types.js.map +1 -1
- package/dist/hooks/useConnectivity.js +13 -10
- package/dist/hooks/useConnectivity.js.map +1 -1
- package/dist/hooks/useTerminalDimensions.js +67 -79
- package/dist/hooks/useTerminalDimensions.js.map +1 -1
- package/dist/index.js +228 -251
- package/dist/index.js.map +1 -1
- package/dist/mcp/mcp-command-handler.js +297 -260
- package/dist/mcp/mcp-command-handler.js.map +1 -1
- package/dist/mcp/mcp-server-manager.js +139 -155
- package/dist/mcp/mcp-server-manager.js.map +1 -1
- package/dist/mcp/mcp-tool-wrapper.js +74 -94
- package/dist/mcp/mcp-tool-wrapper.js.map +1 -1
- package/dist/services/ai-autocomplete-agent.js +169 -181
- package/dist/services/ai-autocomplete-agent.js.map +1 -1
- package/dist/services/ai-context-injector.js +180 -93
- package/dist/services/ai-context-injector.js.map +1 -1
- package/dist/services/ai-service-client.js +513 -456
- package/dist/services/ai-service-client.js.map +1 -1
- package/dist/services/api-client.js +443 -441
- package/dist/services/api-client.js.map +1 -1
- package/dist/services/auth-handler.js +162 -198
- package/dist/services/auth-handler.js.map +1 -1
- package/dist/services/background-task-manager.js +258 -282
- package/dist/services/background-task-manager.js.map +1 -1
- package/dist/services/checkpoint-manager.js +1513 -973
- package/dist/services/checkpoint-manager.js.map +1 -1
- package/dist/services/clipboard-service.js +151 -200
- package/dist/services/clipboard-service.js.map +1 -1
- package/dist/services/connectivity-manager.js +63 -65
- package/dist/services/connectivity-manager.js.map +1 -1
- package/dist/services/conversation-manager.js +118 -121
- package/dist/services/conversation-manager.js.map +1 -1
- package/dist/services/environment-context-injector.js +160 -187
- package/dist/services/environment-context-injector.js.map +1 -1
- package/dist/services/fast-context-agent.js +203 -243
- package/dist/services/fast-context-agent.js.map +1 -1
- package/dist/services/input-detection-agent.js +190 -202
- package/dist/services/input-detection-agent.js.map +1 -1
- package/dist/services/input-requirement-detector.js +155 -189
- package/dist/services/input-requirement-detector.js.map +1 -1
- package/dist/services/local-chat-storage.js +342 -365
- package/dist/services/local-chat-storage.js.map +1 -1
- package/dist/services/monitored-shell-manager.js +225 -233
- package/dist/services/monitored-shell-manager.js.map +1 -1
- package/dist/services/ollama-service.js +293 -310
- package/dist/services/ollama-service.js.map +1 -1
- package/dist/services/rules-storage.js +142 -0
- package/dist/services/rules-storage.js.map +1 -0
- package/dist/services/session-quota-manager.js +219 -235
- package/dist/services/session-quota-manager.js.map +1 -1
- package/dist/services/shell-input-agent.js +299 -334
- package/dist/services/shell-input-agent.js.map +1 -1
- package/dist/services/sub-agent-manager.js +459 -501
- package/dist/services/sub-agent-manager.js.map +1 -1
- package/dist/services/warpify-detector.js +133 -183
- package/dist/services/warpify-detector.js.map +1 -1
- package/dist/services/workflow-storage.js +202 -217
- package/dist/services/workflow-storage.js.map +1 -1
- package/dist/test-ssh-handler.js +148 -193
- package/dist/test-ssh-handler.js.map +1 -1
- package/dist/tools/add-mcp.js +161 -0
- package/dist/tools/add-mcp.js.map +1 -0
- package/dist/tools/background-command.js +240 -273
- package/dist/tools/background-command.js.map +1 -1
- package/dist/tools/command.js +447 -440
- package/dist/tools/command.js.map +1 -1
- package/dist/tools/create-image.js +172 -202
- package/dist/tools/create-image.js.map +1 -1
- package/dist/tools/enter-remote-session.js +169 -215
- package/dist/tools/enter-remote-session.js.map +1 -1
- package/dist/tools/fast-context.js +60 -67
- package/dist/tools/fast-context.js.map +1 -1
- package/dist/tools/file-ops.js +605 -537
- package/dist/tools/file-ops.js.map +1 -1
- package/dist/tools/find-files.js +262 -303
- package/dist/tools/find-files.js.map +1 -1
- package/dist/tools/get-diff.js +423 -400
- package/dist/tools/get-diff.js.map +1 -1
- package/dist/tools/grep-search.js +966 -948
- package/dist/tools/grep-search.js.map +1 -1
- package/dist/tools/inspect-symbol.js +308 -323
- package/dist/tools/inspect-symbol.js.map +1 -1
- package/dist/tools/plan-mode.js +459 -503
- package/dist/tools/plan-mode.js.map +1 -1
- package/dist/tools/read-binary-file.js +160 -190
- package/dist/tools/read-binary-file.js.map +1 -1
- package/dist/tools/registry.js +100 -84
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/reproduce_issue.js +170 -151
- package/dist/tools/reproduce_issue.js.map +1 -1
- package/dist/tools/sub-agent.js +223 -228
- package/dist/tools/sub-agent.js.map +1 -1
- package/dist/tools/task-complete.js +28 -27
- package/dist/tools/task-complete.js.map +1 -1
- package/dist/tools/types.js +0 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/validation.js +96 -118
- package/dist/tools/validation.js.map +1 -1
- package/dist/tools/web-search.js +194 -194
- package/dist/tools/web-search.js.map +1 -1
- package/dist/tools/workflow-tool.js +77 -82
- package/dist/tools/workflow-tool.js.map +1 -1
- package/dist/types/index.js +0 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/rule.js +1 -0
- package/dist/types/rule.js.map +1 -0
- package/dist/types/workflow.js +0 -7
- package/dist/types/workflow.js.map +1 -1
- package/dist/ui/components/AgentTimer.js +24 -25
- package/dist/ui/components/AgentTimer.js.map +1 -1
- package/dist/ui/components/App.js +3266 -3249
- package/dist/ui/components/App.js.map +1 -1
- package/dist/ui/components/AuthScreen.js +22 -34
- package/dist/ui/components/AuthScreen.js.map +1 -1
- package/dist/ui/components/AuthWelcomeScreen.js +30 -24
- package/dist/ui/components/AuthWelcomeScreen.js.map +1 -1
- package/dist/ui/components/Breadcrumbs.js +53 -82
- package/dist/ui/components/Breadcrumbs.js.map +1 -1
- package/dist/ui/components/CircularSelectInput.js +59 -67
- package/dist/ui/components/CircularSelectInput.js.map +1 -1
- package/dist/ui/components/ClipboardFileAutocomplete.js +78 -39
- package/dist/ui/components/ClipboardFileAutocomplete.js.map +1 -1
- package/dist/ui/components/CodeBlock.js +24 -42
- package/dist/ui/components/CodeBlock.js.map +1 -1
- package/dist/ui/components/ConfigViewer.js +18 -25
- package/dist/ui/components/ConfigViewer.js.map +1 -1
- package/dist/ui/components/ConfirmPrompt.js +49 -71
- package/dist/ui/components/ConfirmPrompt.js.map +1 -1
- package/dist/ui/components/ConnectionStatusMessage.js +32 -83
- package/dist/ui/components/ConnectionStatusMessage.js.map +1 -1
- package/dist/ui/components/ContextWindowIndicator.js +34 -49
- package/dist/ui/components/ContextWindowIndicator.js.map +1 -1
- package/dist/ui/components/DetailedPlanReviewScreen.js +104 -106
- package/dist/ui/components/DetailedPlanReviewScreen.js.map +1 -1
- package/dist/ui/components/DiffViewer.js +68 -121
- package/dist/ui/components/DiffViewer.js.map +1 -1
- package/dist/ui/components/ErrorBoundary.js +40 -48
- package/dist/ui/components/ErrorBoundary.js.map +1 -1
- package/dist/ui/components/FileCreationPreview.js +29 -60
- package/dist/ui/components/FileCreationPreview.js.map +1 -1
- package/dist/ui/components/FileOperation.js +34 -29
- package/dist/ui/components/FileOperation.js.map +1 -1
- package/dist/ui/components/FileTagAutocomplete.js +55 -25
- package/dist/ui/components/FileTagAutocomplete.js.map +1 -1
- package/dist/ui/components/FontRecommendation.js.map +1 -1
- package/dist/ui/components/GitDiffBreadcrumb.js +29 -0
- package/dist/ui/components/GitDiffBreadcrumb.js.map +1 -0
- package/dist/ui/components/InputBox.js +1620 -2150
- package/dist/ui/components/InputBox.js.map +1 -1
- package/dist/ui/components/InteractiveShell.js +234 -352
- package/dist/ui/components/InteractiveShell.js.map +1 -1
- package/dist/ui/components/KeyboardHelp.js +34 -35
- package/dist/ui/components/KeyboardHelp.js.map +1 -1
- package/dist/ui/components/LoadingIndicator.js +22 -25
- package/dist/ui/components/LoadingIndicator.js.map +1 -1
- package/dist/ui/components/MCPAddScreen.js +40 -51
- package/dist/ui/components/MCPAddScreen.js.map +1 -1
- package/dist/ui/components/MCPListScreen.js +40 -48
- package/dist/ui/components/MCPListScreen.js.map +1 -1
- package/dist/ui/components/MCPServerListScreen.js +49 -56
- package/dist/ui/components/MCPServerListScreen.js.map +1 -1
- package/dist/ui/components/MarkdownRenderer.js +69 -96
- package/dist/ui/components/MarkdownRenderer.js.map +1 -1
- package/dist/ui/components/MessageBox.js +66 -48
- package/dist/ui/components/MessageBox.js.map +1 -1
- package/dist/ui/components/MessageDisplay.js +150 -142
- package/dist/ui/components/MessageDisplay.js.map +1 -1
- package/dist/ui/components/MonitorModeAIPanel.js +46 -65
- package/dist/ui/components/MonitorModeAIPanel.js.map +1 -1
- package/dist/ui/components/MultiLineInput.js +243 -277
- package/dist/ui/components/MultiLineInput.js.map +1 -1
- package/dist/ui/components/PasswordPrompt.js +37 -18
- package/dist/ui/components/PasswordPrompt.js.map +1 -1
- package/dist/ui/components/PlanAcceptedMessage.js +27 -38
- package/dist/ui/components/PlanAcceptedMessage.js.map +1 -1
- package/dist/ui/components/PlanReviewScreen.js +46 -50
- package/dist/ui/components/PlanReviewScreen.js.map +1 -1
- package/dist/ui/components/RulesEditorScreen.js +81 -0
- package/dist/ui/components/RulesEditorScreen.js.map +1 -0
- package/dist/ui/components/SelectPrompt.js +19 -8
- package/dist/ui/components/SelectPrompt.js.map +1 -1
- package/dist/ui/components/ShimmerText.js +44 -0
- package/dist/ui/components/ShimmerText.js.map +1 -0
- package/dist/ui/components/SlashCommandAutocomplete.js +49 -22
- package/dist/ui/components/SlashCommandAutocomplete.js.map +1 -1
- package/dist/ui/components/StatusBar.js +56 -87
- package/dist/ui/components/StatusBar.js.map +1 -1
- package/dist/ui/components/StreamingMessageDisplay.js +116 -99
- package/dist/ui/components/StreamingMessageDisplay.js.map +1 -1
- package/dist/ui/components/TaskCompletedMessage.js +28 -23
- package/dist/ui/components/TaskCompletedMessage.js.map +1 -1
- package/dist/ui/components/TaskProgressIndicator.js +44 -70
- package/dist/ui/components/TaskProgressIndicator.js.map +1 -1
- package/dist/ui/components/ThinkingDisplay.js +44 -41
- package/dist/ui/components/ThinkingDisplay.js.map +1 -1
- package/dist/ui/components/ToolExecutionMessage.js +772 -1326
- package/dist/ui/components/ToolExecutionMessage.js.map +1 -1
- package/dist/ui/components/ToolExecutionStatus.js +53 -84
- package/dist/ui/components/ToolExecutionStatus.js.map +1 -1
- package/dist/ui/components/ToolResult.js +22 -15
- package/dist/ui/components/ToolResult.js.map +1 -1
- package/dist/ui/components/VersionUpdatePrompt.js +88 -120
- package/dist/ui/components/VersionUpdatePrompt.js.map +1 -1
- package/dist/ui/components/WelcomeBanner.js +176 -26
- package/dist/ui/components/WelcomeBanner.js.map +1 -1
- package/dist/ui/components/WorkflowCreatorScreen.js +94 -161
- package/dist/ui/components/WorkflowCreatorScreen.js.map +1 -1
- package/dist/utils/ansi-encoder.js +30 -61
- package/dist/utils/ansi-encoder.js.map +1 -1
- package/dist/utils/chat-formatter.js +327 -305
- package/dist/utils/chat-formatter.js.map +1 -1
- package/dist/utils/command-history.js +152 -174
- package/dist/utils/command-history.js.map +1 -1
- package/dist/utils/context-sanitizer.js +49 -112
- package/dist/utils/context-sanitizer.js.map +1 -1
- package/dist/utils/conversation-logger.js +292 -324
- package/dist/utils/conversation-logger.js.map +1 -1
- package/dist/utils/custom-commands-manager.js +126 -131
- package/dist/utils/custom-commands-manager.js.map +1 -1
- package/dist/utils/editor-utils.js +732 -837
- package/dist/utils/editor-utils.js.map +1 -1
- package/dist/utils/file.js +174 -213
- package/dist/utils/file.js.map +1 -1
- package/dist/utils/git-stats.js +169 -0
- package/dist/utils/git-stats.js.map +1 -0
- package/dist/utils/input-classifier.js +960 -482
- package/dist/utils/input-classifier.js.map +1 -1
- package/dist/utils/logger.js +48 -73
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/markdown-parser.js +277 -310
- package/dist/utils/markdown-parser.js.map +1 -1
- package/dist/utils/rule-reference-resolver.js +54 -0
- package/dist/utils/rule-reference-resolver.js.map +1 -0
- package/dist/utils/shell.js +144 -156
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/state.js +23 -22
- package/dist/utils/state.js.map +1 -1
- package/dist/utils/syntax-checker.js +279 -327
- package/dist/utils/syntax-checker.js.map +1 -1
- package/dist/utils/terminal-output.js +199 -302
- package/dist/utils/terminal-output.js.map +1 -1
- package/dist/utils/text-clipboard.js +47 -70
- package/dist/utils/text-clipboard.js.map +1 -1
- package/dist/utils/unicode-sanitizer.js +134 -197
- package/dist/utils/unicode-sanitizer.js.map +1 -1
- package/dist/utils/version-checker.js +46 -56
- package/dist/utils/version-checker.js.map +1 -1
- package/package.json +6 -4
- package/dist/ai/types.d.ts +0 -20
- package/dist/ai/types.d.ts.map +0 -1
- package/dist/cli-adapter.d.ts +0 -511
- package/dist/cli-adapter.d.ts.map +0 -1
- package/dist/commands/CommandParser.d.ts +0 -27
- package/dist/commands/CommandParser.d.ts.map +0 -1
- package/dist/config/build-config.d.ts +0 -42
- package/dist/config/build-config.d.ts.map +0 -1
- package/dist/config/defaultConfig.d.ts +0 -79
- package/dist/config/defaultConfig.d.ts.map +0 -1
- package/dist/config/manager.d.ts +0 -62
- package/dist/config/manager.d.ts.map +0 -1
- package/dist/config/mcp-config-manager.d.ts +0 -79
- package/dist/config/mcp-config-manager.d.ts.map +0 -1
- package/dist/config/models.d.ts +0 -83
- package/dist/config/models.d.ts.map +0 -1
- package/dist/config/slash-commands.d.ts +0 -23
- package/dist/config/slash-commands.d.ts.map +0 -1
- package/dist/config/types.d.ts +0 -35
- package/dist/config/types.d.ts.map +0 -1
- package/dist/context/command-detector.d.ts +0 -50
- package/dist/context/command-detector.d.ts.map +0 -1
- package/dist/context/context-manager.d.ts +0 -157
- package/dist/context/context-manager.d.ts.map +0 -1
- package/dist/context/handlers/docker-handler.d.ts +0 -130
- package/dist/context/handlers/docker-handler.d.ts.map +0 -1
- package/dist/context/handlers/ssh-handler.d.ts +0 -201
- package/dist/context/handlers/ssh-handler.d.ts.map +0 -1
- package/dist/context/handlers/wsl-handler.d.ts +0 -146
- package/dist/context/handlers/wsl-handler.d.ts.map +0 -1
- package/dist/context/index.d.ts +0 -8
- package/dist/context/index.d.ts.map +0 -1
- package/dist/context/subshell-handler.d.ts +0 -165
- package/dist/context/subshell-handler.d.ts.map +0 -1
- package/dist/context/types.d.ts +0 -70
- package/dist/context/types.d.ts.map +0 -1
- package/dist/hooks/useConnectivity.d.ts +0 -2
- package/dist/hooks/useConnectivity.d.ts.map +0 -1
- package/dist/hooks/useTerminalDimensions.d.ts +0 -41
- package/dist/hooks/useTerminalDimensions.d.ts.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/mcp/mcp-command-handler.d.ts +0 -47
- package/dist/mcp/mcp-command-handler.d.ts.map +0 -1
- package/dist/mcp/mcp-server-manager.d.ts +0 -30
- package/dist/mcp/mcp-server-manager.d.ts.map +0 -1
- package/dist/mcp/mcp-tool-wrapper.d.ts +0 -12
- package/dist/mcp/mcp-tool-wrapper.d.ts.map +0 -1
- package/dist/services/ai-autocomplete-agent.d.ts +0 -39
- package/dist/services/ai-autocomplete-agent.d.ts.map +0 -1
- package/dist/services/ai-context-injector.d.ts +0 -41
- package/dist/services/ai-context-injector.d.ts.map +0 -1
- package/dist/services/ai-service-client.d.ts +0 -128
- package/dist/services/ai-service-client.d.ts.map +0 -1
- package/dist/services/api-client.d.ts +0 -353
- package/dist/services/api-client.d.ts.map +0 -1
- package/dist/services/auth-handler.d.ts +0 -30
- package/dist/services/auth-handler.d.ts.map +0 -1
- package/dist/services/background-task-manager.d.ts +0 -114
- package/dist/services/background-task-manager.d.ts.map +0 -1
- package/dist/services/checkpoint-manager.d.ts +0 -167
- package/dist/services/checkpoint-manager.d.ts.map +0 -1
- package/dist/services/clipboard-service.d.ts +0 -37
- package/dist/services/clipboard-service.d.ts.map +0 -1
- package/dist/services/connectivity-manager.d.ts +0 -18
- package/dist/services/connectivity-manager.d.ts.map +0 -1
- package/dist/services/conversation-manager.d.ts +0 -73
- package/dist/services/conversation-manager.d.ts.map +0 -1
- package/dist/services/environment-context-injector.d.ts +0 -69
- package/dist/services/environment-context-injector.d.ts.map +0 -1
- package/dist/services/fast-context-agent.d.ts +0 -12
- package/dist/services/fast-context-agent.d.ts.map +0 -1
- package/dist/services/input-detection-agent.d.ts +0 -40
- package/dist/services/input-detection-agent.d.ts.map +0 -1
- package/dist/services/input-requirement-detector.d.ts +0 -28
- package/dist/services/input-requirement-detector.d.ts.map +0 -1
- package/dist/services/local-chat-storage.d.ts +0 -182
- package/dist/services/local-chat-storage.d.ts.map +0 -1
- package/dist/services/monitored-shell-manager.d.ts +0 -120
- package/dist/services/monitored-shell-manager.d.ts.map +0 -1
- package/dist/services/ollama-service.d.ts +0 -197
- package/dist/services/ollama-service.d.ts.map +0 -1
- package/dist/services/session-quota-manager.d.ts +0 -101
- package/dist/services/session-quota-manager.d.ts.map +0 -1
- package/dist/services/shell-input-agent.d.ts +0 -89
- package/dist/services/shell-input-agent.d.ts.map +0 -1
- package/dist/services/sub-agent-manager.d.ts +0 -140
- package/dist/services/sub-agent-manager.d.ts.map +0 -1
- package/dist/services/warpify-detector.d.ts +0 -43
- package/dist/services/warpify-detector.d.ts.map +0 -1
- package/dist/services/workflow-storage.d.ts +0 -72
- package/dist/services/workflow-storage.d.ts.map +0 -1
- package/dist/test-ssh-handler.d.ts +0 -8
- package/dist/test-ssh-handler.d.ts.map +0 -1
- package/dist/tools/background-command.d.ts +0 -11
- package/dist/tools/background-command.d.ts.map +0 -1
- package/dist/tools/command.d.ts +0 -3
- package/dist/tools/command.d.ts.map +0 -1
- package/dist/tools/create-image.d.ts +0 -10
- package/dist/tools/create-image.d.ts.map +0 -1
- package/dist/tools/enter-remote-session.d.ts +0 -48
- package/dist/tools/enter-remote-session.d.ts.map +0 -1
- package/dist/tools/fast-context.d.ts +0 -3
- package/dist/tools/fast-context.d.ts.map +0 -1
- package/dist/tools/file-ops.d.ts +0 -7
- package/dist/tools/file-ops.d.ts.map +0 -1
- package/dist/tools/find-files.d.ts +0 -49
- package/dist/tools/find-files.d.ts.map +0 -1
- package/dist/tools/get-diff.d.ts +0 -14
- package/dist/tools/get-diff.d.ts.map +0 -1
- package/dist/tools/grep-search.d.ts +0 -155
- package/dist/tools/grep-search.d.ts.map +0 -1
- package/dist/tools/inspect-symbol.d.ts +0 -32
- package/dist/tools/inspect-symbol.d.ts.map +0 -1
- package/dist/tools/plan-mode.d.ts +0 -140
- package/dist/tools/plan-mode.d.ts.map +0 -1
- package/dist/tools/read-binary-file.d.ts +0 -10
- package/dist/tools/read-binary-file.d.ts.map +0 -1
- package/dist/tools/registry.d.ts +0 -31
- package/dist/tools/registry.d.ts.map +0 -1
- package/dist/tools/reproduce_issue.d.ts +0 -2
- package/dist/tools/reproduce_issue.d.ts.map +0 -1
- package/dist/tools/sub-agent.d.ts +0 -9
- package/dist/tools/sub-agent.d.ts.map +0 -1
- package/dist/tools/task-complete.d.ts +0 -3
- package/dist/tools/task-complete.d.ts.map +0 -1
- package/dist/tools/types.d.ts +0 -40
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/validation.d.ts +0 -47
- package/dist/tools/validation.d.ts.map +0 -1
- package/dist/tools/web-search.d.ts +0 -24
- package/dist/tools/web-search.d.ts.map +0 -1
- package/dist/tools/workflow-tool.d.ts +0 -11
- package/dist/tools/workflow-tool.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -123
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/workflow.d.ts +0 -110
- package/dist/types/workflow.d.ts.map +0 -1
- package/dist/ui/components/AgentTimer.d.ts +0 -7
- package/dist/ui/components/AgentTimer.d.ts.map +0 -1
- package/dist/ui/components/App.d.ts +0 -197
- package/dist/ui/components/App.d.ts.map +0 -1
- package/dist/ui/components/AuthScreen.d.ts +0 -8
- package/dist/ui/components/AuthScreen.d.ts.map +0 -1
- package/dist/ui/components/AuthWelcomeScreen.d.ts +0 -8
- package/dist/ui/components/AuthWelcomeScreen.d.ts.map +0 -1
- package/dist/ui/components/Breadcrumbs.d.ts +0 -13
- package/dist/ui/components/Breadcrumbs.d.ts.map +0 -1
- package/dist/ui/components/CircularSelectInput.d.ts +0 -24
- package/dist/ui/components/CircularSelectInput.d.ts.map +0 -1
- package/dist/ui/components/ClipboardFileAutocomplete.d.ts +0 -10
- package/dist/ui/components/ClipboardFileAutocomplete.d.ts.map +0 -1
- package/dist/ui/components/CodeBlock.d.ts +0 -9
- package/dist/ui/components/CodeBlock.d.ts.map +0 -1
- package/dist/ui/components/ConfigViewer.d.ts +0 -11
- package/dist/ui/components/ConfigViewer.d.ts.map +0 -1
- package/dist/ui/components/ConfirmPrompt.d.ts +0 -13
- package/dist/ui/components/ConfirmPrompt.d.ts.map +0 -1
- package/dist/ui/components/ConnectionStatusMessage.d.ts +0 -17
- package/dist/ui/components/ConnectionStatusMessage.d.ts.map +0 -1
- package/dist/ui/components/ContextWindowIndicator.d.ts +0 -8
- package/dist/ui/components/ContextWindowIndicator.d.ts.map +0 -1
- package/dist/ui/components/DetailedPlanReviewScreen.d.ts +0 -17
- package/dist/ui/components/DetailedPlanReviewScreen.d.ts.map +0 -1
- package/dist/ui/components/DiffViewer.d.ts +0 -9
- package/dist/ui/components/DiffViewer.d.ts.map +0 -1
- package/dist/ui/components/ErrorBoundary.d.ts +0 -17
- package/dist/ui/components/ErrorBoundary.d.ts.map +0 -1
- package/dist/ui/components/FileCreationPreview.d.ts +0 -8
- package/dist/ui/components/FileCreationPreview.d.ts.map +0 -1
- package/dist/ui/components/FileOperation.d.ts +0 -10
- package/dist/ui/components/FileOperation.d.ts.map +0 -1
- package/dist/ui/components/FileTagAutocomplete.d.ts +0 -11
- package/dist/ui/components/FileTagAutocomplete.d.ts.map +0 -1
- package/dist/ui/components/FontRecommendation.d.ts +0 -1
- package/dist/ui/components/FontRecommendation.d.ts.map +0 -1
- package/dist/ui/components/InputBox.d.ts +0 -42
- package/dist/ui/components/InputBox.d.ts.map +0 -1
- package/dist/ui/components/InteractiveShell.d.ts +0 -30
- package/dist/ui/components/InteractiveShell.d.ts.map +0 -1
- package/dist/ui/components/KeyboardHelp.d.ts +0 -7
- package/dist/ui/components/KeyboardHelp.d.ts.map +0 -1
- package/dist/ui/components/LoadingIndicator.d.ts +0 -3
- package/dist/ui/components/LoadingIndicator.d.ts.map +0 -1
- package/dist/ui/components/MCPAddScreen.d.ts +0 -13
- package/dist/ui/components/MCPAddScreen.d.ts.map +0 -1
- package/dist/ui/components/MCPListScreen.d.ts +0 -17
- package/dist/ui/components/MCPListScreen.d.ts.map +0 -1
- package/dist/ui/components/MCPServerListScreen.d.ts +0 -16
- package/dist/ui/components/MCPServerListScreen.d.ts.map +0 -1
- package/dist/ui/components/MarkdownRenderer.d.ts +0 -8
- package/dist/ui/components/MarkdownRenderer.d.ts.map +0 -1
- package/dist/ui/components/MessageBox.d.ts +0 -10
- package/dist/ui/components/MessageBox.d.ts.map +0 -1
- package/dist/ui/components/MessageDisplay.d.ts +0 -14
- package/dist/ui/components/MessageDisplay.d.ts.map +0 -1
- package/dist/ui/components/MonitorModeAIPanel.d.ts +0 -23
- package/dist/ui/components/MonitorModeAIPanel.d.ts.map +0 -1
- package/dist/ui/components/MultiLineInput.d.ts +0 -13
- package/dist/ui/components/MultiLineInput.d.ts.map +0 -1
- package/dist/ui/components/PasswordPrompt.d.ts +0 -9
- package/dist/ui/components/PasswordPrompt.d.ts.map +0 -1
- package/dist/ui/components/PlanAcceptedMessage.d.ts +0 -20
- package/dist/ui/components/PlanAcceptedMessage.d.ts.map +0 -1
- package/dist/ui/components/PlanReviewScreen.d.ts +0 -14
- package/dist/ui/components/PlanReviewScreen.d.ts.map +0 -1
- package/dist/ui/components/SelectPrompt.d.ts +0 -12
- package/dist/ui/components/SelectPrompt.d.ts.map +0 -1
- package/dist/ui/components/SlashCommandAutocomplete.d.ts +0 -13
- package/dist/ui/components/SlashCommandAutocomplete.d.ts.map +0 -1
- package/dist/ui/components/StatusBar.d.ts +0 -14
- package/dist/ui/components/StatusBar.d.ts.map +0 -1
- package/dist/ui/components/StreamingMessageDisplay.d.ts +0 -15
- package/dist/ui/components/StreamingMessageDisplay.d.ts.map +0 -1
- package/dist/ui/components/TaskCompletedMessage.d.ts +0 -14
- package/dist/ui/components/TaskCompletedMessage.d.ts.map +0 -1
- package/dist/ui/components/TaskProgressIndicator.d.ts +0 -18
- package/dist/ui/components/TaskProgressIndicator.d.ts.map +0 -1
- package/dist/ui/components/ThinkingDisplay.d.ts +0 -15
- package/dist/ui/components/ThinkingDisplay.d.ts.map +0 -1
- package/dist/ui/components/ToolExecutionMessage.d.ts +0 -8
- package/dist/ui/components/ToolExecutionMessage.d.ts.map +0 -1
- package/dist/ui/components/ToolExecutionStatus.d.ts +0 -10
- package/dist/ui/components/ToolExecutionStatus.d.ts.map +0 -1
- package/dist/ui/components/ToolResult.d.ts +0 -10
- package/dist/ui/components/ToolResult.d.ts.map +0 -1
- package/dist/ui/components/VersionUpdatePrompt.d.ts +0 -9
- package/dist/ui/components/VersionUpdatePrompt.d.ts.map +0 -1
- package/dist/ui/components/WelcomeBanner.d.ts +0 -3
- package/dist/ui/components/WelcomeBanner.d.ts.map +0 -1
- package/dist/ui/components/WorkflowCreatorScreen.d.ts +0 -25
- package/dist/ui/components/WorkflowCreatorScreen.d.ts.map +0 -1
- package/dist/utils/ansi-encoder.d.ts +0 -7
- package/dist/utils/ansi-encoder.d.ts.map +0 -1
- package/dist/utils/chat-formatter.d.ts +0 -12
- package/dist/utils/chat-formatter.d.ts.map +0 -1
- package/dist/utils/command-history.d.ts +0 -24
- package/dist/utils/command-history.d.ts.map +0 -1
- package/dist/utils/context-sanitizer.d.ts +0 -50
- package/dist/utils/context-sanitizer.d.ts.map +0 -1
- package/dist/utils/conversation-logger.d.ts +0 -142
- package/dist/utils/conversation-logger.d.ts.map +0 -1
- package/dist/utils/custom-commands-manager.d.ts +0 -59
- package/dist/utils/custom-commands-manager.d.ts.map +0 -1
- package/dist/utils/editor-utils.d.ts +0 -101
- package/dist/utils/editor-utils.d.ts.map +0 -1
- package/dist/utils/file.d.ts +0 -61
- package/dist/utils/file.d.ts.map +0 -1
- package/dist/utils/input-classifier.d.ts +0 -25
- package/dist/utils/input-classifier.d.ts.map +0 -1
- package/dist/utils/logger.d.ts +0 -17
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/markdown-parser.d.ts +0 -60
- package/dist/utils/markdown-parser.d.ts.map +0 -1
- package/dist/utils/shell.d.ts +0 -47
- package/dist/utils/shell.d.ts.map +0 -1
- package/dist/utils/state.d.ts +0 -13
- package/dist/utils/state.d.ts.map +0 -1
- package/dist/utils/syntax-checker.d.ts +0 -24
- package/dist/utils/syntax-checker.d.ts.map +0 -1
- package/dist/utils/terminal-output.d.ts +0 -25
- package/dist/utils/terminal-output.d.ts.map +0 -1
- package/dist/utils/text-clipboard.d.ts +0 -12
- package/dist/utils/text-clipboard.d.ts.map +0 -1
- package/dist/utils/unicode-sanitizer.d.ts +0 -44
- package/dist/utils/unicode-sanitizer.d.ts.map +0 -1
- package/dist/utils/version-checker.d.ts +0 -14
- package/dist/utils/version-checker.d.ts.map +0 -1
|
@@ -1,449 +1,451 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* - User settings management
|
|
8
|
-
* - API key storage and retrieval
|
|
9
|
-
*/
|
|
10
|
-
import axios from 'axios';
|
|
11
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync } from 'fs';
|
|
12
|
-
import { join } from 'path';
|
|
13
|
-
import { homedir } from 'os';
|
|
14
|
-
import { IS_DEV_BUILD, DEV_BACKEND_URL, PRODUCTION_BACKEND_URL } from '../config/build-config.js';
|
|
15
|
-
import { logError } from '../utils/logger.js';
|
|
16
|
-
/**
|
|
17
|
-
* API Client class for communicating with the backend service
|
|
18
|
-
*/
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { homedir } from "os";
|
|
5
|
+
import { IS_DEV_BUILD, DEV_BACKEND_URL, PRODUCTION_BACKEND_URL } from "../config/build-config.js";
|
|
6
|
+
import { logError } from "../utils/logger.js";
|
|
19
7
|
class ApiClient {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const baseURL = IS_DEV_BUILD ? DEV_BACKEND_URL : PRODUCTION_BACKEND_URL;
|
|
52
|
-
this.client = axios.create({
|
|
53
|
-
baseURL,
|
|
54
|
-
timeout: 30000,
|
|
55
|
-
headers: {
|
|
56
|
-
'Content-Type': 'application/json',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
// Request interceptor: Add Authorization header if session token exists
|
|
60
|
-
this.getClient().interceptors.request.use((config) => {
|
|
61
|
-
if (this.sessionToken) {
|
|
62
|
-
config.headers.Authorization = `Bearer ${this.sessionToken}`;
|
|
63
|
-
}
|
|
64
|
-
return config;
|
|
65
|
-
}, (error) => {
|
|
66
|
-
return Promise.reject(error);
|
|
67
|
-
});
|
|
68
|
-
// Response interceptor: Handle 401 errors (expired/invalid session)
|
|
69
|
-
this.getClient().interceptors.response.use((response) => response, async (error) => {
|
|
70
|
-
if (error.response?.status === 401) {
|
|
71
|
-
// Clear invalid session
|
|
72
|
-
this.clearSession();
|
|
73
|
-
// Create a more user-friendly error
|
|
74
|
-
const authError = new Error('Session expired. Please sign in again.');
|
|
75
|
-
authError.name = 'AuthenticationError';
|
|
76
|
-
throw authError;
|
|
77
|
-
}
|
|
78
|
-
// For other errors, extract message from API response if available
|
|
79
|
-
if (error.response?.data) {
|
|
80
|
-
const apiError = error.response.data;
|
|
81
|
-
if (apiError.error) {
|
|
82
|
-
const customError = new Error(apiError.error.message);
|
|
83
|
-
customError.name = apiError.error.code;
|
|
84
|
-
throw customError;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return this.client;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Load session token from local config file
|
|
94
|
-
*/
|
|
95
|
-
loadSession() {
|
|
96
|
-
try {
|
|
97
|
-
if (existsSync(this.configPath)) {
|
|
98
|
-
const data = readFileSync(this.configPath, 'utf-8');
|
|
99
|
-
const session = JSON.parse(data);
|
|
100
|
-
this.sessionToken = session.sessionToken || null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
// If there's any error reading the session, just start fresh
|
|
105
|
-
this.sessionToken = null;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Save session token to local config file
|
|
110
|
-
*/
|
|
111
|
-
saveSession(token, expiresAt) {
|
|
112
|
-
try {
|
|
113
|
-
// Ensure config directory exists
|
|
114
|
-
if (!existsSync(this.configDir)) {
|
|
115
|
-
mkdirSync(this.configDir, { recursive: true, mode: 0o700 });
|
|
116
|
-
}
|
|
117
|
-
// Save session data
|
|
118
|
-
const sessionData = {
|
|
119
|
-
sessionToken: token,
|
|
120
|
-
expiresAt: expiresAt || null,
|
|
121
|
-
savedAt: new Date().toISOString(),
|
|
122
|
-
};
|
|
123
|
-
writeFileSync(this.configPath, JSON.stringify(sessionData, null, 2), { encoding: 'utf-8', mode: 0o600 });
|
|
124
|
-
this.sessionToken = token;
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
logError('Failed to save session', error);
|
|
128
|
-
throw new Error('Failed to save session locally');
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Clear session token from memory and local storage
|
|
133
|
-
*/
|
|
134
|
-
clearSession() {
|
|
135
|
-
this.sessionToken = null;
|
|
136
|
-
try {
|
|
137
|
-
if (existsSync(this.configPath)) {
|
|
138
|
-
unlinkSync(this.configPath);
|
|
139
|
-
}
|
|
8
|
+
client = null;
|
|
9
|
+
sessionToken = null;
|
|
10
|
+
configPath;
|
|
11
|
+
configDir;
|
|
12
|
+
cachedUser = null;
|
|
13
|
+
constructor() {
|
|
14
|
+
this.configDir = join(homedir(), ".centaurus");
|
|
15
|
+
this.configPath = join(this.configDir, "session.json");
|
|
16
|
+
this.loadSession();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Helper to extract data from API response safely
|
|
20
|
+
*/
|
|
21
|
+
extractData(response) {
|
|
22
|
+
if (response.data.data === void 0 || response.data.data === null) {
|
|
23
|
+
throw new Error("API response missing expected data payload");
|
|
24
|
+
}
|
|
25
|
+
return response.data.data;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get or create the axios client instance
|
|
29
|
+
* This is lazy-loaded to ensure environment variables are loaded first
|
|
30
|
+
*/
|
|
31
|
+
getClient() {
|
|
32
|
+
if (!this.client) {
|
|
33
|
+
const baseURL = IS_DEV_BUILD ? DEV_BACKEND_URL : PRODUCTION_BACKEND_URL;
|
|
34
|
+
this.client = axios.create({
|
|
35
|
+
baseURL,
|
|
36
|
+
timeout: 3e4,
|
|
37
|
+
headers: {
|
|
38
|
+
"Content-Type": "application/json"
|
|
140
39
|
}
|
|
141
|
-
|
|
142
|
-
|
|
40
|
+
});
|
|
41
|
+
this.getClient().interceptors.request.use(
|
|
42
|
+
(config) => {
|
|
43
|
+
if (this.sessionToken) {
|
|
44
|
+
config.headers.Authorization = `Bearer ${this.sessionToken}`;
|
|
45
|
+
}
|
|
46
|
+
return config;
|
|
47
|
+
},
|
|
48
|
+
(error) => {
|
|
49
|
+
return Promise.reject(error);
|
|
143
50
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return this.sessionToken !== null;
|
|
150
|
-
}
|
|
151
|
-
// ==================== Authentication Methods ====================
|
|
152
|
-
/**
|
|
153
|
-
* Initialize Google OAuth flow
|
|
154
|
-
* @param redirectUri - The URI to redirect to after OAuth
|
|
155
|
-
* @returns OAuth URL and state parameter
|
|
156
|
-
*/
|
|
157
|
-
async initGoogleAuth(redirectUri) {
|
|
158
|
-
const response = await this.getClient().post('/auth/google/init', { redirectUri });
|
|
159
|
-
return this.extractData(response);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Complete Google OAuth authentication
|
|
163
|
-
* @param code - Authorization code from Google
|
|
164
|
-
* @param state - State parameter for CSRF protection
|
|
165
|
-
* @returns Session token and user information
|
|
166
|
-
*/
|
|
167
|
-
async authenticate(code, state) {
|
|
168
|
-
const response = await this.getClient().post('/auth/google/callback', { code, state });
|
|
169
|
-
const authData = this.extractData(response);
|
|
170
|
-
this.saveSession(authData.sessionToken, authData.expiresAt);
|
|
171
|
-
return authData;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Set session token directly (used when receiving token from web app)
|
|
175
|
-
* @param sessionToken - The session token to save
|
|
176
|
-
* @param user - User information
|
|
177
|
-
*/
|
|
178
|
-
setSessionToken(sessionToken, user) {
|
|
179
|
-
// Calculate expiration (30 days from now)
|
|
180
|
-
const expiresAt = new Date();
|
|
181
|
-
expiresAt.setDate(expiresAt.getDate() + 30);
|
|
182
|
-
this.saveSession(sessionToken, expiresAt.toISOString());
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Refresh the current session token
|
|
186
|
-
* @returns New session token and expiration
|
|
187
|
-
*/
|
|
188
|
-
async refreshSession() {
|
|
189
|
-
const response = await this.getClient().post('/auth/refresh');
|
|
190
|
-
const refreshData = this.extractData(response);
|
|
191
|
-
this.saveSession(refreshData.sessionToken, refreshData.expiresAt);
|
|
192
|
-
return refreshData;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Logout and invalidate current session
|
|
196
|
-
*/
|
|
197
|
-
async logout() {
|
|
198
|
-
try {
|
|
199
|
-
await this.getClient().post('/auth/logout');
|
|
200
|
-
}
|
|
201
|
-
finally {
|
|
202
|
-
// Always clear local session, even if API call fails
|
|
51
|
+
);
|
|
52
|
+
this.getClient().interceptors.response.use(
|
|
53
|
+
(response) => response,
|
|
54
|
+
async (error) => {
|
|
55
|
+
if (error.response?.status === 401) {
|
|
203
56
|
this.clearSession();
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// ==================== Conversation Methods ====================
|
|
215
|
-
/**
|
|
216
|
-
* Create a new conversation
|
|
217
|
-
* @param data - Conversation creation parameters
|
|
218
|
-
* @returns Created conversation
|
|
219
|
-
*/
|
|
220
|
-
async createConversation(data) {
|
|
221
|
-
const response = await this.getClient().post('/conversations', data);
|
|
222
|
-
return this.extractData(response);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Get all conversations for the authenticated user
|
|
226
|
-
* @param params - Pagination and filter parameters
|
|
227
|
-
* @returns List of conversations with pagination metadata
|
|
228
|
-
*/
|
|
229
|
-
async getConversations(params) {
|
|
230
|
-
const queryParams = {
|
|
231
|
-
page: params?.page || 1,
|
|
232
|
-
limit: params?.limit || 20,
|
|
233
|
-
};
|
|
234
|
-
if (params?.includeArchived !== undefined) {
|
|
235
|
-
queryParams.includeArchived = params.includeArchived;
|
|
236
|
-
}
|
|
237
|
-
if (params?.tags && params.tags.length > 0) {
|
|
238
|
-
queryParams.tags = params.tags.join(',');
|
|
239
|
-
}
|
|
240
|
-
const response = await this.getClient().get('/conversations', { params: queryParams });
|
|
241
|
-
return response.data;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Get a specific conversation by ID
|
|
245
|
-
* @param conversationId - The conversation ID
|
|
246
|
-
* @returns Conversation details
|
|
247
|
-
*/
|
|
248
|
-
async getConversation(conversationId) {
|
|
249
|
-
const response = await this.getClient().get(`/conversations/${conversationId}`);
|
|
250
|
-
return this.extractData(response);
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Update a conversation
|
|
254
|
-
* @param conversationId - The conversation ID
|
|
255
|
-
* @param data - Fields to update
|
|
256
|
-
* @returns Updated conversation
|
|
257
|
-
*/
|
|
258
|
-
async updateConversation(conversationId, data) {
|
|
259
|
-
const response = await this.getClient().put(`/conversations/${conversationId}`, data);
|
|
260
|
-
return this.extractData(response);
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Delete (archive) a conversation
|
|
264
|
-
* @param conversationId - The conversation ID
|
|
265
|
-
*/
|
|
266
|
-
async deleteConversation(conversationId) {
|
|
267
|
-
await this.getClient().delete(`/conversations/${conversationId}`);
|
|
268
|
-
}
|
|
269
|
-
// ==================== Message Methods ====================
|
|
270
|
-
/**
|
|
271
|
-
* Add a message to a conversation
|
|
272
|
-
* @param conversationId - The conversation ID
|
|
273
|
-
* @param message - Message data
|
|
274
|
-
* @returns Created message
|
|
275
|
-
*/
|
|
276
|
-
async addMessage(conversationId, message) {
|
|
277
|
-
const response = await this.getClient().post(`/conversations/${conversationId}/messages`, message);
|
|
278
|
-
return this.extractData(response);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Get all messages for a conversation
|
|
282
|
-
* @param conversationId - The conversation ID
|
|
283
|
-
* @param params - Pagination parameters
|
|
284
|
-
* @returns List of messages with pagination metadata
|
|
285
|
-
*/
|
|
286
|
-
async getMessages(conversationId, params) {
|
|
287
|
-
const queryParams = {
|
|
288
|
-
page: params?.page || 1,
|
|
289
|
-
limit: params?.limit || 50,
|
|
290
|
-
};
|
|
291
|
-
const response = await this.getClient().get(`/conversations/${conversationId}/messages`, { params: queryParams });
|
|
292
|
-
return response.data;
|
|
293
|
-
}
|
|
294
|
-
// ==================== Settings Methods ====================
|
|
295
|
-
/**
|
|
296
|
-
* Get user settings
|
|
297
|
-
* @returns User settings object
|
|
298
|
-
*/
|
|
299
|
-
async getSettings() {
|
|
300
|
-
const response = await this.getClient().get('/settings');
|
|
301
|
-
return this.extractData(response);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Update user settings
|
|
305
|
-
* @param settings - Settings to update (partial update supported)
|
|
306
|
-
* @returns Updated settings
|
|
307
|
-
*/
|
|
308
|
-
async updateSettings(settings) {
|
|
309
|
-
const response = await this.getClient().put('/settings', settings);
|
|
310
|
-
return this.extractData(response);
|
|
311
|
-
}
|
|
312
|
-
// ==================== Models Configuration Methods ====================
|
|
313
|
-
/**
|
|
314
|
-
* Get available AI models configuration from backend
|
|
315
|
-
* This is a public endpoint (no auth required)
|
|
316
|
-
* @returns Models configuration including all model variants and default model
|
|
317
|
-
*/
|
|
318
|
-
async getModelsConfig() {
|
|
319
|
-
const response = await this.getClient().get('/models/config');
|
|
320
|
-
return this.extractData(response);
|
|
321
|
-
}
|
|
322
|
-
// ==================== Rate Limits Configuration Methods ====================
|
|
323
|
-
/**
|
|
324
|
-
* Get rate limits configuration from backend
|
|
325
|
-
* This is a public endpoint (no auth required)
|
|
326
|
-
* @returns Rate limits configuration including session quotas
|
|
327
|
-
*/
|
|
328
|
-
async getRateLimitsConfig() {
|
|
329
|
-
const response = await this.getClient().get('/rate-limits/session');
|
|
330
|
-
return this.extractData(response);
|
|
331
|
-
}
|
|
332
|
-
// ==================== Classification Methods ====================
|
|
333
|
-
/**
|
|
334
|
-
* Classify user input to determine if it's a terminal command or AI message
|
|
335
|
-
* @param text - Input text to classify
|
|
336
|
-
* @returns Mode prediction: 'terminal' or 'ai'
|
|
337
|
-
*/
|
|
338
|
-
async classifyInput(text) {
|
|
339
|
-
try {
|
|
340
|
-
const response = await this.getClient().post('/classify', { text });
|
|
341
|
-
return response.data.data?.mode || 'ai';
|
|
342
|
-
}
|
|
343
|
-
catch (error) {
|
|
344
|
-
// On error, return default 'ai' mode - silent fallback
|
|
345
|
-
return 'ai';
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
// ==================== File Upload Methods ====================
|
|
349
|
-
/**
|
|
350
|
-
* Upload a file to the backend for AI processing
|
|
351
|
-
* @param conversationId - The conversation ID
|
|
352
|
-
* @param fileName - Original file name
|
|
353
|
-
* @param fileType - MIME type
|
|
354
|
-
* @param fileData - Base64 encoded file data
|
|
355
|
-
* @returns Upload result with gcsUri for Vertex AI
|
|
356
|
-
*/
|
|
357
|
-
async uploadFile(conversationId, fileName, fileType, fileData) {
|
|
358
|
-
const response = await this.getClient().post('/files/upload', { conversationId, fileName, fileType, mimeType: fileType, fileData, clientType: 'cli' });
|
|
359
|
-
return this.extractData(response);
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Delete all files for a conversation from storage (Supabase and GCS)
|
|
363
|
-
* Call this when deleting a conversation to clean up associated images
|
|
364
|
-
* @param conversationId - The conversation ID
|
|
365
|
-
*/
|
|
366
|
-
async deleteConversationFiles(conversationId) {
|
|
367
|
-
try {
|
|
368
|
-
await this.getClient().delete(`/files/conversation/${conversationId}`);
|
|
369
|
-
}
|
|
370
|
-
catch (error) {
|
|
371
|
-
// Silently fail - files might not exist or user might not be authenticated
|
|
372
|
-
// This is a cleanup operation, so we don't want to block chat deletion
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
// ==================== Sync Methods ====================
|
|
376
|
-
/**
|
|
377
|
-
* Upload sync data (combined chat history and config)
|
|
378
|
-
* @param syncData - The combined data to sync
|
|
379
|
-
* @returns Upload result with version info
|
|
380
|
-
*/
|
|
381
|
-
async uploadSyncData(syncData) {
|
|
382
|
-
const response = await this.getClient().post('/sync', { syncData });
|
|
383
|
-
return this.extractData(response);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Get sync data for the current user
|
|
387
|
-
* @returns Sync data or null if not found
|
|
388
|
-
*/
|
|
389
|
-
async getSyncData() {
|
|
390
|
-
try {
|
|
391
|
-
const response = await this.getClient().get('/sync');
|
|
392
|
-
return this.extractData(response);
|
|
393
|
-
}
|
|
394
|
-
catch (error) {
|
|
395
|
-
if (error.response?.status === 404) {
|
|
396
|
-
return null;
|
|
57
|
+
const authError = new Error("Session expired. Please sign in again.");
|
|
58
|
+
authError.name = "AuthenticationError";
|
|
59
|
+
throw authError;
|
|
60
|
+
}
|
|
61
|
+
if (error.response?.data) {
|
|
62
|
+
const apiError = error.response.data;
|
|
63
|
+
if (apiError.error) {
|
|
64
|
+
const customError = new Error(apiError.error.message);
|
|
65
|
+
customError.name = apiError.error.code;
|
|
66
|
+
throw customError;
|
|
397
67
|
}
|
|
398
|
-
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
399
70
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return this.client;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Load session token from local config file
|
|
77
|
+
*/
|
|
78
|
+
loadSession() {
|
|
79
|
+
try {
|
|
80
|
+
if (existsSync(this.configPath)) {
|
|
81
|
+
const data = readFileSync(this.configPath, "utf-8");
|
|
82
|
+
const session = JSON.parse(data);
|
|
83
|
+
this.sessionToken = session.sessionToken || null;
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
this.sessionToken = null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Save session token to local config file
|
|
91
|
+
*/
|
|
92
|
+
saveSession(token, expiresAt) {
|
|
93
|
+
try {
|
|
94
|
+
if (!existsSync(this.configDir)) {
|
|
95
|
+
mkdirSync(this.configDir, { recursive: true, mode: 448 });
|
|
96
|
+
}
|
|
97
|
+
const sessionData = {
|
|
98
|
+
sessionToken: token,
|
|
99
|
+
expiresAt: expiresAt || null,
|
|
100
|
+
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
101
|
+
};
|
|
102
|
+
writeFileSync(this.configPath, JSON.stringify(sessionData, null, 2), { encoding: "utf-8", mode: 384 });
|
|
103
|
+
this.sessionToken = token;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
logError("Failed to save session", error);
|
|
106
|
+
throw new Error("Failed to save session locally");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Clear session token from memory and local storage
|
|
111
|
+
*/
|
|
112
|
+
clearSession() {
|
|
113
|
+
this.sessionToken = null;
|
|
114
|
+
this.cachedUser = null;
|
|
115
|
+
try {
|
|
116
|
+
if (existsSync(this.configPath)) {
|
|
117
|
+
unlinkSync(this.configPath);
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if user is authenticated
|
|
124
|
+
*/
|
|
125
|
+
isAuthenticated() {
|
|
126
|
+
return this.sessionToken !== null;
|
|
127
|
+
}
|
|
128
|
+
// ==================== Authentication Methods ====================
|
|
129
|
+
/**
|
|
130
|
+
* Initialize Google OAuth flow
|
|
131
|
+
* @param redirectUri - The URI to redirect to after OAuth
|
|
132
|
+
* @returns OAuth URL and state parameter
|
|
133
|
+
*/
|
|
134
|
+
async initGoogleAuth(redirectUri) {
|
|
135
|
+
const response = await this.getClient().post(
|
|
136
|
+
"/auth/google/init",
|
|
137
|
+
{ redirectUri }
|
|
138
|
+
);
|
|
139
|
+
return this.extractData(response);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Complete Google OAuth authentication
|
|
143
|
+
* @param code - Authorization code from Google
|
|
144
|
+
* @param state - State parameter for CSRF protection
|
|
145
|
+
* @returns Session token and user information
|
|
146
|
+
*/
|
|
147
|
+
async authenticate(code, state) {
|
|
148
|
+
const response = await this.getClient().post(
|
|
149
|
+
"/auth/google/callback",
|
|
150
|
+
{ code, state }
|
|
151
|
+
);
|
|
152
|
+
const authData = this.extractData(response);
|
|
153
|
+
this.saveSession(authData.sessionToken, authData.expiresAt);
|
|
154
|
+
return authData;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Set session token directly (used when receiving token from web app)
|
|
158
|
+
* @param sessionToken - The session token to save
|
|
159
|
+
* @param user - User information
|
|
160
|
+
*/
|
|
161
|
+
setSessionToken(sessionToken, user) {
|
|
162
|
+
const expiresAt = /* @__PURE__ */ new Date();
|
|
163
|
+
expiresAt.setDate(expiresAt.getDate() + 30);
|
|
164
|
+
this.saveSession(sessionToken, expiresAt.toISOString());
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Refresh the current session token
|
|
168
|
+
* @returns New session token and expiration
|
|
169
|
+
*/
|
|
170
|
+
async refreshSession() {
|
|
171
|
+
const response = await this.getClient().post(
|
|
172
|
+
"/auth/refresh"
|
|
173
|
+
);
|
|
174
|
+
const refreshData = this.extractData(response);
|
|
175
|
+
this.saveSession(refreshData.sessionToken, refreshData.expiresAt);
|
|
176
|
+
return refreshData;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Logout and invalidate current session
|
|
180
|
+
*/
|
|
181
|
+
async logout() {
|
|
182
|
+
try {
|
|
183
|
+
await this.getClient().post("/auth/logout");
|
|
184
|
+
} finally {
|
|
185
|
+
this.clearSession();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get current authenticated user profile
|
|
190
|
+
* @returns User profile information
|
|
191
|
+
*/
|
|
192
|
+
async getCurrentUser() {
|
|
193
|
+
const response = await this.getClient().get("/auth/me");
|
|
194
|
+
const user = this.extractData(response);
|
|
195
|
+
this.cachedUser = user;
|
|
196
|
+
return user;
|
|
197
|
+
}
|
|
198
|
+
getCachedUser() {
|
|
199
|
+
return this.cachedUser;
|
|
200
|
+
}
|
|
201
|
+
// ==================== Conversation Methods ====================
|
|
202
|
+
/**
|
|
203
|
+
* Create a new conversation
|
|
204
|
+
* @param data - Conversation creation parameters
|
|
205
|
+
* @returns Created conversation
|
|
206
|
+
*/
|
|
207
|
+
async createConversation(data) {
|
|
208
|
+
const response = await this.getClient().post(
|
|
209
|
+
"/threads",
|
|
210
|
+
data
|
|
211
|
+
);
|
|
212
|
+
return this.extractData(response);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get all conversations for the authenticated user
|
|
216
|
+
* @param params - Pagination and filter parameters
|
|
217
|
+
* @returns List of conversations with pagination metadata
|
|
218
|
+
*/
|
|
219
|
+
async getConversations(params) {
|
|
220
|
+
const queryParams = {
|
|
221
|
+
page: params?.page || 1,
|
|
222
|
+
limit: params?.limit || 20
|
|
223
|
+
};
|
|
224
|
+
if (params?.includeArchived !== void 0) {
|
|
225
|
+
queryParams.includeArchived = params.includeArchived;
|
|
226
|
+
}
|
|
227
|
+
if (params?.tags && params.tags.length > 0) {
|
|
228
|
+
queryParams.tags = params.tags.join(",");
|
|
229
|
+
}
|
|
230
|
+
const response = await this.getClient().get(
|
|
231
|
+
"/threads",
|
|
232
|
+
{ params: queryParams }
|
|
233
|
+
);
|
|
234
|
+
return response.data;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get a specific conversation by ID
|
|
238
|
+
* @param conversationId - The conversation ID
|
|
239
|
+
* @returns Conversation details
|
|
240
|
+
*/
|
|
241
|
+
async getConversation(conversationId) {
|
|
242
|
+
const response = await this.getClient().get(
|
|
243
|
+
`/threads/${conversationId}`
|
|
244
|
+
);
|
|
245
|
+
return this.extractData(response);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Update a conversation
|
|
249
|
+
* @param conversationId - The conversation ID
|
|
250
|
+
* @param data - Fields to update
|
|
251
|
+
* @returns Updated conversation
|
|
252
|
+
*/
|
|
253
|
+
async updateConversation(conversationId, data) {
|
|
254
|
+
const response = await this.getClient().put(
|
|
255
|
+
`/threads/${conversationId}`,
|
|
256
|
+
data
|
|
257
|
+
);
|
|
258
|
+
return this.extractData(response);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Delete (archive) a conversation
|
|
262
|
+
* @param conversationId - The conversation ID
|
|
263
|
+
*/
|
|
264
|
+
async deleteConversation(conversationId) {
|
|
265
|
+
await this.getClient().delete(`/threads/${conversationId}`);
|
|
266
|
+
}
|
|
267
|
+
// ==================== Message Methods ====================
|
|
268
|
+
/**
|
|
269
|
+
* Add a message to a conversation
|
|
270
|
+
* @param conversationId - The conversation ID
|
|
271
|
+
* @param message - Message data
|
|
272
|
+
* @returns Created message
|
|
273
|
+
*/
|
|
274
|
+
async addMessage(conversationId, message) {
|
|
275
|
+
const response = await this.getClient().post(
|
|
276
|
+
`/threads/${conversationId}/messages`,
|
|
277
|
+
message
|
|
278
|
+
);
|
|
279
|
+
return this.extractData(response);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Get all messages for a conversation
|
|
283
|
+
* @param conversationId - The conversation ID
|
|
284
|
+
* @param params - Pagination parameters
|
|
285
|
+
* @returns List of messages with pagination metadata
|
|
286
|
+
*/
|
|
287
|
+
async getMessages(conversationId, params) {
|
|
288
|
+
const queryParams = {
|
|
289
|
+
page: params?.page || 1,
|
|
290
|
+
limit: params?.limit || 50
|
|
291
|
+
};
|
|
292
|
+
const response = await this.getClient().get(
|
|
293
|
+
`/threads/${conversationId}/messages`,
|
|
294
|
+
{ params: queryParams }
|
|
295
|
+
);
|
|
296
|
+
return response.data;
|
|
297
|
+
}
|
|
298
|
+
// ==================== Settings Methods ====================
|
|
299
|
+
/**
|
|
300
|
+
* Get user settings
|
|
301
|
+
* @returns User settings object
|
|
302
|
+
*/
|
|
303
|
+
async getSettings() {
|
|
304
|
+
const response = await this.getClient().get("/settings");
|
|
305
|
+
return this.extractData(response);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Update user settings
|
|
309
|
+
* @param settings - Settings to update (partial update supported)
|
|
310
|
+
* @returns Updated settings
|
|
311
|
+
*/
|
|
312
|
+
async updateSettings(settings) {
|
|
313
|
+
const response = await this.getClient().put(
|
|
314
|
+
"/settings",
|
|
315
|
+
settings
|
|
316
|
+
);
|
|
317
|
+
return this.extractData(response);
|
|
318
|
+
}
|
|
319
|
+
// ==================== Models Configuration Methods ====================
|
|
320
|
+
/**
|
|
321
|
+
* Get available AI models configuration from backend
|
|
322
|
+
* This is a public endpoint (no auth required)
|
|
323
|
+
* @returns Models configuration including all model variants and default model
|
|
324
|
+
*/
|
|
325
|
+
async getModelsConfig() {
|
|
326
|
+
const response = await this.getClient().get("/models");
|
|
327
|
+
return this.extractData(response);
|
|
328
|
+
}
|
|
329
|
+
// ==================== Rate Limits Configuration Methods ====================
|
|
330
|
+
/**
|
|
331
|
+
* Get rate limits configuration from backend
|
|
332
|
+
* This is a public endpoint (no auth required)
|
|
333
|
+
* @returns Rate limits configuration including session quotas
|
|
334
|
+
*/
|
|
335
|
+
async getRateLimitsConfig() {
|
|
336
|
+
const response = await this.getClient().get("/rate-limits/session");
|
|
337
|
+
return this.extractData(response);
|
|
338
|
+
}
|
|
339
|
+
// ==================== Classification Methods ====================
|
|
340
|
+
/**
|
|
341
|
+
* Classify user input to determine if it's a terminal command or AI message
|
|
342
|
+
* @param text - Input text to classify
|
|
343
|
+
* @returns Mode prediction: 'terminal' or 'ai'
|
|
344
|
+
*/
|
|
345
|
+
async classifyInput(text) {
|
|
346
|
+
try {
|
|
347
|
+
const response = await this.getClient().post(
|
|
348
|
+
"/classify",
|
|
349
|
+
{ text }
|
|
350
|
+
);
|
|
351
|
+
return response.data.data?.mode || "ai";
|
|
352
|
+
} catch (error) {
|
|
353
|
+
return "ai";
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// ==================== File Upload Methods ====================
|
|
357
|
+
/**
|
|
358
|
+
* Upload a file to the backend for AI processing
|
|
359
|
+
* @param conversationId - The conversation ID
|
|
360
|
+
* @param fileName - Original file name
|
|
361
|
+
* @param fileType - MIME type
|
|
362
|
+
* @param fileData - Base64 encoded file data
|
|
363
|
+
* @returns Upload result with gcsUri for Vertex AI
|
|
364
|
+
*/
|
|
365
|
+
async uploadFile(conversationId, fileName, fileType, fileData) {
|
|
366
|
+
const response = await this.getClient().post("/files", { conversationId, fileName, fileType, mimeType: fileType, fileData, clientType: "cli" });
|
|
367
|
+
return this.extractData(response);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Delete all files for a conversation from storage (Supabase and GCS)
|
|
371
|
+
* Call this when deleting a conversation to clean up associated images
|
|
372
|
+
* @param conversationId - The conversation ID
|
|
373
|
+
*/
|
|
374
|
+
async deleteConversationFiles(conversationId) {
|
|
375
|
+
try {
|
|
376
|
+
await this.getClient().delete(`/files/by-thread/${conversationId}`);
|
|
377
|
+
} catch (error) {
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// ==================== Sync Methods ====================
|
|
381
|
+
/**
|
|
382
|
+
* Upload sync data (combined chat history and config)
|
|
383
|
+
* @param syncData - The combined data to sync
|
|
384
|
+
* @returns Upload result with version info
|
|
385
|
+
*/
|
|
386
|
+
async uploadSyncData(syncData) {
|
|
387
|
+
const response = await this.getClient().post("/sync", { syncData });
|
|
388
|
+
return this.extractData(response);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Get sync data for the current user
|
|
392
|
+
* @returns Sync data or null if not found
|
|
393
|
+
*/
|
|
394
|
+
async getSyncData() {
|
|
395
|
+
try {
|
|
396
|
+
const response = await this.getClient().get("/sync");
|
|
397
|
+
return this.extractData(response);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
if (error.response?.status === 404) {
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Delete sync data for the current user
|
|
407
|
+
*/
|
|
408
|
+
async deleteSyncData() {
|
|
409
|
+
await this.getClient().delete("/sync");
|
|
410
|
+
}
|
|
411
|
+
// ==================== Token Counting Methods ====================
|
|
412
|
+
/**
|
|
413
|
+
* Count tokens for a given model and messages
|
|
414
|
+
* Uses backend's accurate token counting (Vertex AI countTokens API)
|
|
415
|
+
* @param model - Model name (e.g., gemini-2.5-flash)
|
|
416
|
+
* @param messages - Array of conversation messages
|
|
417
|
+
* @returns Total token count including system prompt
|
|
418
|
+
*/
|
|
419
|
+
async countTokens(model, messages) {
|
|
420
|
+
try {
|
|
421
|
+
const response = await this.getClient().post(
|
|
422
|
+
"/chat/token-count",
|
|
423
|
+
{ model, messages }
|
|
424
|
+
);
|
|
425
|
+
return response.data.data?.tokenCount || 0;
|
|
426
|
+
} catch (error) {
|
|
427
|
+
logError("Failed to count tokens via API", error);
|
|
428
|
+
const totalCharacters = messages.reduce((sum, msg) => {
|
|
429
|
+
const content = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
430
|
+
return sum + content.length;
|
|
431
|
+
}, 0);
|
|
432
|
+
return Math.ceil((totalCharacters + 14e3) / 4);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// ==================== Health Check ====================
|
|
436
|
+
/**
|
|
437
|
+
* Check backend service health
|
|
438
|
+
* @returns Health status information
|
|
439
|
+
*/
|
|
440
|
+
async healthCheck() {
|
|
441
|
+
const baseURL = IS_DEV_BUILD ? DEV_BACKEND_URL : PRODUCTION_BACKEND_URL;
|
|
442
|
+
const healthURL = baseURL.replace("/v1", "/health");
|
|
443
|
+
const response = await axios.get(healthURL);
|
|
444
|
+
return this.extractData(response);
|
|
445
|
+
}
|
|
446
446
|
}
|
|
447
|
-
|
|
448
|
-
export
|
|
447
|
+
const apiClient = new ApiClient();
|
|
448
|
+
export {
|
|
449
|
+
apiClient
|
|
450
|
+
};
|
|
449
451
|
//# sourceMappingURL=api-client.js.map
|