@zds-ai/cli 0.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/LICENSE +21 -0
- package/README.md +497 -0
- package/dist/agent/grok-agent.d.ts +250 -0
- package/dist/agent/grok-agent.js +2480 -0
- package/dist/agent/grok-agent.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.js +136 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +239 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/grok/client.d.ts +55 -0
- package/dist/grok/client.js +276 -0
- package/dist/grok/client.js.map +1 -0
- package/dist/grok/tools.d.ts +8 -0
- package/dist/grok/tools.js +878 -0
- package/dist/grok/tools.js.map +1 -0
- package/dist/hooks/use-enhanced-input.d.ts +38 -0
- package/dist/hooks/use-enhanced-input.js +228 -0
- package/dist/hooks/use-enhanced-input.js.map +1 -0
- package/dist/hooks/use-input-handler.d.ts +36 -0
- package/dist/hooks/use-input-handler.js +1099 -0
- package/dist/hooks/use-input-handler.js.map +1 -0
- package/dist/hooks/use-input-history.d.ts +9 -0
- package/dist/hooks/use-input-history.js +61 -0
- package/dist/hooks/use-input-history.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +869 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +41 -0
- package/dist/mcp/client.js +224 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config.d.ts +13 -0
- package/dist/mcp/config.js +56 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/transports.d.ts +53 -0
- package/dist/mcp/transports.js +256 -0
- package/dist/mcp/transports.js.map +1 -0
- package/dist/tools/character-tool.d.ts +27 -0
- package/dist/tools/character-tool.js +194 -0
- package/dist/tools/character-tool.js.map +1 -0
- package/dist/tools/clear-cache-tool.d.ts +14 -0
- package/dist/tools/clear-cache-tool.js +82 -0
- package/dist/tools/clear-cache-tool.js.map +1 -0
- package/dist/tools/confirmation-tool.d.ts +16 -0
- package/dist/tools/confirmation-tool.js +72 -0
- package/dist/tools/confirmation-tool.js.map +1 -0
- package/dist/tools/env-tool.d.ts +17 -0
- package/dist/tools/env-tool.js +89 -0
- package/dist/tools/env-tool.js.map +1 -0
- package/dist/tools/file-conversion-tool.d.ts +16 -0
- package/dist/tools/file-conversion-tool.js +181 -0
- package/dist/tools/file-conversion-tool.js.map +1 -0
- package/dist/tools/image-tool.d.ts +22 -0
- package/dist/tools/image-tool.js +268 -0
- package/dist/tools/image-tool.js.map +1 -0
- package/dist/tools/index.d.ts +14 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internet-tool.d.ts +11 -0
- package/dist/tools/internet-tool.js +108 -0
- package/dist/tools/internet-tool.js.map +1 -0
- package/dist/tools/introspect-tool.d.ts +11 -0
- package/dist/tools/introspect-tool.js +243 -0
- package/dist/tools/introspect-tool.js.map +1 -0
- package/dist/tools/morph-editor.d.ts +38 -0
- package/dist/tools/morph-editor.js +318 -0
- package/dist/tools/morph-editor.js.map +1 -0
- package/dist/tools/restart-tool.d.ts +7 -0
- package/dist/tools/restart-tool.js +24 -0
- package/dist/tools/restart-tool.js.map +1 -0
- package/dist/tools/search.d.ts +71 -0
- package/dist/tools/search.js +340 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/task-tool.d.ts +19 -0
- package/dist/tools/task-tool.js +115 -0
- package/dist/tools/task-tool.js.map +1 -0
- package/dist/tools/text-editor.d.ts +35 -0
- package/dist/tools/text-editor.js +669 -0
- package/dist/tools/text-editor.js.map +1 -0
- package/dist/tools/tool-discovery.d.ts +20 -0
- package/dist/tools/tool-discovery.js +45 -0
- package/dist/tools/tool-discovery.js.map +1 -0
- package/dist/tools/zsh.d.ts +13 -0
- package/dist/tools/zsh.js +168 -0
- package/dist/tools/zsh.js.map +1 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/app.d.ts +7 -0
- package/dist/ui/app.js +99 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/components/active-task-status.d.ts +7 -0
- package/dist/ui/components/active-task-status.js +37 -0
- package/dist/ui/components/active-task-status.js.map +1 -0
- package/dist/ui/components/api-key-input.d.ts +7 -0
- package/dist/ui/components/api-key-input.js +80 -0
- package/dist/ui/components/api-key-input.js.map +1 -0
- package/dist/ui/components/backend-status.d.ts +7 -0
- package/dist/ui/components/backend-status.js +85 -0
- package/dist/ui/components/backend-status.js.map +1 -0
- package/dist/ui/components/chat-history.d.ts +8 -0
- package/dist/ui/components/chat-history.js +187 -0
- package/dist/ui/components/chat-history.js.map +1 -0
- package/dist/ui/components/chat-input.d.ts +9 -0
- package/dist/ui/components/chat-input.js +63 -0
- package/dist/ui/components/chat-input.js.map +1 -0
- package/dist/ui/components/chat-interface.d.ts +9 -0
- package/dist/ui/components/chat-interface.js +389 -0
- package/dist/ui/components/chat-interface.js.map +1 -0
- package/dist/ui/components/command-suggestions.d.ts +17 -0
- package/dist/ui/components/command-suggestions.js +22 -0
- package/dist/ui/components/command-suggestions.js.map +1 -0
- package/dist/ui/components/confirmation-dialog.d.ts +11 -0
- package/dist/ui/components/confirmation-dialog.js +105 -0
- package/dist/ui/components/confirmation-dialog.js.map +1 -0
- package/dist/ui/components/context-status.d.ts +7 -0
- package/dist/ui/components/context-status.js +36 -0
- package/dist/ui/components/context-status.js.map +1 -0
- package/dist/ui/components/diff-renderer.d.ts +13 -0
- package/dist/ui/components/diff-renderer.js +206 -0
- package/dist/ui/components/diff-renderer.js.map +1 -0
- package/dist/ui/components/loading-spinner.d.ts +8 -0
- package/dist/ui/components/loading-spinner.js +64 -0
- package/dist/ui/components/loading-spinner.js.map +1 -0
- package/dist/ui/components/mcp-status.d.ts +5 -0
- package/dist/ui/components/mcp-status.js +57 -0
- package/dist/ui/components/mcp-status.js.map +1 -0
- package/dist/ui/components/model-selection.d.ts +12 -0
- package/dist/ui/components/model-selection.js +17 -0
- package/dist/ui/components/model-selection.js.map +1 -0
- package/dist/ui/components/mood-status.d.ts +7 -0
- package/dist/ui/components/mood-status.js +34 -0
- package/dist/ui/components/mood-status.js.map +1 -0
- package/dist/ui/components/persona-status.d.ts +7 -0
- package/dist/ui/components/persona-status.js +34 -0
- package/dist/ui/components/persona-status.js.map +1 -0
- package/dist/ui/shared/max-sized-box.d.ts +8 -0
- package/dist/ui/shared/max-sized-box.js +6 -0
- package/dist/ui/shared/max-sized-box.js.map +1 -0
- package/dist/ui/utils/code-colorizer.d.ts +2 -0
- package/dist/ui/utils/code-colorizer.js +7 -0
- package/dist/ui/utils/code-colorizer.js.map +1 -0
- package/dist/ui/utils/colors.d.ts +14 -0
- package/dist/ui/utils/colors.js +15 -0
- package/dist/ui/utils/colors.js.map +1 -0
- package/dist/ui/utils/markdown-renderer.d.ts +4 -0
- package/dist/ui/utils/markdown-renderer.js +40 -0
- package/dist/ui/utils/markdown-renderer.js.map +1 -0
- package/dist/utils/auth-helper.d.ts +63 -0
- package/dist/utils/auth-helper.js +129 -0
- package/dist/utils/auth-helper.js.map +1 -0
- package/dist/utils/chat-history-manager-sqlite.d.ts +92 -0
- package/dist/utils/chat-history-manager-sqlite.js +334 -0
- package/dist/utils/chat-history-manager-sqlite.js.map +1 -0
- package/dist/utils/chat-history-manager.d.ts +87 -0
- package/dist/utils/chat-history-manager.js +273 -0
- package/dist/utils/chat-history-manager.js.map +1 -0
- package/dist/utils/chat-history-manager.json-backup.d.ts +69 -0
- package/dist/utils/chat-history-manager.json-backup.js +215 -0
- package/dist/utils/chat-history-manager.json-backup.js.map +1 -0
- package/dist/utils/confirmation-service.d.ts +46 -0
- package/dist/utils/confirmation-service.js +165 -0
- package/dist/utils/confirmation-service.js.map +1 -0
- package/dist/utils/custom-instructions.d.ts +1 -0
- package/dist/utils/custom-instructions.js +30 -0
- package/dist/utils/custom-instructions.js.map +1 -0
- package/dist/utils/database-connection.d.ts +27 -0
- package/dist/utils/database-connection.js +81 -0
- package/dist/utils/database-connection.js.map +1 -0
- package/dist/utils/database-schema.d.ts +17 -0
- package/dist/utils/database-schema.js +93 -0
- package/dist/utils/database-schema.js.map +1 -0
- package/dist/utils/error-logger.d.ts +13 -0
- package/dist/utils/error-logger.js +56 -0
- package/dist/utils/error-logger.js.map +1 -0
- package/dist/utils/hook-executor.d.ts +59 -0
- package/dist/utils/hook-executor.js +351 -0
- package/dist/utils/hook-executor.js.map +1 -0
- package/dist/utils/model-config.d.ts +28 -0
- package/dist/utils/model-config.js +42 -0
- package/dist/utils/model-config.js.map +1 -0
- package/dist/utils/path-utils.d.ts +4 -0
- package/dist/utils/path-utils.js +12 -0
- package/dist/utils/path-utils.js.map +1 -0
- package/dist/utils/settings-manager.d.ts +169 -0
- package/dist/utils/settings-manager.js +403 -0
- package/dist/utils/settings-manager.js.map +1 -0
- package/dist/utils/settings.d.ts +1 -0
- package/dist/utils/settings.js +4 -0
- package/dist/utils/settings.js.map +1 -0
- package/dist/utils/slash-commands.d.ts +25 -0
- package/dist/utils/slash-commands.js +454 -0
- package/dist/utils/slash-commands.js.map +1 -0
- package/dist/utils/startup-hook.d.ts +13 -0
- package/dist/utils/startup-hook.js +44 -0
- package/dist/utils/startup-hook.js.map +1 -0
- package/dist/utils/text-utils.d.ts +80 -0
- package/dist/utils/text-utils.js +182 -0
- package/dist/utils/text-utils.js.map +1 -0
- package/dist/utils/token-counter.d.ts +33 -0
- package/dist/utils/token-counter.js +78 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ChatCompletionMessageParam } from "openai/resources/chat";
|
|
2
|
+
export type GrokMessage = ChatCompletionMessageParam;
|
|
3
|
+
export interface GrokTool {
|
|
4
|
+
type: "function";
|
|
5
|
+
function: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: {
|
|
9
|
+
type: "object";
|
|
10
|
+
properties: Record<string, any>;
|
|
11
|
+
required: string[];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface GrokToolCall {
|
|
16
|
+
id: string;
|
|
17
|
+
type: "function";
|
|
18
|
+
function: {
|
|
19
|
+
name: string;
|
|
20
|
+
arguments: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface SearchParameters {
|
|
24
|
+
mode?: "auto" | "on" | "off";
|
|
25
|
+
}
|
|
26
|
+
export interface SearchOptions {
|
|
27
|
+
search_parameters?: SearchParameters;
|
|
28
|
+
}
|
|
29
|
+
export interface GrokResponse {
|
|
30
|
+
choices: Array<{
|
|
31
|
+
message: {
|
|
32
|
+
role: string;
|
|
33
|
+
content: string | null;
|
|
34
|
+
tool_calls?: GrokToolCall[];
|
|
35
|
+
};
|
|
36
|
+
finish_reason: string;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
export declare class GrokClient {
|
|
40
|
+
private client;
|
|
41
|
+
private currentModel;
|
|
42
|
+
private defaultMaxTokens;
|
|
43
|
+
private backendName;
|
|
44
|
+
private supportsTools;
|
|
45
|
+
constructor(apiKey: string, model?: string, baseURL?: string, displayName?: string);
|
|
46
|
+
setModel(model: string): Promise<void>;
|
|
47
|
+
private enableTools;
|
|
48
|
+
getCurrentModel(): string;
|
|
49
|
+
getBaseURL(): string;
|
|
50
|
+
getBackendName(): string;
|
|
51
|
+
getSupportsTools(): boolean;
|
|
52
|
+
chat(messages: GrokMessage[], tools?: GrokTool[], model?: string, searchOptions?: SearchOptions, temperature?: number, signal?: AbortSignal, maxTokens?: number): Promise<GrokResponse>;
|
|
53
|
+
chatStream(messages: GrokMessage[], tools?: GrokTool[], model?: string, searchOptions?: SearchOptions, temperature?: number, signal?: AbortSignal, maxTokens?: number): AsyncGenerator<any, void, unknown>;
|
|
54
|
+
search(query: string, searchParameters?: SearchParameters): Promise<GrokResponse>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { ChatHistoryManager } from "../utils/chat-history-manager.js";
|
|
3
|
+
import { logApiError } from "../utils/error-logger.js";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
export class GrokClient {
|
|
6
|
+
client;
|
|
7
|
+
currentModel = "grok-code-fast-1";
|
|
8
|
+
defaultMaxTokens;
|
|
9
|
+
backendName;
|
|
10
|
+
supportsTools = true;
|
|
11
|
+
constructor(apiKey, model, baseURL, displayName) {
|
|
12
|
+
const finalBaseURL = baseURL || process.env.GROK_BASE_URL || "https://api.x.ai/v1";
|
|
13
|
+
this.client = new OpenAI({
|
|
14
|
+
apiKey,
|
|
15
|
+
baseURL: finalBaseURL,
|
|
16
|
+
timeout: 360000,
|
|
17
|
+
});
|
|
18
|
+
const envMax = Number(process.env.GROK_MAX_TOKENS);
|
|
19
|
+
this.defaultMaxTokens = Number.isFinite(envMax) && envMax > 0 ? envMax : 1536;
|
|
20
|
+
if (model) {
|
|
21
|
+
this.currentModel = model;
|
|
22
|
+
}
|
|
23
|
+
// Use provided display name, or derive from baseURL hostname as fallback
|
|
24
|
+
if (displayName) {
|
|
25
|
+
this.backendName = displayName;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// Simple fallback: extract hostname from URL
|
|
29
|
+
try {
|
|
30
|
+
const url = new URL(finalBaseURL);
|
|
31
|
+
this.backendName = url.hostname.replace(/^api\./, '').replace(/\..*$/, '');
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
this.backendName = 'AI';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async setModel(model) {
|
|
39
|
+
this.currentModel = model;
|
|
40
|
+
// Reset tool support flag when switching models
|
|
41
|
+
await this.enableTools();
|
|
42
|
+
}
|
|
43
|
+
async enableTools() {
|
|
44
|
+
if (this.supportsTools) {
|
|
45
|
+
return; // Already enabled
|
|
46
|
+
}
|
|
47
|
+
this.supportsTools = true;
|
|
48
|
+
// Reinitialize MCP servers
|
|
49
|
+
try {
|
|
50
|
+
const { getMCPManager, initializeMCPServers } = await import('../grok/tools.js');
|
|
51
|
+
const { loadMCPConfig } = await import('../mcp/config.js');
|
|
52
|
+
const config = loadMCPConfig();
|
|
53
|
+
if (config.servers.length > 0) {
|
|
54
|
+
await initializeMCPServers();
|
|
55
|
+
console.error(`MCP servers reinitialized.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (mcpError) {
|
|
59
|
+
console.warn("MCP reinitialization failed:", mcpError);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
getCurrentModel() {
|
|
63
|
+
return this.currentModel;
|
|
64
|
+
}
|
|
65
|
+
getBaseURL() {
|
|
66
|
+
return this.client.baseURL || "https://api.x.ai/v1";
|
|
67
|
+
}
|
|
68
|
+
getBackendName() {
|
|
69
|
+
return this.backendName;
|
|
70
|
+
}
|
|
71
|
+
getSupportsTools() {
|
|
72
|
+
return this.supportsTools;
|
|
73
|
+
}
|
|
74
|
+
async chat(messages, tools, model, searchOptions, temperature, signal, maxTokens) {
|
|
75
|
+
const maxRetries = 5;
|
|
76
|
+
const retryDelay = 10000; // 10 seconds
|
|
77
|
+
const requestPayload = {
|
|
78
|
+
model: model || this.currentModel,
|
|
79
|
+
messages,
|
|
80
|
+
temperature: temperature ?? 0.7,
|
|
81
|
+
max_tokens: maxTokens ?? this.defaultMaxTokens
|
|
82
|
+
};
|
|
83
|
+
// Only include tools if the model supports them AND tools are provided
|
|
84
|
+
if (this.supportsTools && tools && tools.length > 0) {
|
|
85
|
+
requestPayload.tools = tools;
|
|
86
|
+
requestPayload.tool_choice = "auto";
|
|
87
|
+
}
|
|
88
|
+
// Only add think parameter for backends that support it (Grok, Ollama)
|
|
89
|
+
const backendLower = this.backendName.toLowerCase();
|
|
90
|
+
const supportsThink = backendLower === 'grok' ||
|
|
91
|
+
backendLower === 'ollama' ||
|
|
92
|
+
this.client.baseURL?.includes('x.ai');
|
|
93
|
+
if (supportsThink) {
|
|
94
|
+
requestPayload.think = false;
|
|
95
|
+
}
|
|
96
|
+
// Add search parameters if specified and using Grok API (x.ai)
|
|
97
|
+
if (searchOptions?.search_parameters && this.client.baseURL?.includes('x.ai')) {
|
|
98
|
+
requestPayload.search_parameters = searchOptions.search_parameters;
|
|
99
|
+
}
|
|
100
|
+
// Log tools being sent to API
|
|
101
|
+
const toolNames = (tools || []).map(t => t.function.name);
|
|
102
|
+
const mcpTools = toolNames.filter(name => name.startsWith('mcp__'));
|
|
103
|
+
const debugLogPath = ChatHistoryManager.getDebugLogPath();
|
|
104
|
+
const logEntry = `${new Date().toISOString()} - API CALL: ${toolNames.length} tools (${mcpTools.length} MCP: ${mcpTools.join(', ')})\n`;
|
|
105
|
+
fs.appendFileSync(debugLogPath, logEntry);
|
|
106
|
+
// Retry loop for 429 errors
|
|
107
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
108
|
+
try {
|
|
109
|
+
const response = await this.client.chat.completions.create(requestPayload, { signal: signal });
|
|
110
|
+
return response;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Check if model doesn't support tools
|
|
114
|
+
const isToolsNotSupported = error.status === 400 &&
|
|
115
|
+
error.message &&
|
|
116
|
+
error.message.toLowerCase().includes('does not support tools');
|
|
117
|
+
if (isToolsNotSupported && this.supportsTools) {
|
|
118
|
+
// Disable tools for this model and rebuild request without tools
|
|
119
|
+
this.supportsTools = false;
|
|
120
|
+
console.error(`Model does not support tools. Retrying without tools...`);
|
|
121
|
+
// Shutdown MCP servers since they won't be usable without tools
|
|
122
|
+
try {
|
|
123
|
+
const { getMCPManager } = await import('../grok/tools.js');
|
|
124
|
+
const mcpManager = getMCPManager();
|
|
125
|
+
await mcpManager.shutdown();
|
|
126
|
+
console.error(`MCP servers shut down.`);
|
|
127
|
+
}
|
|
128
|
+
catch (mcpError) {
|
|
129
|
+
console.warn("MCP shutdown failed:", mcpError);
|
|
130
|
+
}
|
|
131
|
+
// Rebuild request payload without tools
|
|
132
|
+
delete requestPayload.tools;
|
|
133
|
+
delete requestPayload.tool_choice;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
// Check if it's a 429 rate limit error
|
|
137
|
+
const is429 = error.status === 429 ||
|
|
138
|
+
error.code === 'rate_limit_exceeded' ||
|
|
139
|
+
(error.message && error.message.toLowerCase().includes('rate limit'));
|
|
140
|
+
if (is429 && attempt < maxRetries) {
|
|
141
|
+
console.error(`Rate limit hit (429). Retrying in ${retryDelay / 1000}s... (attempt ${attempt + 1}/${maxRetries})`);
|
|
142
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
// Log 500 errors with full request/response for debugging
|
|
146
|
+
if (error.status === 500) {
|
|
147
|
+
const { requestFile, responseFile } = await logApiError(requestPayload, error, { errorType: 'runtime-api-error' }, '500');
|
|
148
|
+
// Throw error with file references
|
|
149
|
+
throw new Error(`${this.backendName} API error: ${error.message}\nRequest logged to: ${requestFile}\nResponse logged to: ${responseFile}`);
|
|
150
|
+
}
|
|
151
|
+
// If not 429 or out of retries, throw the error
|
|
152
|
+
throw new Error(`${this.backendName} API error: ${error.message}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Should never reach here, but TypeScript needs it
|
|
156
|
+
throw new Error('Grok API error: Max retries exceeded');
|
|
157
|
+
}
|
|
158
|
+
async *chatStream(messages, tools, model, searchOptions, temperature, signal, maxTokens) {
|
|
159
|
+
const maxRetries = 5;
|
|
160
|
+
const retryDelay = 10000; // 10 seconds
|
|
161
|
+
const requestPayload = {
|
|
162
|
+
model: model || this.currentModel,
|
|
163
|
+
messages,
|
|
164
|
+
temperature: temperature ?? 0.7,
|
|
165
|
+
max_tokens: maxTokens ?? this.defaultMaxTokens,
|
|
166
|
+
stream: true
|
|
167
|
+
};
|
|
168
|
+
// Only include tools if the model supports them
|
|
169
|
+
if (this.supportsTools) {
|
|
170
|
+
requestPayload.tools = tools || [];
|
|
171
|
+
}
|
|
172
|
+
// Only add think parameter for backends that support it (Grok, Ollama)
|
|
173
|
+
const backendLower = this.backendName.toLowerCase();
|
|
174
|
+
const supportsThink = backendLower === 'grok' ||
|
|
175
|
+
backendLower === 'ollama' ||
|
|
176
|
+
this.client.baseURL?.includes('x.ai');
|
|
177
|
+
if (supportsThink) {
|
|
178
|
+
requestPayload.think = false;
|
|
179
|
+
}
|
|
180
|
+
// Venice uses venice_parameters.disable_thinking
|
|
181
|
+
// DISABLED: Venice parameters may be causing API response issues
|
|
182
|
+
// if (backendLower === 'venice') {
|
|
183
|
+
// requestPayload.venice_parameters = {
|
|
184
|
+
// disable_thinking: false,
|
|
185
|
+
// include_venice_system_prompt: false
|
|
186
|
+
// };
|
|
187
|
+
// }
|
|
188
|
+
// Only add tool_choice for backends that support it (OpenAI, Grok, OpenRouter)
|
|
189
|
+
const supportsToolChoice = backendLower === 'grok' ||
|
|
190
|
+
backendLower === 'openai' ||
|
|
191
|
+
backendLower === 'openrouter' ||
|
|
192
|
+
this.client.baseURL?.includes('x.ai') ||
|
|
193
|
+
this.client.baseURL?.includes('openai.com') ||
|
|
194
|
+
this.client.baseURL?.includes('openrouter.ai');
|
|
195
|
+
if (this.supportsTools && supportsToolChoice && tools && tools.length > 0) {
|
|
196
|
+
requestPayload.tool_choice = "auto";
|
|
197
|
+
}
|
|
198
|
+
// Add search parameters if specified and using Grok API (x.ai)
|
|
199
|
+
if (searchOptions?.search_parameters && this.client.baseURL?.includes('x.ai')) {
|
|
200
|
+
requestPayload.search_parameters = searchOptions.search_parameters;
|
|
201
|
+
}
|
|
202
|
+
// Retry loop for 429 errors
|
|
203
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
204
|
+
try {
|
|
205
|
+
const stream = (await this.client.chat.completions.create(requestPayload, { signal: signal }));
|
|
206
|
+
for await (const chunk of stream) {
|
|
207
|
+
// Check if signal was aborted
|
|
208
|
+
if (signal?.aborted) {
|
|
209
|
+
// Try to clean up the stream
|
|
210
|
+
if (stream && typeof stream.controller?.abort === 'function') {
|
|
211
|
+
stream.controller.abort();
|
|
212
|
+
}
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
yield chunk;
|
|
216
|
+
}
|
|
217
|
+
return; // Success, exit the generator
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
// Check if model doesn't support tools
|
|
221
|
+
const isToolsNotSupported = error.status === 400 &&
|
|
222
|
+
error.message &&
|
|
223
|
+
error.message.toLowerCase().includes('does not support tools');
|
|
224
|
+
if (isToolsNotSupported && this.supportsTools) {
|
|
225
|
+
// Disable tools for this model and rebuild request without tools
|
|
226
|
+
this.supportsTools = false;
|
|
227
|
+
console.error(`Model does not support tools. Retrying without tools...`);
|
|
228
|
+
// Shutdown MCP servers since they won't be usable without tools
|
|
229
|
+
try {
|
|
230
|
+
const { getMCPManager } = await import('../grok/tools.js');
|
|
231
|
+
const mcpManager = getMCPManager();
|
|
232
|
+
await mcpManager.shutdown();
|
|
233
|
+
console.error(`MCP servers shut down.`);
|
|
234
|
+
}
|
|
235
|
+
catch (mcpError) {
|
|
236
|
+
console.warn("MCP shutdown failed:", mcpError);
|
|
237
|
+
}
|
|
238
|
+
// Rebuild request payload without tools
|
|
239
|
+
delete requestPayload.tools;
|
|
240
|
+
delete requestPayload.tool_choice;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
// Check if it's a 429 rate limit error
|
|
244
|
+
const is429 = error.status === 429 ||
|
|
245
|
+
error.code === 'rate_limit_exceeded' ||
|
|
246
|
+
(error.message && error.message.toLowerCase().includes('rate limit'));
|
|
247
|
+
if (is429 && attempt < maxRetries) {
|
|
248
|
+
console.error(`Rate limit hit (429). Retrying in ${retryDelay / 1000}s... (attempt ${attempt + 1}/${maxRetries})`);
|
|
249
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
// Log 500 errors with full request/response for debugging
|
|
253
|
+
if (error.status === 500) {
|
|
254
|
+
const { requestFile, responseFile } = await logApiError(requestPayload, error, { errorType: 'runtime-api-error' }, '500');
|
|
255
|
+
// Throw error with file references
|
|
256
|
+
throw new Error(`${this.backendName} API error: ${error.message}\nRequest logged to: ${requestFile}\nResponse logged to: ${responseFile}`);
|
|
257
|
+
}
|
|
258
|
+
// If not 429 or out of retries, throw the error
|
|
259
|
+
throw new Error(`${this.backendName} API error: ${error.message}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Should never reach here, but TypeScript needs it
|
|
263
|
+
throw new Error(`${this.backendName} API error: Max retries exceeded`);
|
|
264
|
+
}
|
|
265
|
+
async search(query, searchParameters) {
|
|
266
|
+
const searchMessage = {
|
|
267
|
+
role: "user",
|
|
268
|
+
content: query,
|
|
269
|
+
};
|
|
270
|
+
const searchOptions = {
|
|
271
|
+
search_parameters: searchParameters || { mode: "on" },
|
|
272
|
+
};
|
|
273
|
+
return this.chat([searchMessage], [], undefined, searchOptions);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/grok/client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,MAAM,IAAI,CAAC;AA8CpB,MAAM,OAAO,UAAU;IACb,MAAM,CAAS;IACf,YAAY,GAAW,kBAAkB,CAAC;IAC1C,gBAAgB,CAAS;IACzB,WAAW,CAAS;IACpB,aAAa,GAAY,IAAI,CAAC;IAEtC,YAAY,MAAc,EAAE,KAAc,EAAE,OAAgB,EAAE,WAAoB;QAChF,MAAM,YAAY,GA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AAc,EACd,KAAK,EACL,EAAE,SAAS,EAAE,mBAAmB,EAAE,EAClC,KAAK,CACN,CAAC;oBAEF,mCAAmC;oBACnC,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,eAAe,KAAK,CAAC,OAAO,wBAAwB,WAAW,yBAAyB,YAAY,EAAE,CAAC,CAAC;gBAC7I,CAAC;gBAED,gDAAgD;gBAChD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QAED,mDAAmD;QACnD,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,kCAAkC,CAAC,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,MAAM,CACV,KAAa,EACb,gBAAmC;QAEnC,MAAM,aAAa,GAAgB;YACjC,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,KAAK;SACf,CAAC;QAEF,MAAM,aAAa,GAAkB;YACnC,iBAAiB,EAAE,gBAAgB,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;SACtD,CAAC;QAEF,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IAClE,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GrokTool } from "./client.js";
|
|
2
|
+
import { MCPManager, MCPTool } from "../mcp/client.js";
|
|
3
|
+
export declare const GROK_TOOLS: GrokTool[];
|
|
4
|
+
export declare function getMCPManager(): MCPManager;
|
|
5
|
+
export declare function initializeMCPServers(debugLogFile?: string): Promise<void>;
|
|
6
|
+
export declare function convertMCPToolToGrokTool(mcpTool: MCPTool): GrokTool;
|
|
7
|
+
export declare function addMCPToolsToGrokTools(baseTools: GrokTool[]): Promise<GrokTool[]>;
|
|
8
|
+
export declare function getAllGrokTools(): Promise<GrokTool[]>;
|