@indiccoder/mentis-cli 1.0.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 (46) hide show
  1. package/README.md +90 -0
  2. package/console.log(tick) +0 -0
  3. package/debug_fs.js +12 -0
  4. package/dist/checkpoint/CheckpointManager.js +53 -0
  5. package/dist/config/ConfigManager.js +55 -0
  6. package/dist/context/ContextManager.js +55 -0
  7. package/dist/context/RepoMapper.js +112 -0
  8. package/dist/index.js +12 -0
  9. package/dist/llm/AnthropicClient.js +70 -0
  10. package/dist/llm/ModelInterface.js +2 -0
  11. package/dist/llm/OpenAIClient.js +58 -0
  12. package/dist/mcp/JsonRpcClient.js +117 -0
  13. package/dist/mcp/McpClient.js +59 -0
  14. package/dist/repl/PersistentShell.js +75 -0
  15. package/dist/repl/ReplManager.js +813 -0
  16. package/dist/tools/FileTools.js +100 -0
  17. package/dist/tools/GitTools.js +127 -0
  18. package/dist/tools/PersistentShellTool.js +30 -0
  19. package/dist/tools/SearchTools.js +83 -0
  20. package/dist/tools/Tool.js +2 -0
  21. package/dist/tools/WebSearchTool.js +60 -0
  22. package/dist/ui/UIManager.js +40 -0
  23. package/package.json +63 -0
  24. package/screenshot_1765779883482_9b30.png +0 -0
  25. package/scripts/test_features.ts +48 -0
  26. package/scripts/test_glm.ts +53 -0
  27. package/scripts/test_models.ts +38 -0
  28. package/src/checkpoint/CheckpointManager.ts +61 -0
  29. package/src/config/ConfigManager.ts +77 -0
  30. package/src/context/ContextManager.ts +63 -0
  31. package/src/context/RepoMapper.ts +119 -0
  32. package/src/index.ts +12 -0
  33. package/src/llm/ModelInterface.ts +47 -0
  34. package/src/llm/OpenAIClient.ts +64 -0
  35. package/src/mcp/JsonRpcClient.ts +103 -0
  36. package/src/mcp/McpClient.ts +75 -0
  37. package/src/repl/PersistentShell.ts +85 -0
  38. package/src/repl/ReplManager.ts +842 -0
  39. package/src/tools/FileTools.ts +89 -0
  40. package/src/tools/GitTools.ts +113 -0
  41. package/src/tools/PersistentShellTool.ts +32 -0
  42. package/src/tools/SearchTools.ts +74 -0
  43. package/src/tools/Tool.ts +6 -0
  44. package/src/tools/WebSearchTool.ts +63 -0
  45. package/src/ui/UIManager.ts +41 -0
  46. package/tsconfig.json +21 -0
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ListDirTool = exports.ReadFileTool = exports.WriteFileTool = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ class WriteFileTool {
10
+ constructor() {
11
+ this.name = 'write_file';
12
+ this.description = 'Write content to a file. Overwrites if exists. Creates directories if needed.';
13
+ this.parameters = {
14
+ type: 'object',
15
+ properties: {
16
+ filePath: {
17
+ type: 'string',
18
+ description: 'The path to the file to write',
19
+ },
20
+ content: {
21
+ type: 'string',
22
+ description: 'The content to write to the file',
23
+ },
24
+ },
25
+ required: ['filePath', 'content'],
26
+ };
27
+ }
28
+ async execute(args) {
29
+ try {
30
+ const absolutePath = path_1.default.resolve(args.filePath);
31
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(absolutePath));
32
+ await fs_extra_1.default.writeFile(absolutePath, args.content, 'utf-8');
33
+ return `Successfully wrote to ${args.filePath}`;
34
+ }
35
+ catch (error) {
36
+ return `Error writing file: ${error.message}`;
37
+ }
38
+ }
39
+ }
40
+ exports.WriteFileTool = WriteFileTool;
41
+ class ReadFileTool {
42
+ constructor() {
43
+ this.name = 'read_file';
44
+ this.description = 'Read content from a file.';
45
+ this.parameters = {
46
+ type: 'object',
47
+ properties: {
48
+ filePath: {
49
+ type: 'string',
50
+ description: 'The path to the file to read',
51
+ },
52
+ },
53
+ required: ['filePath'],
54
+ };
55
+ }
56
+ async execute(args) {
57
+ try {
58
+ const absolutePath = path_1.default.resolve(args.filePath);
59
+ if (!await fs_extra_1.default.pathExists(absolutePath)) {
60
+ return `Error: File not found at ${args.filePath}`;
61
+ }
62
+ const content = await fs_extra_1.default.readFile(absolutePath, 'utf-8');
63
+ return content;
64
+ }
65
+ catch (error) {
66
+ return `Error reading file: ${error.message}`;
67
+ }
68
+ }
69
+ }
70
+ exports.ReadFileTool = ReadFileTool;
71
+ class ListDirTool {
72
+ constructor() {
73
+ this.name = 'list_dir';
74
+ this.description = 'List files and directories in a path.';
75
+ this.parameters = {
76
+ type: 'object',
77
+ properties: {
78
+ path: {
79
+ type: 'string',
80
+ description: 'The directory path to list',
81
+ },
82
+ },
83
+ required: ['path'],
84
+ };
85
+ }
86
+ async execute(args) {
87
+ try {
88
+ const targetPath = path_1.default.resolve(args.path);
89
+ if (!await fs_extra_1.default.pathExists(targetPath)) {
90
+ return `Error: Directory not found at ${args.path}`;
91
+ }
92
+ const files = await fs_extra_1.default.readdir(targetPath);
93
+ return files.join('\n');
94
+ }
95
+ catch (error) {
96
+ return `Error listing directory: ${error.message}`;
97
+ }
98
+ }
99
+ }
100
+ exports.ListDirTool = ListDirTool;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GitPullTool = exports.GitPushTool = exports.GitCommitTool = exports.GitDiffTool = exports.GitStatusTool = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const util_1 = __importDefault(require("util"));
9
+ const execAsync = util_1.default.promisify(child_process_1.exec);
10
+ class GitStatusTool {
11
+ constructor() {
12
+ this.name = 'git_status';
13
+ this.description = 'Check the status of the git repository.';
14
+ this.parameters = {
15
+ type: 'object',
16
+ properties: {},
17
+ required: []
18
+ };
19
+ }
20
+ async execute(args) {
21
+ try {
22
+ const { stdout } = await execAsync('git status');
23
+ return stdout;
24
+ }
25
+ catch (error) {
26
+ return `Error running git status: ${error.message}`;
27
+ }
28
+ }
29
+ }
30
+ exports.GitStatusTool = GitStatusTool;
31
+ class GitDiffTool {
32
+ constructor() {
33
+ this.name = 'git_diff';
34
+ this.description = 'Show changes in the git repository.';
35
+ this.parameters = {
36
+ type: 'object',
37
+ properties: {
38
+ cached: {
39
+ type: 'boolean',
40
+ description: 'Show cached (staged) changes.'
41
+ }
42
+ },
43
+ required: []
44
+ };
45
+ }
46
+ async execute(args) {
47
+ try {
48
+ const cmd = args.cached ? 'git diff --cached' : 'git diff';
49
+ const { stdout } = await execAsync(cmd);
50
+ return stdout || 'No changes found.';
51
+ }
52
+ catch (error) {
53
+ return `Error running git diff: ${error.message}`;
54
+ }
55
+ }
56
+ }
57
+ exports.GitDiffTool = GitDiffTool;
58
+ class GitCommitTool {
59
+ constructor() {
60
+ this.name = 'git_commit';
61
+ this.description = 'Commit changes to the git repository.';
62
+ this.parameters = {
63
+ type: 'object',
64
+ properties: {
65
+ message: {
66
+ type: 'string',
67
+ description: 'The commit message.'
68
+ }
69
+ },
70
+ required: ['message']
71
+ };
72
+ }
73
+ async execute(args) {
74
+ try {
75
+ // Escape double quotes in message
76
+ const safeMessage = args.message.replace(/"/g, '\\"');
77
+ const { stdout } = await execAsync(`git commit -m "${safeMessage}"`);
78
+ return stdout;
79
+ }
80
+ catch (error) {
81
+ return `Error running git commit: ${error.message}`;
82
+ }
83
+ }
84
+ }
85
+ exports.GitCommitTool = GitCommitTool;
86
+ class GitPushTool {
87
+ constructor() {
88
+ this.name = 'git_push';
89
+ this.description = 'Push changes to the remote repository.';
90
+ this.parameters = {
91
+ type: 'object',
92
+ properties: {},
93
+ required: []
94
+ };
95
+ }
96
+ async execute(args) {
97
+ try {
98
+ const { stdout, stderr } = await execAsync('git push');
99
+ return stdout + (stderr ? `\nStderr: ${stderr}` : '');
100
+ }
101
+ catch (error) {
102
+ return `Error running git push: ${error.message}`;
103
+ }
104
+ }
105
+ }
106
+ exports.GitPushTool = GitPushTool;
107
+ class GitPullTool {
108
+ constructor() {
109
+ this.name = 'git_pull';
110
+ this.description = 'Pull changes from the remote repository.';
111
+ this.parameters = {
112
+ type: 'object',
113
+ properties: {},
114
+ required: []
115
+ };
116
+ }
117
+ async execute(args) {
118
+ try {
119
+ const { stdout } = await execAsync('git pull');
120
+ return stdout;
121
+ }
122
+ catch (error) {
123
+ return `Error running git pull: ${error.message}`;
124
+ }
125
+ }
126
+ }
127
+ exports.GitPullTool = GitPullTool;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PersistentShellTool = void 0;
4
+ class PersistentShellTool {
5
+ constructor(shell) {
6
+ this.name = 'run_shell';
7
+ this.description = 'Execute a shell command in a persistent session. Use this for running tests, build scripts, or git commands. State (env vars, cwd) is preserved.';
8
+ this.parameters = {
9
+ type: 'object',
10
+ properties: {
11
+ command: {
12
+ type: 'string',
13
+ description: 'The shell command to execute.'
14
+ }
15
+ },
16
+ required: ['command']
17
+ };
18
+ this.shell = shell;
19
+ }
20
+ async execute(args) {
21
+ try {
22
+ const output = await this.shell.execute(args.command);
23
+ return output || 'Command executed with no output.';
24
+ }
25
+ catch (error) {
26
+ return `Error executing command: ${error.message}`;
27
+ }
28
+ }
29
+ }
30
+ exports.PersistentShellTool = PersistentShellTool;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RunShellTool = exports.SearchFileTool = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const util_1 = __importDefault(require("util"));
9
+ const execAsync = util_1.default.promisify(child_process_1.exec);
10
+ class SearchFileTool {
11
+ constructor() {
12
+ this.name = 'search_files';
13
+ this.description = 'Search for a string pattern in files within the current directory recursively.';
14
+ this.parameters = {
15
+ type: 'object',
16
+ properties: {
17
+ query: {
18
+ type: 'string',
19
+ description: 'The string or regular expression to search for.'
20
+ },
21
+ path: {
22
+ type: 'string',
23
+ description: 'Optional path to limit search (default: .)'
24
+ }
25
+ },
26
+ required: ['query']
27
+ };
28
+ }
29
+ async execute(args) {
30
+ try {
31
+ const searchPath = args.path || '.';
32
+ // Use git grep if available as it respects .gitignore, otherwise fallback to grep or findstr
33
+ // For simplicity/cross-platform in this environment, let's try a heuristic:
34
+ // win32 usually has findstr, but git grep is better if installed.
35
+ // We'll assume standard 'grep -r' works in many envs or user has git bash.
36
+ // Actually, safer to use 'git grep -n "query"' if inside a repo.
37
+ const command = `git grep -n "${args.query}" ${searchPath}`;
38
+ const { stdout } = await execAsync(command);
39
+ return stdout || 'No matches found.';
40
+ }
41
+ catch (error) {
42
+ // grep returns exit code 1 if not found, distinct from error
43
+ if (error.code === 1)
44
+ return 'No matches found.';
45
+ return `Error searching: ${error.message}`;
46
+ }
47
+ }
48
+ }
49
+ exports.SearchFileTool = SearchFileTool;
50
+ class RunShellTool {
51
+ constructor() {
52
+ this.name = 'run_shell';
53
+ this.description = 'Execute a shell command. Use this for running tests, build scripts, or git commands.';
54
+ this.parameters = {
55
+ type: 'object',
56
+ properties: {
57
+ command: {
58
+ type: 'string',
59
+ description: 'The shell command to execute.'
60
+ }
61
+ },
62
+ required: ['command']
63
+ };
64
+ }
65
+ async execute(args) {
66
+ // Safety: We might want to block dangerous commands, but user approval is better.
67
+ // For now, relies on the ReplManager's safety/approval loop if we add it for this tool too.
68
+ // Or we just allow it since it's a CLI tool for devs.
69
+ try {
70
+ const { stdout, stderr } = await execAsync(args.command);
71
+ let result = '';
72
+ if (stdout)
73
+ result += `STDOUT:\n${stdout}\n`;
74
+ if (stderr)
75
+ result += `STDERR:\n${stderr}\n`;
76
+ return result || 'Command executed with no output.';
77
+ }
78
+ catch (error) {
79
+ return `Error executing command: ${error.message}\nSTDOUT: ${error.stdout}\nSTDERR: ${error.stderr}`;
80
+ }
81
+ }
82
+ }
83
+ exports.RunShellTool = RunShellTool;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WebSearchTool = void 0;
7
+ const duck_duck_scrape_1 = require("duck-duck-scrape");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ class WebSearchTool {
10
+ constructor() {
11
+ this.name = 'search_web';
12
+ this.description = 'Search the internet for documentation, libraries, or solutions to errors. Returns snippets of top results.';
13
+ this.parameters = {
14
+ type: 'object',
15
+ properties: {
16
+ query: {
17
+ type: 'string',
18
+ description: 'The search query.'
19
+ }
20
+ },
21
+ required: ['query']
22
+ };
23
+ }
24
+ async execute(args) {
25
+ try {
26
+ // Priority 1: Google Search
27
+ try {
28
+ // Dynamic import to avoid build issues if types are missing
29
+ const { search: googleSearch } = require('google-sr');
30
+ console.log(chalk_1.default.dim(` Searching Google for: "${args.query}"...`));
31
+ const googleResults = await googleSearch({
32
+ query: args.query,
33
+ limit: 5,
34
+ });
35
+ if (googleResults && googleResults.length > 0) {
36
+ const formatted = googleResults.map(r => `[${r.title}](${r.link})\n${r.description || 'No description.'}`).join('\n\n');
37
+ return `Top Google Results:\n\n${formatted}`;
38
+ }
39
+ }
40
+ catch (googleError) {
41
+ console.log(chalk_1.default.dim(` Google search failed (${googleError.message}), failing over to DuckDuckGo...`));
42
+ }
43
+ // Priority 2: DuckDuckGo Fallback
44
+ console.log(chalk_1.default.dim(` Searching DuckDuckGo for: "${args.query}"...`));
45
+ const ddgResults = await (0, duck_duck_scrape_1.search)(args.query, {
46
+ safeSearch: 0
47
+ });
48
+ if (!ddgResults.results || ddgResults.results.length === 0) {
49
+ return 'No results found.';
50
+ }
51
+ // Return top 5 results
52
+ const topResults = ddgResults.results.slice(0, 5).map(r => `[${r.title}](${r.url})\n${r.description || 'No description found.'}`).join('\n\n');
53
+ return `Top Search Results (via DDG):\n\n${topResults}`;
54
+ }
55
+ catch (error) {
56
+ return `Error searching web: ${error.message}`;
57
+ }
58
+ }
59
+ }
60
+ exports.WebSearchTool = WebSearchTool;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UIManager = void 0;
7
+ const figlet_1 = __importDefault(require("figlet"));
8
+ const gradient_string_1 = __importDefault(require("gradient-string"));
9
+ const boxen_1 = __importDefault(require("boxen"));
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ class UIManager {
12
+ static displayLogo() {
13
+ console.clear();
14
+ const logoText = figlet_1.default.textSync('MENTIS', {
15
+ font: 'ANSI Shadow', // Use a block-like font
16
+ horizontalLayout: 'default',
17
+ verticalLayout: 'default',
18
+ width: 100,
19
+ whitespaceBreak: true,
20
+ });
21
+ console.log(gradient_string_1.default.pastel.multiline(logoText));
22
+ console.log(chalk_1.default.gray(' v1.0.0 - AI Coding Agent'));
23
+ console.log('');
24
+ }
25
+ static displayWelcome() {
26
+ console.log((0, boxen_1.default)(`${chalk_1.default.bold('Welcome to Mentis-CLI')}\n\n` +
27
+ `โ€ข Type ${chalk_1.default.cyan('/help')} for commands.\n` +
28
+ `โ€ข Type ${chalk_1.default.cyan('/config')} to setup your model.\n` +
29
+ `โ€ข Start typing to chat with your agent.`, {
30
+ padding: 1,
31
+ margin: 1,
32
+ borderStyle: 'round',
33
+ borderColor: 'cyan',
34
+ }));
35
+ }
36
+ static printSeparator() {
37
+ console.log(chalk_1.default.gray('โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€'));
38
+ }
39
+ }
40
+ exports.UIManager = UIManager;
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@indiccoder/mentis-cli",
3
+ "version": "1.0.3",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "An Agentic, Multi-Model CLI Coding Assistant",
8
+ "main": "index.js",
9
+ "bin": {
10
+ "mentis": "./dist/index.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "start": "node dist/index.js",
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "keywords": [
18
+ "cli",
19
+ "ai",
20
+ "agent",
21
+ "gemini",
22
+ "ollama",
23
+ "mcp"
24
+ ],
25
+ "author": "CoderVLSI",
26
+ "license": "ISC",
27
+ "dependencies": {
28
+ "@anthropic-ai/sdk": "^0.71.2",
29
+ "@types/marked": "^5.0.2",
30
+ "@types/marked-terminal": "^6.1.1",
31
+ "@types/pdf-parse": "^1.1.5",
32
+ "@types/uuid": "^10.0.0",
33
+ "axios": "^1.13.2",
34
+ "boxen": "^8.0.1",
35
+ "chalk": "^5.6.2",
36
+ "cli-highlight": "^2.1.11",
37
+ "commander": "^14.0.2",
38
+ "dotenv": "^17.2.3",
39
+ "duck-duck-scrape": "^2.2.7",
40
+ "fast-glob": "^3.3.3",
41
+ "figlet": "^1.9.4",
42
+ "fs-extra": "^11.3.2",
43
+ "google-sr": "^6.0.0",
44
+ "gradient-string": "^3.0.0",
45
+ "inquirer": "^13.1.0",
46
+ "marked": "^17.0.1",
47
+ "marked-terminal": "^7.3.0",
48
+ "ora": "^9.0.0",
49
+ "pdf-parse": "^2.4.5",
50
+ "screenshot-desktop": "^1.15.3",
51
+ "uuid": "^13.0.0",
52
+ "vscode-ripgrep": "^1.13.2",
53
+ "xlsx": "^0.18.5"
54
+ },
55
+ "devDependencies": {
56
+ "@types/figlet": "^1.7.0",
57
+ "@types/fs-extra": "^11.0.4",
58
+ "@types/gradient-string": "^1.1.6",
59
+ "@types/inquirer": "^9.0.9",
60
+ "@types/node": "^25.0.2",
61
+ "typescript": "^5.9.3"
62
+ }
63
+ }
@@ -0,0 +1,48 @@
1
+ import { WebSearchTool } from '../src/tools/WebSearchTool';
2
+ import { RepoMapper } from '../src/context/RepoMapper';
3
+ import chalk from 'chalk';
4
+ import path from 'path';
5
+
6
+ async function runTests() {
7
+ console.log(chalk.cyan('๐Ÿงช Starting Feature Tests...\n'));
8
+
9
+ // --- Test 1: Web Search ---
10
+ console.log(chalk.yellow('1. Testing Web Search Tool...'));
11
+ const webTool = new WebSearchTool();
12
+ try {
13
+ const result = await webTool.execute({ query: 'nodejs latest version' });
14
+ if (result.includes('Node.js') || result.includes('v')) {
15
+ console.log(chalk.green('โœ… Web Search Success!'));
16
+ console.log(chalk.dim(result.substring(0, 150) + '...'));
17
+ } else {
18
+ console.log(chalk.red('โŒ Web Search returned unexpected results.'));
19
+ console.log(result);
20
+ }
21
+ } catch (e: any) {
22
+ console.log(chalk.red(`โŒ Web Search Failed: ${e.message}`));
23
+ }
24
+ console.log('');
25
+
26
+ // --- Test 2: Repo Mapper ---
27
+ console.log(chalk.yellow('2. Testing Repo Mapper...'));
28
+ try {
29
+ const mapper = new RepoMapper(process.cwd());
30
+ const tree = mapper.generateTree();
31
+
32
+ if (tree.includes('src/') && tree.includes('package.json')) {
33
+ console.log(chalk.green('โœ… Repo Map Success!'));
34
+ console.log(chalk.dim('Tree preview:'));
35
+ const preview = tree.split('\n').slice(0, 10).join('\n');
36
+ console.log(preview);
37
+ } else {
38
+ console.log(chalk.red('โŒ Repo Map expected src/ and package.json but got:'));
39
+ console.log(tree);
40
+ }
41
+ } catch (e: any) {
42
+ console.log(chalk.red(`โŒ Repo Map Failed: ${e.message}`));
43
+ }
44
+
45
+ console.log(chalk.cyan('\n๐Ÿ Tests Completed.'));
46
+ }
47
+
48
+ runTests();
@@ -0,0 +1,53 @@
1
+
2
+ import axios from 'axios';
3
+ import inquirer from 'inquirer';
4
+
5
+ async function testConnection() {
6
+ console.log("GLM-4.6 Connection Tester");
7
+
8
+ const apiKey = "d6127b23ffa74130bf6fbe3d98dab35a.o3cs6OuoHVuzn894";
9
+ console.log("Using provided key...");
10
+
11
+ const { endpoint } = await inquirer.prompt([{
12
+ type: 'list',
13
+ name: 'endpoint',
14
+ message: 'Select Endpoint to Test:',
15
+ choices: [
16
+ 'https://open.bigmodel.cn/api/paas/v4/chat/completions',
17
+ 'https://api.z.ai/api/paas/v4/chat/completions'
18
+ ]
19
+ }]);
20
+
21
+ const { model } = await inquirer.prompt([{
22
+ type: 'list',
23
+ name: 'model',
24
+ message: 'Select Model ID:',
25
+ choices: ['glm-4.6', 'glm-4', 'glm-4-plus']
26
+ }]);
27
+
28
+ console.log(`\nTesting ${model} @ ${endpoint} ...`);
29
+
30
+ try {
31
+ const response = await axios.post(
32
+ endpoint,
33
+ {
34
+ model: model,
35
+ messages: [{ role: "user", content: "Hello, are you working?" }]
36
+ },
37
+ {
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ 'Authorization': `Bearer ${apiKey}`
41
+ }
42
+ }
43
+ );
44
+ console.log("\nโœ… SUCCESS!");
45
+ console.log("Response:", response.data.choices[0].message.content);
46
+ } catch (error: any) {
47
+ console.log("\nโŒ FAILED");
48
+ console.log("Status:", error.response?.status);
49
+ console.log("Data:", JSON.stringify(error.response?.data, null, 2));
50
+ }
51
+ }
52
+
53
+ testConnection();
@@ -0,0 +1,38 @@
1
+
2
+ import axios from 'axios';
3
+
4
+ async function testConnection() {
5
+ const apiKey = "d6127b23ffa74130bf6fbe3d98dab35a.o3cs6OuoHVuzn894";
6
+ const endpoint = "https://open.bigmodel.cn/api/paas/v4/chat/completions";
7
+ const models = ['glm-4-plus', 'glm-4', 'glm-4-air'];
8
+
9
+ console.log("Testing models...");
10
+
11
+ for (const model of models) {
12
+ console.log(`\n--- Testing ${model} ---`);
13
+ try {
14
+ const response = await axios.post(
15
+ endpoint,
16
+ {
17
+ model: model,
18
+ messages: [{ role: "user", content: "Hi" }]
19
+ },
20
+ {
21
+ headers: {
22
+ 'Content-Type': 'application/json',
23
+ 'Authorization': `Bearer ${apiKey}`
24
+ }
25
+ }
26
+ );
27
+ console.log("โœ… SUCCESS!");
28
+ console.log("Response:", response.data.choices[0].message.content);
29
+ return; // Exit on first success
30
+ } catch (error: any) {
31
+ console.log("โŒ FAILED");
32
+ // console.log("Status:", error.response?.status);
33
+ console.log("Error:", error.response?.data?.error?.message || error.message);
34
+ }
35
+ }
36
+ }
37
+
38
+ testConnection();