centaurus-cli 2.9.1 → 2.9.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.
Files changed (156) hide show
  1. package/dist/cli-adapter.d.ts +76 -3
  2. package/dist/cli-adapter.d.ts.map +1 -1
  3. package/dist/cli-adapter.js +593 -230
  4. package/dist/cli-adapter.js.map +1 -1
  5. package/dist/config/mcp-config-manager.d.ts +21 -0
  6. package/dist/config/mcp-config-manager.d.ts.map +1 -1
  7. package/dist/config/mcp-config-manager.js +184 -1
  8. package/dist/config/mcp-config-manager.js.map +1 -1
  9. package/dist/config/models.d.ts +1 -0
  10. package/dist/config/models.d.ts.map +1 -1
  11. package/dist/config/models.js +9 -2
  12. package/dist/config/models.js.map +1 -1
  13. package/dist/config/slash-commands.d.ts +3 -0
  14. package/dist/config/slash-commands.d.ts.map +1 -1
  15. package/dist/config/slash-commands.js +39 -4
  16. package/dist/config/slash-commands.js.map +1 -1
  17. package/dist/config/types.d.ts +2 -0
  18. package/dist/config/types.d.ts.map +1 -1
  19. package/dist/config/types.js +1 -0
  20. package/dist/config/types.js.map +1 -1
  21. package/dist/index.js +60 -11
  22. package/dist/index.js.map +1 -1
  23. package/dist/mcp/mcp-command-handler.d.ts +34 -3
  24. package/dist/mcp/mcp-command-handler.d.ts.map +1 -1
  25. package/dist/mcp/mcp-command-handler.js +171 -83
  26. package/dist/mcp/mcp-command-handler.js.map +1 -1
  27. package/dist/mcp/mcp-server-manager.d.ts.map +1 -1
  28. package/dist/mcp/mcp-server-manager.js +9 -23
  29. package/dist/mcp/mcp-server-manager.js.map +1 -1
  30. package/dist/mcp/mcp-tool-wrapper.d.ts.map +1 -1
  31. package/dist/mcp/mcp-tool-wrapper.js +42 -5
  32. package/dist/mcp/mcp-tool-wrapper.js.map +1 -1
  33. package/dist/services/ai-autocomplete-agent.d.ts +39 -0
  34. package/dist/services/ai-autocomplete-agent.d.ts.map +1 -0
  35. package/dist/services/ai-autocomplete-agent.js +189 -0
  36. package/dist/services/ai-autocomplete-agent.js.map +1 -0
  37. package/dist/services/ai-service-client.d.ts +25 -0
  38. package/dist/services/ai-service-client.d.ts.map +1 -1
  39. package/dist/services/ai-service-client.js +162 -1
  40. package/dist/services/ai-service-client.js.map +1 -1
  41. package/dist/services/api-client.d.ts +9 -0
  42. package/dist/services/api-client.d.ts.map +1 -1
  43. package/dist/services/api-client.js +25 -0
  44. package/dist/services/api-client.js.map +1 -1
  45. package/dist/services/auth-handler.js +1 -1
  46. package/dist/services/auth-handler.js.map +1 -1
  47. package/dist/services/input-detection-agent.d.ts +40 -0
  48. package/dist/services/input-detection-agent.d.ts.map +1 -0
  49. package/dist/services/input-detection-agent.js +213 -0
  50. package/dist/services/input-detection-agent.js.map +1 -0
  51. package/dist/services/input-requirement-detector.d.ts +28 -0
  52. package/dist/services/input-requirement-detector.d.ts.map +1 -0
  53. package/dist/services/input-requirement-detector.js +203 -0
  54. package/dist/services/input-requirement-detector.js.map +1 -0
  55. package/dist/services/local-chat-storage.d.ts +21 -0
  56. package/dist/services/local-chat-storage.d.ts.map +1 -1
  57. package/dist/services/local-chat-storage.js +138 -43
  58. package/dist/services/local-chat-storage.js.map +1 -1
  59. package/dist/services/monitored-shell-manager.d.ts +120 -0
  60. package/dist/services/monitored-shell-manager.d.ts.map +1 -0
  61. package/dist/services/monitored-shell-manager.js +239 -0
  62. package/dist/services/monitored-shell-manager.js.map +1 -0
  63. package/dist/services/ollama-service.d.ts +197 -0
  64. package/dist/services/ollama-service.d.ts.map +1 -0
  65. package/dist/services/ollama-service.js +324 -0
  66. package/dist/services/ollama-service.js.map +1 -0
  67. package/dist/services/shell-input-agent.d.ts +89 -0
  68. package/dist/services/shell-input-agent.d.ts.map +1 -0
  69. package/dist/services/shell-input-agent.js +361 -0
  70. package/dist/services/shell-input-agent.js.map +1 -0
  71. package/dist/services/sub-agent-manager.d.ts +139 -0
  72. package/dist/services/sub-agent-manager.d.ts.map +1 -0
  73. package/dist/services/sub-agent-manager.js +517 -0
  74. package/dist/services/sub-agent-manager.js.map +1 -0
  75. package/dist/tools/background-command.d.ts.map +1 -1
  76. package/dist/tools/background-command.js +33 -13
  77. package/dist/tools/background-command.js.map +1 -1
  78. package/dist/tools/command.d.ts.map +1 -1
  79. package/dist/tools/command.js +64 -1
  80. package/dist/tools/command.js.map +1 -1
  81. package/dist/tools/file-ops.d.ts.map +1 -1
  82. package/dist/tools/file-ops.js +33 -19
  83. package/dist/tools/file-ops.js.map +1 -1
  84. package/dist/tools/get-diff.js +1 -1
  85. package/dist/tools/get-diff.js.map +1 -1
  86. package/dist/tools/grep-search.d.ts.map +1 -1
  87. package/dist/tools/grep-search.js +41 -15
  88. package/dist/tools/grep-search.js.map +1 -1
  89. package/dist/tools/plan-mode.js +3 -3
  90. package/dist/tools/plan-mode.js.map +1 -1
  91. package/dist/tools/registry.js +1 -1
  92. package/dist/tools/registry.js.map +1 -1
  93. package/dist/tools/sub-agent.d.ts +9 -0
  94. package/dist/tools/sub-agent.d.ts.map +1 -0
  95. package/dist/tools/sub-agent.js +232 -0
  96. package/dist/tools/sub-agent.js.map +1 -0
  97. package/dist/tools/task-complete.d.ts.map +1 -1
  98. package/dist/tools/task-complete.js +14 -26
  99. package/dist/tools/task-complete.js.map +1 -1
  100. package/dist/ui/components/App.d.ts +45 -2
  101. package/dist/ui/components/App.d.ts.map +1 -1
  102. package/dist/ui/components/App.js +605 -96
  103. package/dist/ui/components/App.js.map +1 -1
  104. package/dist/ui/components/CircularSelectInput.d.ts +24 -0
  105. package/dist/ui/components/CircularSelectInput.d.ts.map +1 -0
  106. package/dist/ui/components/CircularSelectInput.js +71 -0
  107. package/dist/ui/components/CircularSelectInput.js.map +1 -0
  108. package/dist/ui/components/ErrorBoundary.d.ts +3 -2
  109. package/dist/ui/components/ErrorBoundary.d.ts.map +1 -1
  110. package/dist/ui/components/ErrorBoundary.js +29 -1
  111. package/dist/ui/components/ErrorBoundary.js.map +1 -1
  112. package/dist/ui/components/InputBox.d.ts +4 -0
  113. package/dist/ui/components/InputBox.d.ts.map +1 -1
  114. package/dist/ui/components/InputBox.js +343 -21
  115. package/dist/ui/components/InputBox.js.map +1 -1
  116. package/dist/ui/components/InteractiveShell.d.ts +6 -0
  117. package/dist/ui/components/InteractiveShell.d.ts.map +1 -1
  118. package/dist/ui/components/InteractiveShell.js +57 -6
  119. package/dist/ui/components/InteractiveShell.js.map +1 -1
  120. package/dist/ui/components/MCPAddScreen.d.ts +13 -0
  121. package/dist/ui/components/MCPAddScreen.d.ts.map +1 -0
  122. package/dist/ui/components/MCPAddScreen.js +54 -0
  123. package/dist/ui/components/MCPAddScreen.js.map +1 -0
  124. package/dist/ui/components/MCPListScreen.d.ts +17 -0
  125. package/dist/ui/components/MCPListScreen.d.ts.map +1 -0
  126. package/dist/ui/components/MCPListScreen.js +50 -0
  127. package/dist/ui/components/MCPListScreen.js.map +1 -0
  128. package/dist/ui/components/MCPServerListScreen.d.ts +16 -0
  129. package/dist/ui/components/MCPServerListScreen.d.ts.map +1 -0
  130. package/dist/ui/components/MCPServerListScreen.js +59 -0
  131. package/dist/ui/components/MCPServerListScreen.js.map +1 -0
  132. package/dist/ui/components/MonitorModeAIPanel.d.ts +23 -0
  133. package/dist/ui/components/MonitorModeAIPanel.d.ts.map +1 -0
  134. package/dist/ui/components/MonitorModeAIPanel.js +69 -0
  135. package/dist/ui/components/MonitorModeAIPanel.js.map +1 -0
  136. package/dist/ui/components/MultiLineInput.d.ts +13 -0
  137. package/dist/ui/components/MultiLineInput.d.ts.map +1 -0
  138. package/dist/ui/components/MultiLineInput.js +289 -0
  139. package/dist/ui/components/MultiLineInput.js.map +1 -0
  140. package/dist/ui/components/StatusBar.d.ts +2 -0
  141. package/dist/ui/components/StatusBar.d.ts.map +1 -1
  142. package/dist/ui/components/StatusBar.js +33 -2
  143. package/dist/ui/components/StatusBar.js.map +1 -1
  144. package/dist/ui/components/ToolExecutionMessage.d.ts.map +1 -1
  145. package/dist/ui/components/ToolExecutionMessage.js +231 -13
  146. package/dist/ui/components/ToolExecutionMessage.js.map +1 -1
  147. package/dist/ui/components/VersionUpdatePrompt.d.ts.map +1 -1
  148. package/dist/ui/components/VersionUpdatePrompt.js +3 -2
  149. package/dist/ui/components/VersionUpdatePrompt.js.map +1 -1
  150. package/dist/utils/command-history.d.ts +12 -2
  151. package/dist/utils/command-history.d.ts.map +1 -1
  152. package/dist/utils/command-history.js +57 -13
  153. package/dist/utils/command-history.js.map +1 -1
  154. package/dist/utils/input-classifier.js +1 -1
  155. package/dist/utils/input-classifier.js.map +1 -1
  156. package/package.json +2 -1
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Monitored Shell Manager Service
3
+ *
4
+ * Manages agent-controlled shell sessions, detecting when input is required
5
+ * and coordinating with the AI to provide appropriate responses.
6
+ */
7
+ import { detectInputRequirement, extractPromptContext, getInputTypeDescription } from './input-requirement-detector.js';
8
+ import { quickLog } from '../utils/conversation-logger.js';
9
+ /**
10
+ * Monitored Shell Manager
11
+ *
12
+ * Handles tracking of agent-controlled shells and coordinating input detection.
13
+ */
14
+ class MonitoredShellManagerClass {
15
+ sessions = new Map();
16
+ onAIInputRequest;
17
+ onMonitoringMessage;
18
+ inputCheckIntervalMs = 500;
19
+ shellIdCounter = 0;
20
+ /**
21
+ * Generate a unique shell ID
22
+ */
23
+ generateShellId() {
24
+ this.shellIdCounter++;
25
+ return `shell-${Date.now()}-${this.shellIdCounter}`;
26
+ }
27
+ /**
28
+ * Set the callback for requesting AI input
29
+ */
30
+ setOnAIInputRequest(callback) {
31
+ this.onAIInputRequest = callback;
32
+ }
33
+ /**
34
+ * Set the callback for new monitoring messages
35
+ */
36
+ setOnMonitoringMessage(callback) {
37
+ this.onMonitoringMessage = callback;
38
+ }
39
+ /**
40
+ * Start monitoring a shell session
41
+ */
42
+ startMonitoring(shellId, command, cwd, onInputRequired) {
43
+ // Clean up any existing session with the same ID
44
+ this.stopMonitoring(shellId);
45
+ const session = {
46
+ shellId,
47
+ command,
48
+ cwd,
49
+ output: '',
50
+ isRunning: true,
51
+ lastOutputTime: Date.now(),
52
+ monitoringMessages: [],
53
+ onInputRequired
54
+ };
55
+ // Start periodic input detection
56
+ session.inputCheckInterval = setInterval(() => {
57
+ this.checkForInputRequirement(shellId);
58
+ }, this.inputCheckIntervalMs);
59
+ this.sessions.set(shellId, session);
60
+ quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Started monitoring shell ${shellId}: ${command}\n`);
61
+ return session;
62
+ }
63
+ /**
64
+ * Stop monitoring a shell session
65
+ */
66
+ stopMonitoring(shellId) {
67
+ const session = this.sessions.get(shellId);
68
+ if (session) {
69
+ if (session.inputCheckInterval) {
70
+ clearInterval(session.inputCheckInterval);
71
+ }
72
+ this.sessions.delete(shellId);
73
+ quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Stopped monitoring shell ${shellId}\n`);
74
+ }
75
+ }
76
+ /**
77
+ * Update shell output for a monitored session
78
+ */
79
+ updateOutput(shellId, newOutput) {
80
+ const session = this.sessions.get(shellId);
81
+ if (session) {
82
+ session.output += newOutput;
83
+ session.lastOutputTime = Date.now();
84
+ }
85
+ }
86
+ /**
87
+ * Mark a shell session as complete
88
+ */
89
+ markComplete(shellId) {
90
+ const session = this.sessions.get(shellId);
91
+ if (session) {
92
+ session.isRunning = false;
93
+ this.stopMonitoring(shellId);
94
+ }
95
+ }
96
+ /**
97
+ * Get a session by ID
98
+ */
99
+ getSession(shellId) {
100
+ return this.sessions.get(shellId);
101
+ }
102
+ /**
103
+ * Check if a specific shell session is active
104
+ */
105
+ isSessionActive(shellId) {
106
+ return this.sessions.has(shellId);
107
+ }
108
+ /**
109
+ * Get all active shell IDs
110
+ */
111
+ getActiveShellIds() {
112
+ return Array.from(this.sessions.keys());
113
+ }
114
+ /**
115
+ * Add a monitoring message to a session
116
+ */
117
+ addMonitoringMessage(shellId, type, content) {
118
+ const session = this.sessions.get(shellId);
119
+ const message = {
120
+ id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
121
+ type,
122
+ content,
123
+ timestamp: new Date()
124
+ };
125
+ if (session) {
126
+ session.monitoringMessages.push(message);
127
+ // Callback to notify UI
128
+ if (this.onMonitoringMessage) {
129
+ this.onMonitoringMessage(shellId, message);
130
+ }
131
+ }
132
+ return message;
133
+ }
134
+ /**
135
+ * Get monitoring messages for a session
136
+ */
137
+ getMonitoringMessages(shellId) {
138
+ return this.sessions.get(shellId)?.monitoringMessages || [];
139
+ }
140
+ /**
141
+ * Clear monitoring messages for a session
142
+ */
143
+ clearMonitoringMessages(shellId) {
144
+ const session = this.sessions.get(shellId);
145
+ if (session) {
146
+ session.monitoringMessages = [];
147
+ }
148
+ }
149
+ /**
150
+ * Mark the most recent 'thinking' message as answered
151
+ * This changes the spinner to a tick in the UI
152
+ */
153
+ markLastThinkingAsAnswered(shellId) {
154
+ const session = this.sessions.get(shellId);
155
+ if (session) {
156
+ // Find the last 'thinking' message that isn't already answered
157
+ for (let i = session.monitoringMessages.length - 1; i >= 0; i--) {
158
+ const msg = session.monitoringMessages[i];
159
+ if (msg.type === 'thinking' && !msg.isAnswered) {
160
+ msg.isAnswered = true;
161
+ quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Marked message ${msg.id} as answered\n`);
162
+ break;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ /**
168
+ * Check if a shell requires input and trigger AI prompt if needed
169
+ */
170
+ async checkForInputRequirement(shellId) {
171
+ const session = this.sessions.get(shellId);
172
+ if (!session || !session.isRunning) {
173
+ return;
174
+ }
175
+ const timeSinceLastOutput = Date.now() - session.lastOutputTime;
176
+ const result = detectInputRequirement(session.output, timeSinceLastOutput);
177
+ if (result.requiresInput && result.confidence !== 'low') {
178
+ quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Input detected for ${shellId}: ${result.matchedPattern}\n`);
179
+ // Notify session callback
180
+ if (session.onInputRequired) {
181
+ session.onInputRequired(session, result);
182
+ }
183
+ // Request AI input
184
+ if (this.onAIInputRequest) {
185
+ const promptContext = extractPromptContext(session.output);
186
+ const inputType = getInputTypeDescription(result);
187
+ // Add "thinking" message
188
+ this.addMonitoringMessage(shellId, 'thinking', 'Analyzing shell prompt...');
189
+ try {
190
+ const aiInput = await this.onAIInputRequest(shellId, session.output, promptContext, inputType);
191
+ if (aiInput !== null) {
192
+ // Add message showing what input was sent
193
+ this.addMonitoringMessage(shellId, 'input_sent', `Sent input: ${aiInput}`);
194
+ }
195
+ }
196
+ catch (error) {
197
+ quickLog(`[${new Date().toISOString()}] [MonitoredShellManager] Error requesting AI input: ${error.message}\n`);
198
+ this.addMonitoringMessage(shellId, 'text', `Error: ${error.message}`);
199
+ }
200
+ }
201
+ }
202
+ }
203
+ /**
204
+ * Build a prompt for the AI to provide shell input
205
+ * This is used when the AI needs to decide what to input
206
+ */
207
+ buildInputPrompt(shellOutput, promptContext, inputType, originalCommand) {
208
+ return `The command "${originalCommand}" is currently running and requires user input.
209
+
210
+ **Current shell output (last 50 lines):**
211
+ \`\`\`
212
+ ${this.getLastNLines(shellOutput, 50)}
213
+ \`\`\`
214
+
215
+ **The command is asking for:** ${promptContext}
216
+
217
+ **Expected input type:** ${inputType}
218
+
219
+ Please provide the appropriate input to respond to this prompt. Use the execute_command tool with the shell_input parameter to send your response.
220
+
221
+ Guidelines:
222
+ - For yes/no prompts, respond with "y" or "n" (or "yes"/"no" if the prompt requires full words)
223
+ - For password prompts, you should NOT provide passwords - ask the user to handle this manually
224
+ - For npm init style prompts, provide reasonable defaults or press Enter for default values
225
+ - For other prompts, provide the most appropriate response based on context
226
+
227
+ If this appears to be a security-sensitive prompt (passwords, authentication), respond with a message indicating the user should handle this manually.`;
228
+ }
229
+ /**
230
+ * Get the last N lines of output
231
+ */
232
+ getLastNLines(text, n) {
233
+ const lines = text.split('\n');
234
+ return lines.slice(-n).join('\n');
235
+ }
236
+ }
237
+ // Export singleton instance
238
+ export const MonitoredShellManager = new MonitoredShellManagerClass();
239
+ //# sourceMappingURL=monitored-shell-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitored-shell-manager.js","sourceRoot":"","sources":["../../src/services/monitored-shell-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,uBAAuB,EAAkD,MAAM,iCAAiC,CAAC;AACxK,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAsC3D;;;;GAIG;AACH,MAAM,0BAA0B;IACpB,QAAQ,GAAuC,IAAI,GAAG,EAAE,CAAC;IACzD,gBAAgB,CAA4B;IAC5C,mBAAmB,CAAsD;IACzE,oBAAoB,GAAW,GAAG,CAAC;IACnC,cAAc,GAAW,CAAC,CAAC;IAEnC;;OAEG;IACH,eAAe;QACX,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,SAAS,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,QAAkC;QAClD,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,sBAAsB,CAAC,QAA4D;QAC/E,IAAI,CAAC,mBAAmB,GAAG,QAAQ,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,eAAe,CACX,OAAe,EACf,OAAe,EACf,GAAW,EACX,eAAiG;QAEjG,iDAAiD;QACjD,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE7B,MAAM,OAAO,GAA0B;YACnC,OAAO;YACP,OAAO;YACP,GAAG;YACH,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,IAAI;YACf,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE;YAC1B,kBAAkB,EAAE,EAAE;YACtB,eAAe;SAClB,CAAC;QAEF,iCAAiC;QACjC,OAAO,CAAC,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE;YAC1C,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,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WAAmB,EAAE,aAAqB,EAAE,SAAiB,EAAE,eAAuB;QACnG,OAAO,gBAAgB,eAAe;;;;EAI5C,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,EAAE,CAAC;;;iCAGJ,aAAa;;2BAEnB,SAAS;;;;;;;;;;uJAUmH,CAAC;IACpJ,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,IAAY,EAAE,CAAS;QACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACJ;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,0BAA0B,EAAE,CAAC"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Ollama Service
3
+ * Client for interacting with the local Ollama API
4
+ *
5
+ * Ollama exposes a REST API at http://localhost:11434 by default.
6
+ * This service provides methods for:
7
+ * - Checking if Ollama is running
8
+ * - Fetching available local models
9
+ * - Sending chat messages to local models
10
+ */
11
+ /**
12
+ * Ollama model information as returned by /api/tags
13
+ */
14
+ export interface OllamaModel {
15
+ name: string;
16
+ model: string;
17
+ size: number;
18
+ digest: string;
19
+ modified_at: string;
20
+ details?: {
21
+ family?: string;
22
+ parameter_size?: string;
23
+ quantization_level?: string;
24
+ };
25
+ }
26
+ /**
27
+ * Response from Ollama /api/tags endpoint
28
+ */
29
+ export interface OllamaTagsResponse {
30
+ models: OllamaModel[];
31
+ }
32
+ /**
33
+ * Chat message format for Ollama (with tool support)
34
+ */
35
+ export interface OllamaChatMessage {
36
+ role: 'system' | 'user' | 'assistant' | 'tool';
37
+ content: string;
38
+ images?: string[];
39
+ tool_calls?: OllamaToolCall[];
40
+ tool_name?: string;
41
+ }
42
+ /**
43
+ * Ollama tool call structure (OpenAI-compatible)
44
+ */
45
+ export interface OllamaToolCall {
46
+ function: {
47
+ name: string;
48
+ arguments: Record<string, any>;
49
+ };
50
+ }
51
+ /**
52
+ * Ollama tool definition (OpenAI-compatible)
53
+ */
54
+ export interface OllamaTool {
55
+ type: 'function';
56
+ function: {
57
+ name: string;
58
+ description: string;
59
+ parameters: {
60
+ type: 'object';
61
+ properties: Record<string, {
62
+ type: string;
63
+ description: string;
64
+ enum?: string[];
65
+ }>;
66
+ required?: string[];
67
+ };
68
+ };
69
+ }
70
+ /**
71
+ * Request body for Ollama /api/chat endpoint (with tools support)
72
+ */
73
+ export interface OllamaChatRequest {
74
+ model: string;
75
+ messages: OllamaChatMessage[];
76
+ stream?: boolean;
77
+ format?: 'json';
78
+ tools?: OllamaTool[];
79
+ options?: {
80
+ temperature?: number;
81
+ top_p?: number;
82
+ top_k?: number;
83
+ num_predict?: number;
84
+ stop?: string[];
85
+ };
86
+ }
87
+ /**
88
+ * Model families that support tool calling
89
+ * Based on https://ollama.com/search?c=tools
90
+ */
91
+ export declare const TOOL_CAPABLE_MODEL_FAMILIES: string[];
92
+ /**
93
+ * Single streaming response chunk from Ollama /api/chat
94
+ */
95
+ export interface OllamaChatStreamChunk {
96
+ model: string;
97
+ created_at: string;
98
+ message: {
99
+ role: 'assistant';
100
+ content: string;
101
+ tool_calls?: OllamaToolCall[];
102
+ };
103
+ done: boolean;
104
+ done_reason?: string;
105
+ total_duration?: number;
106
+ load_duration?: number;
107
+ prompt_eval_count?: number;
108
+ prompt_eval_duration?: number;
109
+ eval_count?: number;
110
+ eval_duration?: number;
111
+ }
112
+ /**
113
+ * Non-streaming response from Ollama /api/chat
114
+ */
115
+ export interface OllamaChatResponse {
116
+ model: string;
117
+ created_at: string;
118
+ message: {
119
+ role: 'assistant';
120
+ content: string;
121
+ tool_calls?: OllamaToolCall[];
122
+ };
123
+ done: boolean;
124
+ done_reason?: string;
125
+ total_duration: number;
126
+ load_duration: number;
127
+ prompt_eval_count: number;
128
+ prompt_eval_duration: number;
129
+ eval_count: number;
130
+ eval_duration: number;
131
+ }
132
+ /**
133
+ * Result from checking if Ollama is available
134
+ */
135
+ export interface OllamaStatus {
136
+ available: boolean;
137
+ version?: string;
138
+ error?: string;
139
+ }
140
+ /**
141
+ * Ollama Service Class
142
+ * Provides methods for interacting with the local Ollama API
143
+ */
144
+ declare class OllamaService {
145
+ private baseUrl;
146
+ constructor(baseUrl?: string);
147
+ /**
148
+ * Check if Ollama is running and accessible
149
+ * @returns OllamaStatus indicating if Ollama is available
150
+ */
151
+ isOllamaRunning(): Promise<OllamaStatus>;
152
+ /**
153
+ * Get list of locally available models from Ollama
154
+ * @returns Array of OllamaModel objects
155
+ * @throws Error if Ollama is not available or request fails
156
+ */
157
+ getLocalModels(): Promise<OllamaModel[]>;
158
+ /**
159
+ * Send a chat message to an Ollama model (non-streaming)
160
+ * @param model Model name to use (e.g., "llama3:latest")
161
+ * @param messages Array of chat messages
162
+ * @param tools Optional array of tool definitions
163
+ * @param options Optional generation parameters
164
+ * @returns OllamaChatResponse with the model's reply
165
+ */
166
+ sendChatMessage(model: string, messages: OllamaChatMessage[], tools?: OllamaTool[], options?: OllamaChatRequest['options']): Promise<OllamaChatResponse>;
167
+ /**
168
+ * Check if a model name indicates it supports tool calling
169
+ * @param modelName The model name (e.g., "llama3.2:latest")
170
+ * @returns True if the model likely supports tools
171
+ */
172
+ static modelSupportsTools(modelName: string): boolean;
173
+ /**
174
+ * Send a streaming chat message to an Ollama model
175
+ * @param model Model name to use
176
+ * @param messages Array of chat messages
177
+ * @param onChunk Callback for each streaming chunk
178
+ * @param options Optional generation parameters
179
+ * @returns Final complete response after stream ends
180
+ */
181
+ sendChatMessageStreaming(model: string, messages: OllamaChatMessage[], onChunk: (chunk: OllamaChatStreamChunk) => void, options?: OllamaChatRequest['options']): Promise<OllamaChatResponse>;
182
+ /**
183
+ * Format model size for display (bytes to human-readable)
184
+ * @param bytes Size in bytes
185
+ * @returns Human-readable size string
186
+ */
187
+ static formatModelSize(bytes: number): string;
188
+ /**
189
+ * Get a user-friendly error message for common Ollama issues
190
+ * @param error The error that occurred
191
+ * @returns User-friendly error message with helpful instructions
192
+ */
193
+ static getHelpfulErrorMessage(error: Error): string;
194
+ }
195
+ export declare const ollamaService: OllamaService;
196
+ export { OllamaService };
197
+ //# sourceMappingURL=ollama-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-service.d.ts","sourceRoot":"","sources":["../../src/services/ollama-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC/B,CAAC;CACL;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,WAAW,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAClC,CAAC;CACL;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACN,IAAI,EAAE,MAAM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