@nils.del/supergrok 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +45 -0
- package/.grok/settings.json +13 -0
- package/dist/agent/index.d.ts +35 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +244 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +242 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +33 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +134 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config.d.ts +15 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +123 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/transports.d.ts +24 -0
- package/dist/mcp/transports.d.ts.map +1 -0
- package/dist/mcp/transports.js +91 -0
- package/dist/mcp/transports.js.map +1 -0
- package/dist/tools/bash.d.ts +28 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +70 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/index.d.ts +77 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +80 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/text-editor.d.ts +69 -0
- package/dist/tools/text-editor.d.ts.map +1 -0
- package/dist/tools/text-editor.js +178 -0
- package/dist/tools/text-editor.js.map +1 -0
- package/dist/tools/types.d.ts +14 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/ui/readline-ui.d.ts +32 -0
- package/dist/ui/readline-ui.d.ts.map +1 -0
- package/dist/ui/readline-ui.js +256 -0
- package/dist/ui/readline-ui.js.map +1 -0
- package/dist/utils/settings.d.ts +20 -0
- package/dist/utils/settings.d.ts.map +1 -0
- package/dist/utils/settings.js +101 -0
- package/dist/utils/settings.js.map +1 -0
- package/package.json +51 -0
- package/src/agent/index.ts +302 -0
- package/src/index.ts +275 -0
- package/src/mcp/client.ts +178 -0
- package/src/mcp/config.ts +149 -0
- package/src/mcp/transports.ts +142 -0
- package/src/tools/bash.ts +84 -0
- package/src/tools/index.ts +91 -0
- package/src/tools/text-editor.ts +222 -0
- package/src/tools/types.ts +14 -0
- package/src/ui/readline-ui.ts +294 -0
- package/src/utils/settings.ts +129 -0
- package/tsconfig.json +20 -0
package/.env
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Active Model - Options: "grok", "claude", "llama-finetuned"
|
|
2
|
+
ACTIVE_MODEL=llama-finetuned
|
|
3
|
+
|
|
4
|
+
# Anthropic API
|
|
5
|
+
ANTHROPIC_API_KEY=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
|
|
6
|
+
|
|
7
|
+
# xAI (Grok) API
|
|
8
|
+
XAI_API_KEY=xai-RUaYXtYkmL0llOyRNtks4nfI2bW9Z0fhxu3qyk4xiU2enWJWXYjYyTswath5zTfwMu0agziSp836bLW3
|
|
9
|
+
|
|
10
|
+
# Telegram Bot
|
|
11
|
+
TELEGRAM_BOT_TOKEN=8568943279:AAFWxdPm10zlVU5D2VfbOeIfwe1IeYKixKM
|
|
12
|
+
TELEGRAM_ADMIN_CHAT_IDS=-5085659125
|
|
13
|
+
|
|
14
|
+
# Clerk API
|
|
15
|
+
CLERK_SECRET_KEY=sk_test_iX9l4S8vM4pvLrqqvoHZyUJKgQhn2bI77kQwveLBJB
|
|
16
|
+
|
|
17
|
+
GOOGLE_API_KEY=AIzaSyDuB2WadqUDqGHcXNQ15txR_Wwd34zqy8U
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Infomaniak SMTP
|
|
21
|
+
INFOMANIAK_SMTP_HOST=mail.infomaniak.com
|
|
22
|
+
INFOMANIAK_SMTP_PORT=587
|
|
23
|
+
INFOMANIAK_SMTP_USER=contact@clashware.com
|
|
24
|
+
INFOMANIAK_SMTP_PASSWORD=tP6kgBYHXRcCg8ue
|
|
25
|
+
INFOMANIAK_FROM_EMAIL=contact@clashware.com
|
|
26
|
+
INFOMANIAK_FROM_NAME=Clashware
|
|
27
|
+
|
|
28
|
+
# Tavily for web search
|
|
29
|
+
TAVILY_API_KEY=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
|
|
30
|
+
|
|
31
|
+
# Unsubscribe settings
|
|
32
|
+
UNSUBSCRIBE_BASE_URL=https://bonega.ai/api/email/unsubscribe
|
|
33
|
+
UNSUBSCRIBE_SECRET=RArdl3vxpzgrS2pJ/3c3ekq1oY61Ld5Of7H4DYbO4p8=
|
|
34
|
+
|
|
35
|
+
# Hugging Face (for model upload)
|
|
36
|
+
HF_TOKEN=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
|
|
37
|
+
|
|
38
|
+
# RunPod Serverless (fine-tuned Llama model)
|
|
39
|
+
RUNPOD_API_KEY=rpa_YQ97KFWORER2CS8H2JN4XRPXRX425ZCO4Q6GR98Oyr08hp
|
|
40
|
+
RUNPOD_ENDPOINT_ID=x7ftmgzf7lk9wk
|
|
41
|
+
RUNPOD_ENDPOINT_URL=https://api.runpod.ai/v2/x7ftmgzf7lk9wk/openai/v1
|
|
42
|
+
RUNPOD_MODEL_NAME=clashware/mail-agent-llama
|
|
43
|
+
|
|
44
|
+
# UploadThing (for hosting email screenshots)
|
|
45
|
+
UPLOADTHING_TOKEN='eyJhcGlLZXkiOiJza19saXZlX2M4ZTNhMWI5MDk1Y2E5NjlkNjgzZDIxZGM4ZjNlNjQ4Njg1NzMxZjYxY2NkMmY0ZWJkYjFkNmE0MWFkNzJhY2IiLCJhcHBJZCI6Imh6NTlkemF5a3ciLCJyZWdpb25zIjpbInNlYTEiXX0='
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ToolResult, ToolCall } from '../tools/index.js';
|
|
2
|
+
export interface ChatEntry {
|
|
3
|
+
type: 'user' | 'assistant' | 'tool_call' | 'tool_result';
|
|
4
|
+
content: string;
|
|
5
|
+
timestamp: Date;
|
|
6
|
+
toolCall?: ToolCall;
|
|
7
|
+
toolCalls?: ToolCall[];
|
|
8
|
+
toolResult?: ToolResult;
|
|
9
|
+
isStreaming?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface StreamChunk {
|
|
12
|
+
type: 'content' | 'tool_calls' | 'tool_result' | 'token_count' | 'done';
|
|
13
|
+
content?: string;
|
|
14
|
+
toolCalls?: ToolCall[];
|
|
15
|
+
toolCall?: ToolCall;
|
|
16
|
+
toolResult?: ToolResult;
|
|
17
|
+
tokenCount?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class GrokAgent {
|
|
20
|
+
private client;
|
|
21
|
+
private model;
|
|
22
|
+
private messages;
|
|
23
|
+
private maxToolRounds;
|
|
24
|
+
private abortController;
|
|
25
|
+
constructor(apiKey: string, baseURL?: string, model?: string, maxToolRounds?: number);
|
|
26
|
+
getCurrentModel(): string;
|
|
27
|
+
setModel(model: string): void;
|
|
28
|
+
abortCurrentOperation(): void;
|
|
29
|
+
executeBashCommand(command: string): Promise<ToolResult>;
|
|
30
|
+
processUserMessageStream(userMessage: string): AsyncGenerator<StreamChunk>;
|
|
31
|
+
processUserMessage(userMessage: string): Promise<ChatEntry[]>;
|
|
32
|
+
clearHistory(): void;
|
|
33
|
+
shutdown(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIvF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,GAA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CAIhC"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { getAllTools, executeToolCall } from '../tools/index.js';
|
|
3
|
+
import { loadCustomInstructions, getCurrentModel } from '../utils/settings.js';
|
|
4
|
+
import { getMCPManager } from '../mcp/client.js';
|
|
5
|
+
const DEFAULT_SYSTEM_PROMPT = `You are Grok, a powerful AI assistant running in a command-line interface.
|
|
6
|
+
|
|
7
|
+
You have access to various tools to help users with their tasks:
|
|
8
|
+
- bash: Execute shell commands
|
|
9
|
+
- str_replace_editor: View and edit files (view, create, str_replace, insert)
|
|
10
|
+
- MCP tools: Additional capabilities from connected Model Context Protocol servers
|
|
11
|
+
|
|
12
|
+
Guidelines:
|
|
13
|
+
1. Be concise but helpful
|
|
14
|
+
2. Use tools when appropriate to accomplish tasks
|
|
15
|
+
3. When editing files, first view the file to understand its structure
|
|
16
|
+
4. For complex changes, break them into smaller steps
|
|
17
|
+
5. Always confirm destructive operations
|
|
18
|
+
6. Provide clear feedback about what you're doing
|
|
19
|
+
|
|
20
|
+
Current working directory: ${process.cwd()}`;
|
|
21
|
+
export class GrokAgent {
|
|
22
|
+
client;
|
|
23
|
+
model;
|
|
24
|
+
messages = [];
|
|
25
|
+
maxToolRounds;
|
|
26
|
+
abortController = null;
|
|
27
|
+
constructor(apiKey, baseURL, model, maxToolRounds = 400) {
|
|
28
|
+
this.client = new OpenAI({
|
|
29
|
+
apiKey,
|
|
30
|
+
baseURL: baseURL || 'https://api.x.ai/v1'
|
|
31
|
+
});
|
|
32
|
+
this.model = model || getCurrentModel();
|
|
33
|
+
this.maxToolRounds = maxToolRounds;
|
|
34
|
+
// Initialize system prompt
|
|
35
|
+
const customInstructions = loadCustomInstructions();
|
|
36
|
+
let systemPrompt = DEFAULT_SYSTEM_PROMPT;
|
|
37
|
+
if (customInstructions) {
|
|
38
|
+
systemPrompt += `\n\nCustom Instructions:\n${customInstructions}`;
|
|
39
|
+
}
|
|
40
|
+
this.messages.push({
|
|
41
|
+
role: 'system',
|
|
42
|
+
content: systemPrompt
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getCurrentModel() {
|
|
46
|
+
return this.model;
|
|
47
|
+
}
|
|
48
|
+
setModel(model) {
|
|
49
|
+
this.model = model;
|
|
50
|
+
}
|
|
51
|
+
abortCurrentOperation() {
|
|
52
|
+
if (this.abortController) {
|
|
53
|
+
this.abortController.abort();
|
|
54
|
+
this.abortController = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async executeBashCommand(command) {
|
|
58
|
+
const { executeBashCommand } = await import('../tools/bash.js');
|
|
59
|
+
return executeBashCommand({ command });
|
|
60
|
+
}
|
|
61
|
+
async *processUserMessageStream(userMessage) {
|
|
62
|
+
this.abortController = new AbortController();
|
|
63
|
+
this.messages.push({
|
|
64
|
+
role: 'user',
|
|
65
|
+
content: userMessage
|
|
66
|
+
});
|
|
67
|
+
let toolRounds = 0;
|
|
68
|
+
while (toolRounds < this.maxToolRounds) {
|
|
69
|
+
const tools = await getAllTools();
|
|
70
|
+
try {
|
|
71
|
+
const stream = await this.client.chat.completions.create({
|
|
72
|
+
model: this.model,
|
|
73
|
+
messages: this.messages,
|
|
74
|
+
tools: tools,
|
|
75
|
+
stream: true
|
|
76
|
+
}, { signal: this.abortController?.signal });
|
|
77
|
+
let currentContent = '';
|
|
78
|
+
let toolCalls = [];
|
|
79
|
+
let currentToolCallId = '';
|
|
80
|
+
let currentToolCallName = '';
|
|
81
|
+
let currentToolCallArgs = '';
|
|
82
|
+
for await (const chunk of stream) {
|
|
83
|
+
const delta = chunk.choices[0]?.delta;
|
|
84
|
+
// Handle content
|
|
85
|
+
if (delta?.content) {
|
|
86
|
+
currentContent += delta.content;
|
|
87
|
+
yield { type: 'content', content: delta.content };
|
|
88
|
+
}
|
|
89
|
+
// Handle tool calls
|
|
90
|
+
if (delta?.tool_calls) {
|
|
91
|
+
for (const tc of delta.tool_calls) {
|
|
92
|
+
if (tc.id) {
|
|
93
|
+
if (currentToolCallId && currentToolCallName) {
|
|
94
|
+
toolCalls.push({
|
|
95
|
+
id: currentToolCallId,
|
|
96
|
+
type: 'function',
|
|
97
|
+
function: {
|
|
98
|
+
name: currentToolCallName,
|
|
99
|
+
arguments: currentToolCallArgs
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
currentToolCallId = tc.id;
|
|
104
|
+
currentToolCallName = tc.function?.name || '';
|
|
105
|
+
currentToolCallArgs = tc.function?.arguments || '';
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (tc.function?.name)
|
|
109
|
+
currentToolCallName += tc.function.name;
|
|
110
|
+
if (tc.function?.arguments)
|
|
111
|
+
currentToolCallArgs += tc.function.arguments;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Token count (approximate from stream)
|
|
116
|
+
if (chunk.usage?.total_tokens) {
|
|
117
|
+
yield { type: 'token_count', tokenCount: chunk.usage.total_tokens };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Push last tool call if any
|
|
121
|
+
if (currentToolCallId && currentToolCallName) {
|
|
122
|
+
toolCalls.push({
|
|
123
|
+
id: currentToolCallId,
|
|
124
|
+
type: 'function',
|
|
125
|
+
function: {
|
|
126
|
+
name: currentToolCallName,
|
|
127
|
+
arguments: currentToolCallArgs
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// If we have tool calls, execute them
|
|
132
|
+
if (toolCalls.length > 0) {
|
|
133
|
+
// Add assistant message with tool calls
|
|
134
|
+
this.messages.push({
|
|
135
|
+
role: 'assistant',
|
|
136
|
+
content: currentContent || null,
|
|
137
|
+
tool_calls: toolCalls.map(tc => ({
|
|
138
|
+
id: tc.id,
|
|
139
|
+
type: 'function',
|
|
140
|
+
function: {
|
|
141
|
+
name: tc.function.name,
|
|
142
|
+
arguments: tc.function.arguments
|
|
143
|
+
}
|
|
144
|
+
}))
|
|
145
|
+
});
|
|
146
|
+
yield { type: 'tool_calls', toolCalls };
|
|
147
|
+
// Execute each tool call
|
|
148
|
+
for (const toolCall of toolCalls) {
|
|
149
|
+
const result = await executeToolCall(toolCall);
|
|
150
|
+
// Add tool result to messages
|
|
151
|
+
this.messages.push({
|
|
152
|
+
role: 'tool',
|
|
153
|
+
tool_call_id: toolCall.id,
|
|
154
|
+
content: result.success ? (result.output || 'Success') : (result.error || 'Error')
|
|
155
|
+
});
|
|
156
|
+
yield { type: 'tool_result', toolCall, toolResult: result };
|
|
157
|
+
}
|
|
158
|
+
toolRounds++;
|
|
159
|
+
// Continue the loop to let the model respond to tool results
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// No tool calls, we're done
|
|
163
|
+
if (currentContent) {
|
|
164
|
+
this.messages.push({
|
|
165
|
+
role: 'assistant',
|
|
166
|
+
content: currentContent
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error.name === 'AbortError') {
|
|
174
|
+
yield { type: 'content', content: '\n[Operation aborted]' };
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
yield { type: 'done' };
|
|
181
|
+
this.abortController = null;
|
|
182
|
+
}
|
|
183
|
+
async processUserMessage(userMessage) {
|
|
184
|
+
const entries = [];
|
|
185
|
+
entries.push({
|
|
186
|
+
type: 'user',
|
|
187
|
+
content: userMessage,
|
|
188
|
+
timestamp: new Date()
|
|
189
|
+
});
|
|
190
|
+
let assistantContent = '';
|
|
191
|
+
for await (const chunk of this.processUserMessageStream(userMessage)) {
|
|
192
|
+
switch (chunk.type) {
|
|
193
|
+
case 'content':
|
|
194
|
+
if (chunk.content) {
|
|
195
|
+
assistantContent += chunk.content;
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case 'tool_calls':
|
|
199
|
+
if (assistantContent) {
|
|
200
|
+
entries.push({
|
|
201
|
+
type: 'assistant',
|
|
202
|
+
content: assistantContent,
|
|
203
|
+
timestamp: new Date(),
|
|
204
|
+
toolCalls: chunk.toolCalls
|
|
205
|
+
});
|
|
206
|
+
assistantContent = '';
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
case 'tool_result':
|
|
210
|
+
if (chunk.toolCall && chunk.toolResult) {
|
|
211
|
+
entries.push({
|
|
212
|
+
type: 'tool_result',
|
|
213
|
+
content: chunk.toolResult.success
|
|
214
|
+
? (chunk.toolResult.output || 'Success')
|
|
215
|
+
: (chunk.toolResult.error || 'Error'),
|
|
216
|
+
timestamp: new Date(),
|
|
217
|
+
toolCall: chunk.toolCall,
|
|
218
|
+
toolResult: chunk.toolResult
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case 'done':
|
|
223
|
+
if (assistantContent) {
|
|
224
|
+
entries.push({
|
|
225
|
+
type: 'assistant',
|
|
226
|
+
content: assistantContent,
|
|
227
|
+
timestamp: new Date()
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return entries;
|
|
234
|
+
}
|
|
235
|
+
clearHistory() {
|
|
236
|
+
// Keep only the system message
|
|
237
|
+
this.messages = this.messages.slice(0, 1);
|
|
238
|
+
}
|
|
239
|
+
async shutdown() {
|
|
240
|
+
const mcpManager = getMCPManager();
|
|
241
|
+
await mcpManager.shutdown();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAwB,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,sB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U,GAAG,aAAa,EAAE,CAAC;QACnC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from 'commander';
|
|
3
|
+
import * as dotenv from 'dotenv';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { GrokAgent } from './agent/index.js';
|
|
6
|
+
import { runReadlineUI } from './ui/readline-ui.js';
|
|
7
|
+
import { getApiKey, getBaseURL, getCurrentModel, saveUserSettings, loadUserSettings } from './utils/settings.js';
|
|
8
|
+
// Load environment variables
|
|
9
|
+
dotenv.config();
|
|
10
|
+
// Handle uncaught exceptions
|
|
11
|
+
process.on('uncaughtException', (error) => {
|
|
12
|
+
console.error(chalk.red('Uncaught exception:'), error.message);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
|
15
|
+
process.on('unhandledRejection', (reason) => {
|
|
16
|
+
console.error(chalk.red('Unhandled rejection:'), reason?.message || reason);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
|
19
|
+
// Headless mode processing
|
|
20
|
+
async function processPromptHeadless(prompt, apiKey, baseURL, model, maxToolRounds) {
|
|
21
|
+
try {
|
|
22
|
+
const agent = new GrokAgent(apiKey, baseURL, model, maxToolRounds);
|
|
23
|
+
console.log(chalk.gray('Processing...'));
|
|
24
|
+
console.log();
|
|
25
|
+
for await (const chunk of agent.processUserMessageStream(prompt)) {
|
|
26
|
+
switch (chunk.type) {
|
|
27
|
+
case 'content':
|
|
28
|
+
if (chunk.content) {
|
|
29
|
+
process.stdout.write(chunk.content);
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
case 'tool_calls':
|
|
33
|
+
if (chunk.toolCalls) {
|
|
34
|
+
console.log();
|
|
35
|
+
for (const tc of chunk.toolCalls) {
|
|
36
|
+
console.log(chalk.blue(`⚡ ${tc.function.name}`));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
case 'tool_result':
|
|
41
|
+
if (chunk.toolResult) {
|
|
42
|
+
if (chunk.toolResult.success) {
|
|
43
|
+
console.log(chalk.green('✓'), chalk.gray(chunk.toolResult.output?.substring(0, 200) || 'Success'));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.log(chalk.red('✗'), chunk.toolResult.error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case 'done':
|
|
51
|
+
console.log();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
await agent.shutdown();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error(chalk.red('Error:'), error.message);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
program
|
|
63
|
+
.name('grok-fixed')
|
|
64
|
+
.description('Grok CLI (Fixed Edition) - Works properly with MCP on Linux. No Ink flickering issues.')
|
|
65
|
+
.version('1.0.0')
|
|
66
|
+
.argument('[message...]', 'Initial message to send to Grok')
|
|
67
|
+
.option('-d, --directory <dir>', 'Set working directory', process.cwd())
|
|
68
|
+
.option('-k, --api-key <key>', 'Grok API key (or set GROK_API_KEY env var)')
|
|
69
|
+
.option('-u, --base-url <url>', 'Grok API base URL (or set GROK_BASE_URL env var)')
|
|
70
|
+
.option('-m, --model <model>', 'AI model to use (or set GROK_MODEL env var)')
|
|
71
|
+
.option('-p, --prompt <prompt>', 'Process a single prompt and exit (headless mode)')
|
|
72
|
+
.option('--max-tool-rounds <rounds>', 'Maximum tool execution rounds (default: 400)', '400')
|
|
73
|
+
.action(async (message, options) => {
|
|
74
|
+
// Change working directory if specified
|
|
75
|
+
if (options.directory) {
|
|
76
|
+
try {
|
|
77
|
+
process.chdir(options.directory);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error(chalk.red(`Error changing directory: ${error.message}`));
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
// Get API key
|
|
86
|
+
const apiKey = options.apiKey || getApiKey();
|
|
87
|
+
const baseURL = options.baseUrl || getBaseURL();
|
|
88
|
+
const model = options.model || getCurrentModel();
|
|
89
|
+
const maxToolRounds = parseInt(options.maxToolRounds) || 400;
|
|
90
|
+
if (!apiKey) {
|
|
91
|
+
console.error(chalk.red('Error: API key required.'));
|
|
92
|
+
console.error(chalk.gray('Set GROK_API_KEY environment variable, use --api-key flag,'));
|
|
93
|
+
console.error(chalk.gray('or add "apiKey" to ~/.grok/user-settings.json'));
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
// Save API key if provided via command line
|
|
97
|
+
if (options.apiKey) {
|
|
98
|
+
const settings = loadUserSettings();
|
|
99
|
+
settings.apiKey = options.apiKey;
|
|
100
|
+
if (options.baseUrl) {
|
|
101
|
+
settings.baseURL = options.baseUrl;
|
|
102
|
+
}
|
|
103
|
+
saveUserSettings(settings);
|
|
104
|
+
console.log(chalk.green('✓ API key saved to ~/.grok/user-settings.json'));
|
|
105
|
+
}
|
|
106
|
+
// Headless mode
|
|
107
|
+
if (options.prompt) {
|
|
108
|
+
await processPromptHeadless(options.prompt, apiKey, baseURL, model, maxToolRounds);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// Interactive mode
|
|
112
|
+
const agent = new GrokAgent(apiKey, baseURL, model, maxToolRounds);
|
|
113
|
+
const initialMessage = Array.isArray(message) ? message.join(' ') : message;
|
|
114
|
+
await runReadlineUI(agent, initialMessage || undefined);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error(chalk.red('Error:'), error.message);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
// MCP subcommand
|
|
122
|
+
const mcpCommand = program
|
|
123
|
+
.command('mcp')
|
|
124
|
+
.description('Manage MCP (Model Context Protocol) servers');
|
|
125
|
+
mcpCommand
|
|
126
|
+
.command('list')
|
|
127
|
+
.description('List configured MCP servers')
|
|
128
|
+
.action(async () => {
|
|
129
|
+
const { loadMCPConfig } = await import('./mcp/config.js');
|
|
130
|
+
const config = loadMCPConfig();
|
|
131
|
+
if (config.servers.length === 0) {
|
|
132
|
+
console.log(chalk.gray('No MCP servers configured.'));
|
|
133
|
+
console.log(chalk.gray('Use "grok-fixed mcp add" to add a server.'));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
console.log(chalk.cyan('Configured MCP Servers:'));
|
|
137
|
+
for (const server of config.servers) {
|
|
138
|
+
console.log(chalk.white(` • ${server.name}`));
|
|
139
|
+
console.log(chalk.gray(` Transport: ${server.transport.type}`));
|
|
140
|
+
if (server.transport.type === 'stdio') {
|
|
141
|
+
console.log(chalk.gray(` Command: ${server.transport.command} ${(server.transport.args || []).join(' ')}`));
|
|
142
|
+
}
|
|
143
|
+
else if ('url' in server.transport) {
|
|
144
|
+
console.log(chalk.gray(` URL: ${server.transport.url}`));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
mcpCommand
|
|
149
|
+
.command('add <name>')
|
|
150
|
+
.description('Add a new MCP server')
|
|
151
|
+
.option('-t, --transport <type>', 'Transport type (stdio, http, sse)', 'stdio')
|
|
152
|
+
.option('-c, --command <command>', 'Command to run (for stdio transport)')
|
|
153
|
+
.option('-a, --args <args...>', 'Arguments for the command')
|
|
154
|
+
.option('-u, --url <url>', 'URL (for http/sse transport)')
|
|
155
|
+
.option('-e, --env <env...>', 'Environment variables (KEY=value format)')
|
|
156
|
+
.action(async (name, options) => {
|
|
157
|
+
const { saveMCPServerConfig } = await import('./mcp/config.js');
|
|
158
|
+
let transport;
|
|
159
|
+
if (options.transport === 'stdio') {
|
|
160
|
+
if (!options.command) {
|
|
161
|
+
console.error(chalk.red('Error: --command is required for stdio transport'));
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
const env = {};
|
|
165
|
+
if (options.env) {
|
|
166
|
+
for (const e of options.env) {
|
|
167
|
+
const [key, ...valueParts] = e.split('=');
|
|
168
|
+
env[key] = valueParts.join('=');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
transport = {
|
|
172
|
+
type: 'stdio',
|
|
173
|
+
command: options.command,
|
|
174
|
+
args: options.args || [],
|
|
175
|
+
env
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
else if (options.transport === 'http' || options.transport === 'sse') {
|
|
179
|
+
if (!options.url) {
|
|
180
|
+
console.error(chalk.red(`Error: --url is required for ${options.transport} transport`));
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
transport = {
|
|
184
|
+
type: options.transport,
|
|
185
|
+
url: options.url
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.error(chalk.red(`Error: Unknown transport type: ${options.transport}`));
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
saveMCPServerConfig({ name, transport });
|
|
194
|
+
console.log(chalk.green(`✓ MCP server "${name}" added successfully`));
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
mcpCommand
|
|
202
|
+
.command('remove <name>')
|
|
203
|
+
.description('Remove an MCP server')
|
|
204
|
+
.action(async (name) => {
|
|
205
|
+
const { removeMCPServerConfig } = await import('./mcp/config.js');
|
|
206
|
+
if (removeMCPServerConfig(name)) {
|
|
207
|
+
console.log(chalk.green(`✓ MCP server "${name}" removed`));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.log(chalk.yellow(`Server "${name}" not found`));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
mcpCommand
|
|
214
|
+
.command('test [name]')
|
|
215
|
+
.description('Test connection to MCP server(s)')
|
|
216
|
+
.action(async (name) => {
|
|
217
|
+
const { loadMCPConfig } = await import('./mcp/config.js');
|
|
218
|
+
const { getMCPManager } = await import('./mcp/client.js');
|
|
219
|
+
const config = loadMCPConfig();
|
|
220
|
+
const serversToTest = name
|
|
221
|
+
? config.servers.filter(s => s.name === name)
|
|
222
|
+
: config.servers;
|
|
223
|
+
if (serversToTest.length === 0) {
|
|
224
|
+
console.log(chalk.yellow('No servers to test.'));
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const mcpManager = getMCPManager();
|
|
228
|
+
for (const server of serversToTest) {
|
|
229
|
+
process.stdout.write(chalk.gray(`Testing ${server.name}... `));
|
|
230
|
+
try {
|
|
231
|
+
await mcpManager.addServer(server);
|
|
232
|
+
const tools = mcpManager.getTools().filter(t => t.serverName === server.name);
|
|
233
|
+
console.log(chalk.green(`✓ Connected (${tools.length} tools)`));
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
console.log(chalk.red(`✗ Failed: ${error.message}`));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
await mcpManager.shutdown();
|
|
240
|
+
});
|
|
241
|
+
program.parse();
|
|
242
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,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AAG,CAAC,KAAK,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC;QACjD,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,KAAK,MAAM,MAAM,IAAI,aAAa,EAAE,CAAC;QACnC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC;QAE/D,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC;YAC9E,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,KAAK,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC;QAClE,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { TransportType, TransportConfig } from "./transports.js";
|
|
4
|
+
export interface MCPServerConfig {
|
|
5
|
+
name: string;
|
|
6
|
+
transport: TransportConfig;
|
|
7
|
+
command?: string;
|
|
8
|
+
args?: string[];
|
|
9
|
+
env?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
export interface MCPTool {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
inputSchema: any;
|
|
15
|
+
serverName: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class MCPManager extends EventEmitter {
|
|
18
|
+
private clients;
|
|
19
|
+
private transports;
|
|
20
|
+
private tools;
|
|
21
|
+
private initPromise;
|
|
22
|
+
addServer(config: MCPServerConfig): Promise<void>;
|
|
23
|
+
removeServer(serverName: string): Promise<void>;
|
|
24
|
+
callTool(toolName: string, arguments_: any): Promise<CallToolResult>;
|
|
25
|
+
getTools(): MCPTool[];
|
|
26
|
+
getServers(): string[];
|
|
27
|
+
shutdown(): Promise<void>;
|
|
28
|
+
getTransportType(serverName: string): TransportType | undefined;
|
|
29
|
+
ensureServersInitialized(): Promise<void>;
|
|
30
|
+
private initializeServers;
|
|
31
|
+
}
|
|
32
|
+
export declare function getMCPManager(): MCPManager;
|
|
33
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAiC,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhG,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,GAAG,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,UA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