@juspay/neurolink 1.6.0 → 1.10.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/CHANGELOG.md +200 -7
- package/README.md +101 -18
- package/dist/agent/direct-tools.d.ts +1203 -0
- package/dist/agent/direct-tools.js +387 -0
- package/dist/cli/commands/agent-generate.d.ts +2 -0
- package/dist/cli/commands/agent-generate.js +70 -0
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/cli/commands/config.js +326 -273
- package/dist/cli/commands/mcp.d.ts +2 -1
- package/dist/cli/commands/mcp.js +874 -146
- package/dist/cli/commands/ollama.d.ts +1 -1
- package/dist/cli/commands/ollama.js +153 -143
- package/dist/cli/index.js +687 -325
- package/dist/cli/utils/complete-setup.d.ts +19 -0
- package/dist/cli/utils/complete-setup.js +81 -0
- package/dist/cli/utils/env-manager.d.ts +44 -0
- package/dist/cli/utils/env-manager.js +226 -0
- package/dist/cli/utils/interactive-setup.d.ts +48 -0
- package/dist/cli/utils/interactive-setup.js +302 -0
- package/dist/core/dynamic-models.d.ts +208 -0
- package/dist/core/dynamic-models.js +250 -0
- package/dist/core/factory.d.ts +13 -6
- package/dist/core/factory.js +177 -62
- package/dist/core/types.d.ts +4 -2
- package/dist/core/types.js +4 -4
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/lib/agent/direct-tools.d.ts +1203 -0
- package/dist/lib/agent/direct-tools.js +387 -0
- package/dist/lib/core/dynamic-models.d.ts +208 -0
- package/dist/lib/core/dynamic-models.js +250 -0
- package/dist/lib/core/factory.d.ts +13 -6
- package/dist/lib/core/factory.js +177 -62
- package/dist/lib/core/types.d.ts +4 -2
- package/dist/lib/core/types.js +4 -4
- package/dist/lib/index.d.ts +16 -16
- package/dist/lib/index.js +16 -16
- package/dist/lib/mcp/auto-discovery.d.ts +120 -0
- package/dist/lib/mcp/auto-discovery.js +793 -0
- package/dist/lib/mcp/client.d.ts +66 -0
- package/dist/lib/mcp/client.js +245 -0
- package/dist/lib/mcp/config.d.ts +31 -0
- package/dist/lib/mcp/config.js +74 -0
- package/dist/lib/mcp/context-manager.d.ts +4 -4
- package/dist/lib/mcp/context-manager.js +24 -18
- package/dist/lib/mcp/factory.d.ts +28 -11
- package/dist/lib/mcp/factory.js +36 -29
- package/dist/lib/mcp/function-calling.d.ts +51 -0
- package/dist/lib/mcp/function-calling.js +510 -0
- package/dist/lib/mcp/index.d.ts +190 -0
- package/dist/lib/mcp/index.js +156 -0
- package/dist/lib/mcp/initialize-tools.d.ts +28 -0
- package/dist/lib/mcp/initialize-tools.js +209 -0
- package/dist/lib/mcp/initialize.d.ts +17 -0
- package/dist/lib/mcp/initialize.js +51 -0
- package/dist/lib/mcp/logging.d.ts +71 -0
- package/dist/lib/mcp/logging.js +183 -0
- package/dist/lib/mcp/manager.d.ts +67 -0
- package/dist/lib/mcp/manager.js +176 -0
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +417 -0
- package/dist/lib/mcp/orchestrator.d.ts +3 -3
- package/dist/lib/mcp/orchestrator.js +46 -43
- package/dist/lib/mcp/registry.d.ts +12 -4
- package/dist/lib/mcp/registry.js +64 -37
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +204 -65
- package/dist/lib/mcp/servers/ai-providers/ai-core-server.js +142 -102
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/lib/mcp/servers/ai-providers/ai-workflow-tools.js +197 -142
- package/dist/lib/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/lib/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/lib/mcp/tool-integration.d.ts +67 -0
- package/dist/lib/mcp/tool-integration.js +179 -0
- package/dist/lib/mcp/unified-registry.d.ts +269 -0
- package/dist/lib/mcp/unified-registry.js +1411 -0
- package/dist/lib/neurolink.d.ts +68 -6
- package/dist/lib/neurolink.js +304 -42
- package/dist/lib/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/lib/providers/agent-enhanced-provider.js +242 -0
- package/dist/lib/providers/amazonBedrock.d.ts +3 -3
- package/dist/lib/providers/amazonBedrock.js +54 -50
- package/dist/lib/providers/anthropic.d.ts +2 -2
- package/dist/lib/providers/anthropic.js +92 -84
- package/dist/lib/providers/azureOpenAI.d.ts +2 -2
- package/dist/lib/providers/azureOpenAI.js +97 -86
- package/dist/lib/providers/function-calling-provider.d.ts +70 -0
- package/dist/lib/providers/function-calling-provider.js +359 -0
- package/dist/lib/providers/googleAIStudio.d.ts +10 -5
- package/dist/lib/providers/googleAIStudio.js +60 -38
- package/dist/lib/providers/googleVertexAI.d.ts +3 -3
- package/dist/lib/providers/googleVertexAI.js +96 -86
- package/dist/lib/providers/huggingFace.d.ts +3 -3
- package/dist/lib/providers/huggingFace.js +70 -63
- package/dist/lib/providers/index.d.ts +11 -11
- package/dist/lib/providers/index.js +18 -18
- package/dist/lib/providers/mcp-provider.d.ts +62 -0
- package/dist/lib/providers/mcp-provider.js +183 -0
- package/dist/lib/providers/mistralAI.d.ts +3 -3
- package/dist/lib/providers/mistralAI.js +42 -36
- package/dist/lib/providers/ollama.d.ts +4 -4
- package/dist/lib/providers/ollama.js +128 -98
- package/dist/lib/providers/openAI.d.ts +7 -3
- package/dist/lib/providers/openAI.js +45 -33
- package/dist/lib/utils/logger.js +2 -2
- package/dist/lib/utils/providerUtils-fixed.d.ts +8 -0
- package/dist/lib/utils/providerUtils-fixed.js +75 -0
- package/dist/lib/utils/providerUtils.d.ts +8 -1
- package/dist/lib/utils/providerUtils.js +63 -32
- package/dist/mcp/auto-discovery.d.ts +120 -0
- package/dist/mcp/auto-discovery.js +794 -0
- package/dist/mcp/client.d.ts +66 -0
- package/dist/mcp/client.js +245 -0
- package/dist/mcp/config.d.ts +31 -0
- package/dist/mcp/config.js +74 -0
- package/dist/mcp/context-manager.d.ts +4 -4
- package/dist/mcp/context-manager.js +24 -18
- package/dist/mcp/factory.d.ts +28 -11
- package/dist/mcp/factory.js +36 -29
- package/dist/mcp/function-calling.d.ts +51 -0
- package/dist/mcp/function-calling.js +510 -0
- package/dist/mcp/index.d.ts +190 -0
- package/dist/mcp/index.js +156 -0
- package/dist/mcp/initialize-tools.d.ts +28 -0
- package/dist/mcp/initialize-tools.js +210 -0
- package/dist/mcp/initialize.d.ts +17 -0
- package/dist/mcp/initialize.js +51 -0
- package/dist/mcp/logging.d.ts +71 -0
- package/dist/mcp/logging.js +183 -0
- package/dist/mcp/manager.d.ts +67 -0
- package/dist/mcp/manager.js +176 -0
- package/dist/mcp/neurolink-mcp-client.d.ts +96 -0
- package/dist/mcp/neurolink-mcp-client.js +417 -0
- package/dist/mcp/orchestrator.d.ts +3 -3
- package/dist/mcp/orchestrator.js +46 -43
- package/dist/mcp/registry.d.ts +12 -4
- package/dist/mcp/registry.js +64 -37
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.d.ts +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +204 -65
- package/dist/mcp/servers/ai-providers/ai-core-server.js +142 -102
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.d.ts +6 -6
- package/dist/mcp/servers/ai-providers/ai-workflow-tools.js +197 -142
- package/dist/mcp/servers/utilities/utility-server.d.ts +8 -0
- package/dist/mcp/servers/utilities/utility-server.js +326 -0
- package/dist/mcp/tool-integration.d.ts +67 -0
- package/dist/mcp/tool-integration.js +179 -0
- package/dist/mcp/unified-registry.d.ts +269 -0
- package/dist/mcp/unified-registry.js +1411 -0
- package/dist/neurolink.d.ts +68 -6
- package/dist/neurolink.js +304 -42
- package/dist/providers/agent-enhanced-provider.d.ts +59 -0
- package/dist/providers/agent-enhanced-provider.js +242 -0
- package/dist/providers/amazonBedrock.d.ts +3 -3
- package/dist/providers/amazonBedrock.js +54 -50
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +92 -84
- package/dist/providers/azureOpenAI.d.ts +2 -2
- package/dist/providers/azureOpenAI.js +97 -86
- package/dist/providers/function-calling-provider.d.ts +70 -0
- package/dist/providers/function-calling-provider.js +359 -0
- package/dist/providers/googleAIStudio.d.ts +10 -5
- package/dist/providers/googleAIStudio.js +60 -38
- package/dist/providers/googleVertexAI.d.ts +3 -3
- package/dist/providers/googleVertexAI.js +96 -86
- package/dist/providers/huggingFace.d.ts +3 -3
- package/dist/providers/huggingFace.js +70 -63
- package/dist/providers/index.d.ts +11 -11
- package/dist/providers/index.js +18 -18
- package/dist/providers/mcp-provider.d.ts +62 -0
- package/dist/providers/mcp-provider.js +183 -0
- package/dist/providers/mistralAI.d.ts +3 -3
- package/dist/providers/mistralAI.js +42 -36
- package/dist/providers/ollama.d.ts +4 -4
- package/dist/providers/ollama.js +128 -98
- package/dist/providers/openAI.d.ts +7 -3
- package/dist/providers/openAI.js +45 -33
- package/dist/utils/logger.js +2 -2
- package/dist/utils/providerUtils-fixed.d.ts +8 -0
- package/dist/utils/providerUtils-fixed.js +75 -0
- package/dist/utils/providerUtils.d.ts +8 -1
- package/dist/utils/providerUtils.js +63 -32
- package/package.json +182 -160
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct Tool Definitions for NeuroLink CLI Agent
|
|
3
|
+
* Simple, reliable tools that work immediately with Vercel AI SDK
|
|
4
|
+
*/
|
|
5
|
+
import { tool } from "ai";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
/**
|
|
10
|
+
* Direct tool definitions that work immediately with Gemini/AI SDK
|
|
11
|
+
* These bypass MCP complexity and provide reliable agent functionality
|
|
12
|
+
*/
|
|
13
|
+
export const directAgentTools = {
|
|
14
|
+
getCurrentTime: tool({
|
|
15
|
+
description: "Get the current date and time",
|
|
16
|
+
parameters: z.object({
|
|
17
|
+
timezone: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('Timezone (e.g., "America/New_York", "Asia/Kolkata"). Defaults to local time.'),
|
|
21
|
+
}),
|
|
22
|
+
execute: async ({ timezone }) => {
|
|
23
|
+
try {
|
|
24
|
+
const now = new Date();
|
|
25
|
+
if (timezone) {
|
|
26
|
+
return {
|
|
27
|
+
success: true,
|
|
28
|
+
time: now.toLocaleString("en-US", { timeZone: timezone }),
|
|
29
|
+
timezone: timezone,
|
|
30
|
+
iso: now.toISOString(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
success: true,
|
|
35
|
+
time: now.toLocaleString(),
|
|
36
|
+
iso: now.toISOString(),
|
|
37
|
+
timestamp: now.getTime(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: error instanceof Error ? error.message : String(error),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
readFile: tool({
|
|
49
|
+
description: "Read the contents of a file from the filesystem",
|
|
50
|
+
parameters: z.object({
|
|
51
|
+
path: z.string().describe("File path to read (relative or absolute)"),
|
|
52
|
+
}),
|
|
53
|
+
execute: async ({ path: filePath }) => {
|
|
54
|
+
try {
|
|
55
|
+
// Security check - prevent reading outside current directory for relative paths
|
|
56
|
+
const resolvedPath = path.resolve(filePath);
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
if (!resolvedPath.startsWith(cwd) && !path.isAbsolute(filePath)) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
error: `Access denied: Cannot read files outside current directory`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const content = fs.readFileSync(resolvedPath, "utf-8");
|
|
65
|
+
const stats = fs.statSync(resolvedPath);
|
|
66
|
+
return {
|
|
67
|
+
success: true,
|
|
68
|
+
content,
|
|
69
|
+
size: stats.size,
|
|
70
|
+
path: resolvedPath,
|
|
71
|
+
lastModified: stats.mtime.toISOString(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return {
|
|
76
|
+
success: false,
|
|
77
|
+
error: error instanceof Error ? error.message : String(error),
|
|
78
|
+
path: filePath,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
listDirectory: tool({
|
|
84
|
+
description: "List files and directories in a specified directory",
|
|
85
|
+
parameters: z.object({
|
|
86
|
+
path: z
|
|
87
|
+
.string()
|
|
88
|
+
.describe("Directory path to list (relative or absolute)"),
|
|
89
|
+
includeHidden: z
|
|
90
|
+
.boolean()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe("Include hidden files (starting with .)")
|
|
93
|
+
.default(false),
|
|
94
|
+
}),
|
|
95
|
+
execute: async ({ path: dirPath, includeHidden }) => {
|
|
96
|
+
try {
|
|
97
|
+
const resolvedPath = path.resolve(dirPath);
|
|
98
|
+
const items = fs.readdirSync(resolvedPath);
|
|
99
|
+
const filteredItems = includeHidden
|
|
100
|
+
? items
|
|
101
|
+
: items.filter((item) => !item.startsWith("."));
|
|
102
|
+
const itemDetails = filteredItems.map((item) => {
|
|
103
|
+
const itemPath = path.join(resolvedPath, item);
|
|
104
|
+
const stats = fs.statSync(itemPath);
|
|
105
|
+
return {
|
|
106
|
+
name: item,
|
|
107
|
+
type: stats.isDirectory() ? "directory" : "file",
|
|
108
|
+
size: stats.isFile() ? stats.size : undefined,
|
|
109
|
+
lastModified: stats.mtime.toISOString(),
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
path: resolvedPath,
|
|
115
|
+
items: itemDetails,
|
|
116
|
+
count: itemDetails.length,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
error: error instanceof Error ? error.message : String(error),
|
|
123
|
+
path: dirPath,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
calculateMath: tool({
|
|
129
|
+
description: "Perform mathematical calculations safely",
|
|
130
|
+
parameters: z.object({
|
|
131
|
+
expression: z
|
|
132
|
+
.string()
|
|
133
|
+
.describe('Mathematical expression to evaluate (e.g., "2 + 2", "Math.sqrt(16)")'),
|
|
134
|
+
precision: z
|
|
135
|
+
.number()
|
|
136
|
+
.optional()
|
|
137
|
+
.describe("Number of decimal places for result")
|
|
138
|
+
.default(2),
|
|
139
|
+
}),
|
|
140
|
+
execute: async ({ expression, precision }) => {
|
|
141
|
+
try {
|
|
142
|
+
// Simple safe evaluation - only allow basic math operations
|
|
143
|
+
const sanitizedExpression = expression.replace(/[^0-9+\-*/().\s]/g, "");
|
|
144
|
+
if (sanitizedExpression !== expression) {
|
|
145
|
+
// Try Math functions for more complex operations
|
|
146
|
+
const allowedMathFunctions = [
|
|
147
|
+
"Math.abs",
|
|
148
|
+
"Math.ceil",
|
|
149
|
+
"Math.floor",
|
|
150
|
+
"Math.round",
|
|
151
|
+
"Math.sqrt",
|
|
152
|
+
"Math.pow",
|
|
153
|
+
"Math.sin",
|
|
154
|
+
"Math.cos",
|
|
155
|
+
"Math.tan",
|
|
156
|
+
"Math.log",
|
|
157
|
+
"Math.exp",
|
|
158
|
+
"Math.PI",
|
|
159
|
+
"Math.E",
|
|
160
|
+
];
|
|
161
|
+
let safeExpression = expression;
|
|
162
|
+
for (const func of allowedMathFunctions) {
|
|
163
|
+
safeExpression = safeExpression.replace(new RegExp(func, "g"), func);
|
|
164
|
+
}
|
|
165
|
+
// Remove any remaining non-safe characters except Math functions
|
|
166
|
+
const mathSafe = /^[0-9+\-*/().\s]|Math\.(abs|ceil|floor|round|sqrt|pow|sin|cos|tan|log|exp|PI|E)/g;
|
|
167
|
+
if (!safeExpression
|
|
168
|
+
.split("")
|
|
169
|
+
.every((char) => mathSafe.test(char) ||
|
|
170
|
+
char === "(" ||
|
|
171
|
+
char === ")" ||
|
|
172
|
+
char === "," ||
|
|
173
|
+
char === " ")) {
|
|
174
|
+
return {
|
|
175
|
+
success: false,
|
|
176
|
+
error: `Unsafe expression: Only basic math operations and Math functions are allowed`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// Use Function constructor for safe evaluation
|
|
181
|
+
const result = new Function(`'use strict'; return (${expression})`)();
|
|
182
|
+
const roundedResult = typeof result === "number"
|
|
183
|
+
? Number(result.toFixed(precision))
|
|
184
|
+
: result;
|
|
185
|
+
return {
|
|
186
|
+
success: true,
|
|
187
|
+
expression,
|
|
188
|
+
result: roundedResult,
|
|
189
|
+
type: typeof result,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
return {
|
|
194
|
+
success: false,
|
|
195
|
+
error: error instanceof Error ? error.message : String(error),
|
|
196
|
+
expression,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
writeFile: tool({
|
|
202
|
+
description: "Write content to a file (use with caution)",
|
|
203
|
+
parameters: z.object({
|
|
204
|
+
path: z.string().describe("File path to write to"),
|
|
205
|
+
content: z.string().describe("Content to write to the file"),
|
|
206
|
+
mode: z
|
|
207
|
+
.enum(["create", "overwrite", "append"])
|
|
208
|
+
.default("create")
|
|
209
|
+
.describe("Write mode"),
|
|
210
|
+
}),
|
|
211
|
+
execute: async ({ path: filePath, content, mode }) => {
|
|
212
|
+
try {
|
|
213
|
+
const resolvedPath = path.resolve(filePath);
|
|
214
|
+
const cwd = process.cwd();
|
|
215
|
+
// Security check
|
|
216
|
+
if (!resolvedPath.startsWith(cwd) && !path.isAbsolute(filePath)) {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
error: `Access denied: Cannot write files outside current directory`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
// Check if file exists for create mode
|
|
223
|
+
if (mode === "create" && fs.existsSync(resolvedPath)) {
|
|
224
|
+
return {
|
|
225
|
+
success: false,
|
|
226
|
+
error: `File already exists. Use 'overwrite' or 'append' mode to modify existing files.`,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
let finalContent = content;
|
|
230
|
+
if (mode === "append" && fs.existsSync(resolvedPath)) {
|
|
231
|
+
const existingContent = fs.readFileSync(resolvedPath, "utf-8");
|
|
232
|
+
finalContent = existingContent + content;
|
|
233
|
+
}
|
|
234
|
+
fs.writeFileSync(resolvedPath, finalContent, "utf-8");
|
|
235
|
+
const stats = fs.statSync(resolvedPath);
|
|
236
|
+
return {
|
|
237
|
+
success: true,
|
|
238
|
+
path: resolvedPath,
|
|
239
|
+
mode,
|
|
240
|
+
size: stats.size,
|
|
241
|
+
written: content.length,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
return {
|
|
246
|
+
success: false,
|
|
247
|
+
error: error instanceof Error ? error.message : String(error),
|
|
248
|
+
path: filePath,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
}),
|
|
253
|
+
searchFiles: tool({
|
|
254
|
+
description: "Search for files by name pattern in a directory",
|
|
255
|
+
parameters: z.object({
|
|
256
|
+
directory: z.string().describe("Directory to search in"),
|
|
257
|
+
pattern: z
|
|
258
|
+
.string()
|
|
259
|
+
.describe("File name pattern to search for (supports wildcards like *.js)"),
|
|
260
|
+
recursive: z
|
|
261
|
+
.boolean()
|
|
262
|
+
.optional()
|
|
263
|
+
.default(true)
|
|
264
|
+
.describe("Search recursively in subdirectories"),
|
|
265
|
+
}),
|
|
266
|
+
execute: async ({ directory, pattern, recursive }) => {
|
|
267
|
+
try {
|
|
268
|
+
const resolvedDir = path.resolve(directory);
|
|
269
|
+
if (!fs.existsSync(resolvedDir)) {
|
|
270
|
+
return {
|
|
271
|
+
success: false,
|
|
272
|
+
error: `Directory does not exist: ${resolvedDir}`,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
const matches = [];
|
|
276
|
+
const searchDir = (dir, depth = 0) => {
|
|
277
|
+
if (!recursive && depth > 0) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const items = fs.readdirSync(dir);
|
|
281
|
+
for (const item of items) {
|
|
282
|
+
const itemPath = path.join(dir, item);
|
|
283
|
+
const stats = fs.statSync(itemPath);
|
|
284
|
+
if (stats.isDirectory()) {
|
|
285
|
+
if (recursive && depth < 10) {
|
|
286
|
+
// Prevent infinite recursion
|
|
287
|
+
searchDir(itemPath, depth + 1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else if (stats.isFile()) {
|
|
291
|
+
// Simple pattern matching (convert * to regex)
|
|
292
|
+
const regexPattern = pattern
|
|
293
|
+
.replace(/\*/g, ".*")
|
|
294
|
+
.replace(/\?/g, ".");
|
|
295
|
+
const regex = new RegExp(`^${regexPattern}$`, "i");
|
|
296
|
+
if (regex.test(item)) {
|
|
297
|
+
matches.push({
|
|
298
|
+
name: item,
|
|
299
|
+
path: itemPath,
|
|
300
|
+
size: stats.size,
|
|
301
|
+
lastModified: stats.mtime.toISOString(),
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
searchDir(resolvedDir);
|
|
308
|
+
return {
|
|
309
|
+
success: true,
|
|
310
|
+
directory: resolvedDir,
|
|
311
|
+
pattern,
|
|
312
|
+
matches,
|
|
313
|
+
count: matches.length,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
return {
|
|
318
|
+
success: false,
|
|
319
|
+
error: error instanceof Error ? error.message : String(error),
|
|
320
|
+
directory,
|
|
321
|
+
pattern,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
}),
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Get a subset of tools for specific use cases
|
|
329
|
+
*/
|
|
330
|
+
export function getToolsForCategory(category = "all") {
|
|
331
|
+
switch (category) {
|
|
332
|
+
case "basic":
|
|
333
|
+
return {
|
|
334
|
+
getCurrentTime: directAgentTools.getCurrentTime,
|
|
335
|
+
calculateMath: directAgentTools.calculateMath,
|
|
336
|
+
};
|
|
337
|
+
case "filesystem":
|
|
338
|
+
return {
|
|
339
|
+
readFile: directAgentTools.readFile,
|
|
340
|
+
listDirectory: directAgentTools.listDirectory,
|
|
341
|
+
writeFile: directAgentTools.writeFile,
|
|
342
|
+
searchFiles: directAgentTools.searchFiles,
|
|
343
|
+
};
|
|
344
|
+
case "utility":
|
|
345
|
+
return {
|
|
346
|
+
getCurrentTime: directAgentTools.getCurrentTime,
|
|
347
|
+
calculateMath: directAgentTools.calculateMath,
|
|
348
|
+
listDirectory: directAgentTools.listDirectory,
|
|
349
|
+
};
|
|
350
|
+
case "all":
|
|
351
|
+
default:
|
|
352
|
+
return directAgentTools;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get tool names for validation
|
|
357
|
+
*/
|
|
358
|
+
export function getAvailableToolNames() {
|
|
359
|
+
return Object.keys(directAgentTools);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Validate that all tools have proper structure
|
|
363
|
+
*/
|
|
364
|
+
export function validateToolStructure() {
|
|
365
|
+
try {
|
|
366
|
+
for (const [name, tool] of Object.entries(directAgentTools)) {
|
|
367
|
+
if (!tool.description || typeof tool.description !== "string") {
|
|
368
|
+
console.error(`❌ Tool ${name} missing description`);
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
if (!tool.parameters) {
|
|
372
|
+
console.error(`❌ Tool ${name} missing parameters`);
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
if (!tool.execute || typeof tool.execute !== "function") {
|
|
376
|
+
console.error(`❌ Tool ${name} missing execute function`);
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
console.log("✅ All tools have valid structure");
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
console.error("❌ Tool validation failed:", error);
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AgentEnhancedProvider } from "../../lib/providers/agent-enhanced-provider.js";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
export const agentGenerateCommand = {
|
|
5
|
+
command: "agent-generate <prompt>",
|
|
6
|
+
describe: "Generate text with agent capabilities (tool calling)",
|
|
7
|
+
builder: (yargs) => yargs
|
|
8
|
+
.positional("prompt", {
|
|
9
|
+
describe: "The prompt for the agent",
|
|
10
|
+
type: "string",
|
|
11
|
+
})
|
|
12
|
+
.option("provider", {
|
|
13
|
+
alias: "p",
|
|
14
|
+
describe: "The AI provider to use",
|
|
15
|
+
type: "string",
|
|
16
|
+
choices: ["google-ai", "openai", "anthropic"],
|
|
17
|
+
default: "google-ai",
|
|
18
|
+
})
|
|
19
|
+
.option("model", {
|
|
20
|
+
alias: "m",
|
|
21
|
+
describe: "The model to use",
|
|
22
|
+
type: "string",
|
|
23
|
+
})
|
|
24
|
+
.option("toolCategory", {
|
|
25
|
+
alias: "t",
|
|
26
|
+
describe: "The category of tools to use",
|
|
27
|
+
type: "string",
|
|
28
|
+
choices: ["basic", "filesystem", "utility", "all"],
|
|
29
|
+
default: "all",
|
|
30
|
+
}),
|
|
31
|
+
handler: async (argv) => {
|
|
32
|
+
const { prompt, provider, model, toolCategory } = argv;
|
|
33
|
+
const spinner = ora(`Generating response with ${provider} agent...`).start();
|
|
34
|
+
try {
|
|
35
|
+
const agentProvider = new AgentEnhancedProvider({
|
|
36
|
+
provider,
|
|
37
|
+
model,
|
|
38
|
+
toolCategory,
|
|
39
|
+
});
|
|
40
|
+
const result = await agentProvider.generateText(prompt);
|
|
41
|
+
if (result) {
|
|
42
|
+
spinner.succeed("Response generated successfully!");
|
|
43
|
+
console.log(chalk.green("\nAI Response:"));
|
|
44
|
+
console.log(result.text);
|
|
45
|
+
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
46
|
+
console.log(chalk.yellow("\nTools Called:"));
|
|
47
|
+
for (const call of result.toolCalls) {
|
|
48
|
+
console.log(`- ${call.toolName}`);
|
|
49
|
+
console.log(` Args: ${JSON.stringify(call.args)}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (result.toolResults && result.toolResults.length > 0) {
|
|
53
|
+
console.log(chalk.blue("\nTool Results:"));
|
|
54
|
+
for (const toolResult of result.toolResults) {
|
|
55
|
+
console.log(`- ${toolResult.toolName}`);
|
|
56
|
+
console.log(` Result: ${JSON.stringify(toolResult.result)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
spinner.fail("Failed to generate response.");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
spinner.fail("An error occurred during generation.");
|
|
66
|
+
console.error(chalk.red(error));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Enhanced configuration system with interactive setup,
|
|
6
6
|
* multi-profile support, and smart validation.
|
|
7
7
|
*/
|
|
8
|
-
import { z } from
|
|
8
|
+
import { z } from "zod";
|
|
9
9
|
declare const ConfigSchema: z.ZodObject<{
|
|
10
10
|
defaultProvider: z.ZodDefault<z.ZodEnum<["auto", "openai", "bedrock", "vertex", "anthropic", "azure", "google-ai", "huggingface", "ollama", "mistral"]>>;
|
|
11
11
|
providers: z.ZodDefault<z.ZodObject<{
|
|
@@ -92,7 +92,7 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
92
92
|
endpoint?: string | undefined;
|
|
93
93
|
deploymentId?: string | undefined;
|
|
94
94
|
}>>;
|
|
95
|
-
|
|
95
|
+
"google-ai": z.ZodOptional<z.ZodObject<{
|
|
96
96
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
97
97
|
model: z.ZodDefault<z.ZodString>;
|
|
98
98
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -167,7 +167,7 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
167
167
|
endpoint?: string | undefined;
|
|
168
168
|
deploymentId?: string | undefined;
|
|
169
169
|
} | undefined;
|
|
170
|
-
|
|
170
|
+
"google-ai"?: {
|
|
171
171
|
model: string;
|
|
172
172
|
apiKey?: string | undefined;
|
|
173
173
|
} | undefined;
|
|
@@ -216,7 +216,7 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
216
216
|
endpoint?: string | undefined;
|
|
217
217
|
deploymentId?: string | undefined;
|
|
218
218
|
} | undefined;
|
|
219
|
-
|
|
219
|
+
"google-ai"?: {
|
|
220
220
|
model?: string | undefined;
|
|
221
221
|
apiKey?: string | undefined;
|
|
222
222
|
} | undefined;
|
|
@@ -291,7 +291,7 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
291
291
|
endpoint?: string | undefined;
|
|
292
292
|
deploymentId?: string | undefined;
|
|
293
293
|
} | undefined;
|
|
294
|
-
|
|
294
|
+
"google-ai"?: {
|
|
295
295
|
model: string;
|
|
296
296
|
apiKey?: string | undefined;
|
|
297
297
|
} | undefined;
|
|
@@ -352,7 +352,7 @@ declare const ConfigSchema: z.ZodObject<{
|
|
|
352
352
|
endpoint?: string | undefined;
|
|
353
353
|
deploymentId?: string | undefined;
|
|
354
354
|
} | undefined;
|
|
355
|
-
|
|
355
|
+
"google-ai"?: {
|
|
356
356
|
model?: string | undefined;
|
|
357
357
|
apiKey?: string | undefined;
|
|
358
358
|
} | undefined;
|