matex-cli 1.0.1 ā 1.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/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +2 -5
- package/dist/api/client.js.map +1 -1
- package/dist/commands/code.d.ts +3 -0
- package/dist/commands/code.d.ts.map +1 -0
- package/dist/commands/code.js +88 -0
- package/dist/commands/code.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +94 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/index.js +57 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/client.ts +2 -6
- package/src/commands/code.ts +92 -0
- package/src/commands/dev.ts +102 -0
- package/src/index.ts +60 -10
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IACxB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,cAAc;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,MAAmE;IAcxG;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IACxB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,cAAc;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,MAAmE;IAcxG;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBjD;;OAEG;YACW,uBAAuB;IA+BrC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAKjC;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CAY3C"}
|
package/dist/api/client.js
CHANGED
|
@@ -27,11 +27,8 @@ class MatexAPIClient {
|
|
|
27
27
|
...request,
|
|
28
28
|
uid: 'cli-user', // Placeholder, backend uses API key for auth
|
|
29
29
|
});
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
return this.handleStreamingResponse(response.data);
|
|
33
|
-
}
|
|
34
|
-
return response.data;
|
|
30
|
+
// Backend always returns SSE format, parse it
|
|
31
|
+
return this.handleStreamingResponse(response.data);
|
|
35
32
|
}
|
|
36
33
|
catch (error) {
|
|
37
34
|
if (error.response) {
|
package/dist/api/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":";;;;;;AAA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AI,MAAM,CAAC,OAAO,EAAE,CAAC;wBACjB,YAAY,IAAI,MAAM,CAAC,OAAO,CAAC;oBACnC,CAAC;oBACD,8CAA8C;gBAClD,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,sCAAsC;gBAC1C,CAAC;YACL,CAAC;QACL,CAAC;QAED,OAAO,YAAY,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW;QACb,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAChE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAChB,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,IAAI,CAAC;gBACZ,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;gBAC7C,KAAK,EAAE,YAAY;gBACnB,UAAU,EAAE,EAAE;aACjB,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ;AAnGD,wCAmGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/commands/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,eAAO,MAAM,WAAW,SAqFlB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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.codeCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const config_1 = require("../utils/config");
|
|
10
|
+
const client_1 = require("../api/client");
|
|
11
|
+
const spinner_1 = require("../utils/spinner");
|
|
12
|
+
exports.codeCommand = new commander_1.Command('code')
|
|
13
|
+
.description('Generate code with MATEXCodex (optimized for coding)')
|
|
14
|
+
.argument('<prompt>', 'What code do you need?')
|
|
15
|
+
.option('-o, --output <file>', 'Save output to file')
|
|
16
|
+
.option('-l, --language <lang>', 'Programming language (auto-detected if not specified)')
|
|
17
|
+
.option('-t, --temperature <number>', 'Temperature (0-1)', '0.3')
|
|
18
|
+
.option('--max-tokens <number>', 'Maximum tokens in response', '8000')
|
|
19
|
+
.action(async (prompt, options) => {
|
|
20
|
+
try {
|
|
21
|
+
// Check for API key
|
|
22
|
+
const apiKey = config_1.configManager.getAPIKey();
|
|
23
|
+
if (!apiKey) {
|
|
24
|
+
console.error(chalk_1.default.red('ā No API key configured.'));
|
|
25
|
+
console.log(chalk_1.default.yellow('Run: matex config set-key <your-api-key>'));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
// Create API client
|
|
29
|
+
const client = new client_1.MatexAPIClient(apiKey, config_1.configManager.getBaseURL());
|
|
30
|
+
// Enhance prompt for code generation
|
|
31
|
+
let enhancedPrompt = prompt;
|
|
32
|
+
if (options.language) {
|
|
33
|
+
enhancedPrompt = `Generate ${options.language} code: ${prompt}`;
|
|
34
|
+
}
|
|
35
|
+
// Show thinking indicator
|
|
36
|
+
spinner_1.spinner.start('Generating code with MATEXCodex...');
|
|
37
|
+
// Send request (always use matexcodex for code command)
|
|
38
|
+
const response = await client.chat({
|
|
39
|
+
messages: [
|
|
40
|
+
{ role: 'system', content: 'You are MATEXCodex, an expert coding assistant. Generate clean, production-ready code with comments and best practices. Always include complete, working code.' },
|
|
41
|
+
{ role: 'user', content: enhancedPrompt }
|
|
42
|
+
],
|
|
43
|
+
model: 'matexcodex',
|
|
44
|
+
temperature: parseFloat(options.temperature),
|
|
45
|
+
max_tokens: parseInt(options.maxTokens),
|
|
46
|
+
stream: false,
|
|
47
|
+
});
|
|
48
|
+
spinner_1.spinner.succeed('Code generated!');
|
|
49
|
+
// Display response
|
|
50
|
+
console.log(chalk_1.default.cyan('\nš» MATEXCodex:\n'));
|
|
51
|
+
console.log(chalk_1.default.white(response));
|
|
52
|
+
console.log();
|
|
53
|
+
// Save to file if requested
|
|
54
|
+
if (options.output) {
|
|
55
|
+
const fs = require('fs');
|
|
56
|
+
const path = require('path');
|
|
57
|
+
// Ensure directory exists
|
|
58
|
+
const dir = path.dirname(options.output);
|
|
59
|
+
if (!fs.existsSync(dir) && dir !== '.') {
|
|
60
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
// Extract code from response (remove markdown if present)
|
|
63
|
+
let codeContent = response;
|
|
64
|
+
const codeBlockMatch = response.match(/```[\w]*\n([\s\S]*?)```/);
|
|
65
|
+
if (codeBlockMatch) {
|
|
66
|
+
codeContent = codeBlockMatch[1];
|
|
67
|
+
}
|
|
68
|
+
fs.writeFileSync(options.output, codeContent.trim());
|
|
69
|
+
console.log(chalk_1.default.green(`ā
Code saved to: ${options.output}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
spinner_1.spinner.fail('Code generation failed');
|
|
74
|
+
if (error.message.includes('403')) {
|
|
75
|
+
console.error(chalk_1.default.red('\nā Invalid or revoked API key.'));
|
|
76
|
+
console.log(chalk_1.default.yellow('Please check your API key or generate a new one from the MATEX AI platform.'));
|
|
77
|
+
}
|
|
78
|
+
else if (error.message.includes('429')) {
|
|
79
|
+
console.error(chalk_1.default.red('\nā Rate limit exceeded.'));
|
|
80
|
+
console.log(chalk_1.default.yellow('Please wait a moment before trying again.'));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.error(chalk_1.default.red(`\nā Error: ${error.message}`));
|
|
84
|
+
}
|
|
85
|
+
process.exit(1);
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@@
|
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,UAAU,SA8FjB,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
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.devCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const config_1 = require("../utils/config");
|
|
11
|
+
const client_1 = require("../api/client");
|
|
12
|
+
const spinner_1 = require("../utils/spinner");
|
|
13
|
+
exports.devCommand = new commander_1.Command('dev')
|
|
14
|
+
.description('Start interactive development session with MATEXCodex')
|
|
15
|
+
.option('-m, --model <model>', 'AI model to use', 'matexcodex')
|
|
16
|
+
.action(async (options) => {
|
|
17
|
+
try {
|
|
18
|
+
// Check for API key
|
|
19
|
+
const apiKey = config_1.configManager.getAPIKey();
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
console.error(chalk_1.default.red('ā No API key configured.'));
|
|
22
|
+
console.log(chalk_1.default.yellow('Run: matex config set-key <your-api-key>'));
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
// Create API client
|
|
26
|
+
const client = new client_1.MatexAPIClient(apiKey, config_1.configManager.getBaseURL());
|
|
27
|
+
// Welcome message
|
|
28
|
+
console.log(chalk_1.default.cyan.bold('\nš MATEX Development Session'));
|
|
29
|
+
console.log(chalk_1.default.gray('ā'.repeat(50)));
|
|
30
|
+
console.log(chalk_1.default.white(`Model: ${chalk_1.default.cyan(options.model)}`));
|
|
31
|
+
console.log(chalk_1.default.gray('Type your requests, or "exit" to quit\n'));
|
|
32
|
+
// Conversation history
|
|
33
|
+
const messages = [
|
|
34
|
+
{
|
|
35
|
+
role: 'system',
|
|
36
|
+
content: 'You are MATEXCodex, an expert software development assistant. Help the user build their application step by step. Provide complete, production-ready code with explanations. Be concise but thorough.'
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
// Interactive loop
|
|
40
|
+
let continueChat = true;
|
|
41
|
+
while (continueChat) {
|
|
42
|
+
// Get user input
|
|
43
|
+
const { userInput } = await inquirer_1.default.prompt([
|
|
44
|
+
{
|
|
45
|
+
type: 'input',
|
|
46
|
+
name: 'userInput',
|
|
47
|
+
message: chalk_1.default.cyan('You:'),
|
|
48
|
+
prefix: ''
|
|
49
|
+
}
|
|
50
|
+
]);
|
|
51
|
+
// Check for exit
|
|
52
|
+
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
|
53
|
+
console.log(chalk_1.default.yellow('\nš Ending development session. Happy coding!\n'));
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
// Skip empty input
|
|
57
|
+
if (!userInput.trim()) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
// Add user message to history
|
|
61
|
+
messages.push({ role: 'user', content: userInput });
|
|
62
|
+
// Show thinking indicator
|
|
63
|
+
spinner_1.spinner.start('Thinking...');
|
|
64
|
+
try {
|
|
65
|
+
// Send request
|
|
66
|
+
const response = await client.chat({
|
|
67
|
+
messages,
|
|
68
|
+
model: options.model,
|
|
69
|
+
temperature: 0.3,
|
|
70
|
+
max_tokens: 8000,
|
|
71
|
+
stream: false,
|
|
72
|
+
});
|
|
73
|
+
spinner_1.spinner.stop();
|
|
74
|
+
// Add assistant response to history
|
|
75
|
+
messages.push({ role: 'assistant', content: response });
|
|
76
|
+
// Display response
|
|
77
|
+
console.log(chalk_1.default.green('\nMATEXCodex:'));
|
|
78
|
+
console.log(chalk_1.default.white(response));
|
|
79
|
+
console.log();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
spinner_1.spinner.fail('Request failed');
|
|
83
|
+
console.error(chalk_1.default.red(`Error: ${error.message}\n`));
|
|
84
|
+
// Remove the failed user message
|
|
85
|
+
messages.pop();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error(chalk_1.default.red(`\nā Error: ${error.message}`));
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,kDAA0B;AAC1B,wDAAgC;AAChC,4CAAgD;AAChD,0CAA4D;AAC5D,8CAA2C;AAE9B,QAAA,UAAU,GAAG,IAAI,mBAAO,CAAC,KAAK,CAAC;KACvC,WAAW,CAAC,uDAAuD,CAAC;KACpE,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,CAAC;KAC9D,MAAM,CAAC,KAAK,EAAE,OAAY,EAAE,EAAE;IAC3B,IAAI,CAAC;QACD,oBAAoB;QACpB,MAAM,MAAM,GAAG,sBAAa,CAAC,SAAS,EAAE,CAAC;QACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC,CAAC;YACrD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,0CAA0C,CAAC,CAAC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QAED,oBAAoB;QACpB,MAAM,MAAM,GAAG,IAAI,uBAAc,CAAC,MAAM,EAAE,sBAAa,CAAC,UAAU,EAAE,CAAC,CAAC;QAEtE,kBAAkB;QAClB,OAA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js
CHANGED
|
@@ -10,11 +10,16 @@ const config_1 = require("./commands/config");
|
|
|
10
10
|
const ask_1 = require("./commands/ask");
|
|
11
11
|
const chat_1 = require("./commands/chat");
|
|
12
12
|
const models_1 = require("./commands/models");
|
|
13
|
+
const code_1 = require("./commands/code");
|
|
14
|
+
const dev_1 = require("./commands/dev");
|
|
15
|
+
const config_2 = require("./utils/config");
|
|
16
|
+
const client_1 = require("./api/client");
|
|
17
|
+
const spinner_1 = require("./utils/spinner");
|
|
13
18
|
const program = new commander_1.Command();
|
|
14
19
|
program
|
|
15
20
|
.name('matex')
|
|
16
21
|
.description('Official CLI tool for MATEX AI - Access powerful AI models from your terminal')
|
|
17
|
-
.version('1.0.
|
|
22
|
+
.version('1.0.2');
|
|
18
23
|
// ASCII Art Banner
|
|
19
24
|
const banner = `
|
|
20
25
|
${chalk_1.default.cyan('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā')}
|
|
@@ -26,9 +31,9 @@ program.on('--help', () => {
|
|
|
26
31
|
console.log(banner);
|
|
27
32
|
console.log(chalk_1.default.gray('\nExamples:'));
|
|
28
33
|
console.log(chalk_1.default.white(' $ matex config set-key sk-matex-xxxxx'));
|
|
29
|
-
console.log(chalk_1.default.white(' $ matex
|
|
30
|
-
console.log(chalk_1.default.white(' $ matex
|
|
31
|
-
console.log(chalk_1.default.white(' $ matex
|
|
34
|
+
console.log(chalk_1.default.white(' $ matex code "Create a React login component"'));
|
|
35
|
+
console.log(chalk_1.default.white(' $ matex dev'));
|
|
36
|
+
console.log(chalk_1.default.white(' $ matex "build a todo app" # Direct input'));
|
|
32
37
|
console.log();
|
|
33
38
|
console.log(chalk_1.default.gray('Get your API key from: ') + chalk_1.default.cyan('https://matexai.space/platform'));
|
|
34
39
|
console.log();
|
|
@@ -38,11 +43,53 @@ program.addCommand(config_1.configCommand);
|
|
|
38
43
|
program.addCommand(ask_1.askCommand);
|
|
39
44
|
program.addCommand(chat_1.chatCommand);
|
|
40
45
|
program.addCommand(models_1.modelsCommand);
|
|
41
|
-
|
|
42
|
-
program.
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
program.addCommand(code_1.codeCommand);
|
|
47
|
+
program.addCommand(dev_1.devCommand);
|
|
48
|
+
// Handle direct input (no subcommand)
|
|
49
|
+
const args = process.argv.slice(2);
|
|
50
|
+
const knownCommands = ['config', 'ask', 'chat', 'models', 'code', 'dev', 'help', '--help', '-h', '--version', '-V'];
|
|
51
|
+
if (args.length > 0 && !args[0].startsWith('-') && !knownCommands.includes(args[0])) {
|
|
52
|
+
// Direct input mode - treat as code generation
|
|
53
|
+
const prompt = args.join(' ');
|
|
54
|
+
(async () => {
|
|
55
|
+
try {
|
|
56
|
+
const apiKey = config_2.configManager.getAPIKey();
|
|
57
|
+
if (!apiKey) {
|
|
58
|
+
console.error(chalk_1.default.red('ā No API key configured.'));
|
|
59
|
+
console.log(chalk_1.default.yellow('Run: matex config set-key <your-api-key>'));
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const client = new client_1.MatexAPIClient(apiKey, config_2.configManager.getBaseURL());
|
|
63
|
+
spinner_1.spinner.start('Generating with MATEXCodex...');
|
|
64
|
+
const response = await client.chat({
|
|
65
|
+
messages: [
|
|
66
|
+
{ role: 'system', content: 'You are MATEXCodex, an expert coding assistant. Provide complete, production-ready code with explanations.' },
|
|
67
|
+
{ role: 'user', content: prompt }
|
|
68
|
+
],
|
|
69
|
+
model: 'matexcodex',
|
|
70
|
+
temperature: 0.3,
|
|
71
|
+
max_tokens: 8000,
|
|
72
|
+
stream: false,
|
|
73
|
+
});
|
|
74
|
+
spinner_1.spinner.succeed('Done!');
|
|
75
|
+
console.log(chalk_1.default.cyan('\nš» MATEXCodex:\n'));
|
|
76
|
+
console.log(chalk_1.default.white(response));
|
|
77
|
+
console.log();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
spinner_1.spinner.fail('Failed');
|
|
81
|
+
console.error(chalk_1.default.red(`\nā ${error.message}`));
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// Parse arguments normally
|
|
88
|
+
program.parse(process.argv);
|
|
89
|
+
// Show help if no command provided
|
|
90
|
+
if (!args.length) {
|
|
91
|
+
console.log(banner);
|
|
92
|
+
program.outputHelp();
|
|
93
|
+
}
|
|
47
94
|
}
|
|
48
95
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAkD;AAClD,wCAA4C;AAC5C,0CAA8C;AAC9C,8CAAkD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAkD;AAClD,wCAA4C;AAC5C,0CAA8C;AAC9C,8CAAkD;AAClD,0CAA8C;AAC9C,wCAA4C;AAC5C,2CAA+C;AAC/C,yCAA8C;AAC9C,6CAA0C;AAE1C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACF,IAAI,CAAC,OAAO,CAAC;KACb,WAAW,CAAC,+EAA+E,CAAC;KAC5F,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,mBAAmB;AACnB,MAAM,MAAM,GAAG;EACb,eAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC;EACvD,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,eAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,eAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC;EAC7G,eAAK,CAAC,IAAI,C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AC,OAAO,CAAC,OAAO,CAAC,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;YACnC,OAAO,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YAClB,iBAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACL,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;KAAM,CAAC;IACJ,2BAA2B;IAC3B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B,mCAAmC;IACnC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpB,OAAO,CAAC,UAAU,EAAE,CAAC;IACzB,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/api/client.ts
CHANGED
|
@@ -42,12 +42,8 @@ export class MatexAPIClient {
|
|
|
42
42
|
uid: 'cli-user', // Placeholder, backend uses API key for auth
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
return this.handleStreamingResponse(response.data);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return response.data;
|
|
45
|
+
// Backend always returns SSE format, parse it
|
|
46
|
+
return this.handleStreamingResponse(response.data);
|
|
51
47
|
} catch (error: any) {
|
|
52
48
|
if (error.response) {
|
|
53
49
|
throw new Error(`API Error: ${error.response.data.detail || error.response.statusText}`);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../utils/config';
|
|
4
|
+
import { MatexAPIClient } from '../api/client';
|
|
5
|
+
import { spinner } from '../utils/spinner';
|
|
6
|
+
|
|
7
|
+
export const codeCommand = new Command('code')
|
|
8
|
+
.description('Generate code with MATEXCodex (optimized for coding)')
|
|
9
|
+
.argument('<prompt>', 'What code do you need?')
|
|
10
|
+
.option('-o, --output <file>', 'Save output to file')
|
|
11
|
+
.option('-l, --language <lang>', 'Programming language (auto-detected if not specified)')
|
|
12
|
+
.option('-t, --temperature <number>', 'Temperature (0-1)', '0.3')
|
|
13
|
+
.option('--max-tokens <number>', 'Maximum tokens in response', '8000')
|
|
14
|
+
.action(async (prompt: string, options: any) => {
|
|
15
|
+
try {
|
|
16
|
+
// Check for API key
|
|
17
|
+
const apiKey = configManager.getAPIKey();
|
|
18
|
+
if (!apiKey) {
|
|
19
|
+
console.error(chalk.red('ā No API key configured.'));
|
|
20
|
+
console.log(chalk.yellow('Run: matex config set-key <your-api-key>'));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Create API client
|
|
25
|
+
const client = new MatexAPIClient(apiKey, configManager.getBaseURL());
|
|
26
|
+
|
|
27
|
+
// Enhance prompt for code generation
|
|
28
|
+
let enhancedPrompt = prompt;
|
|
29
|
+
if (options.language) {
|
|
30
|
+
enhancedPrompt = `Generate ${options.language} code: ${prompt}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Show thinking indicator
|
|
34
|
+
spinner.start('Generating code with MATEXCodex...');
|
|
35
|
+
|
|
36
|
+
// Send request (always use matexcodex for code command)
|
|
37
|
+
const response = await client.chat({
|
|
38
|
+
messages: [
|
|
39
|
+
{ role: 'system', content: 'You are MATEXCodex, an expert coding assistant. Generate clean, production-ready code with comments and best practices. Always include complete, working code.' },
|
|
40
|
+
{ role: 'user', content: enhancedPrompt }
|
|
41
|
+
],
|
|
42
|
+
model: 'matexcodex',
|
|
43
|
+
temperature: parseFloat(options.temperature),
|
|
44
|
+
max_tokens: parseInt(options.maxTokens),
|
|
45
|
+
stream: false,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
spinner.succeed('Code generated!');
|
|
49
|
+
|
|
50
|
+
// Display response
|
|
51
|
+
console.log(chalk.cyan('\nš» MATEXCodex:\n'));
|
|
52
|
+
console.log(chalk.white(response));
|
|
53
|
+
console.log();
|
|
54
|
+
|
|
55
|
+
// Save to file if requested
|
|
56
|
+
if (options.output) {
|
|
57
|
+
const fs = require('fs');
|
|
58
|
+
const path = require('path');
|
|
59
|
+
|
|
60
|
+
// Ensure directory exists
|
|
61
|
+
const dir = path.dirname(options.output);
|
|
62
|
+
if (!fs.existsSync(dir) && dir !== '.') {
|
|
63
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Extract code from response (remove markdown if present)
|
|
67
|
+
let codeContent = response;
|
|
68
|
+
const codeBlockMatch = response.match(/```[\w]*\n([\s\S]*?)```/);
|
|
69
|
+
if (codeBlockMatch) {
|
|
70
|
+
codeContent = codeBlockMatch[1];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fs.writeFileSync(options.output, codeContent.trim());
|
|
74
|
+
console.log(chalk.green(`ā
Code saved to: ${options.output}`));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
} catch (error: any) {
|
|
78
|
+
spinner.fail('Code generation failed');
|
|
79
|
+
|
|
80
|
+
if (error.message.includes('403')) {
|
|
81
|
+
console.error(chalk.red('\nā Invalid or revoked API key.'));
|
|
82
|
+
console.log(chalk.yellow('Please check your API key or generate a new one from the MATEX AI platform.'));
|
|
83
|
+
} else if (error.message.includes('429')) {
|
|
84
|
+
console.error(chalk.red('\nā Rate limit exceeded.'));
|
|
85
|
+
console.log(chalk.yellow('Please wait a moment before trying again.'));
|
|
86
|
+
} else {
|
|
87
|
+
console.error(chalk.red(`\nā Error: ${error.message}`));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import { configManager } from '../utils/config';
|
|
5
|
+
import { MatexAPIClient, ChatMessage } from '../api/client';
|
|
6
|
+
import { spinner } from '../utils/spinner';
|
|
7
|
+
|
|
8
|
+
export const devCommand = new Command('dev')
|
|
9
|
+
.description('Start interactive development session with MATEXCodex')
|
|
10
|
+
.option('-m, --model <model>', 'AI model to use', 'matexcodex')
|
|
11
|
+
.action(async (options: any) => {
|
|
12
|
+
try {
|
|
13
|
+
// Check for API key
|
|
14
|
+
const apiKey = configManager.getAPIKey();
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
console.error(chalk.red('ā No API key configured.'));
|
|
17
|
+
console.log(chalk.yellow('Run: matex config set-key <your-api-key>'));
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Create API client
|
|
22
|
+
const client = new MatexAPIClient(apiKey, configManager.getBaseURL());
|
|
23
|
+
|
|
24
|
+
// Welcome message
|
|
25
|
+
console.log(chalk.cyan.bold('\nš MATEX Development Session'));
|
|
26
|
+
console.log(chalk.gray('ā'.repeat(50)));
|
|
27
|
+
console.log(chalk.white(`Model: ${chalk.cyan(options.model)}`));
|
|
28
|
+
console.log(chalk.gray('Type your requests, or "exit" to quit\n'));
|
|
29
|
+
|
|
30
|
+
// Conversation history
|
|
31
|
+
const messages: ChatMessage[] = [
|
|
32
|
+
{
|
|
33
|
+
role: 'system',
|
|
34
|
+
content: 'You are MATEXCodex, an expert software development assistant. Help the user build their application step by step. Provide complete, production-ready code with explanations. Be concise but thorough.'
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
// Interactive loop
|
|
39
|
+
let continueChat = true;
|
|
40
|
+
|
|
41
|
+
while (continueChat) {
|
|
42
|
+
// Get user input
|
|
43
|
+
const { userInput } = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
type: 'input',
|
|
46
|
+
name: 'userInput',
|
|
47
|
+
message: chalk.cyan('You:'),
|
|
48
|
+
prefix: ''
|
|
49
|
+
}
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
// Check for exit
|
|
53
|
+
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
|
54
|
+
console.log(chalk.yellow('\nš Ending development session. Happy coding!\n'));
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Skip empty input
|
|
59
|
+
if (!userInput.trim()) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Add user message to history
|
|
64
|
+
messages.push({ role: 'user', content: userInput });
|
|
65
|
+
|
|
66
|
+
// Show thinking indicator
|
|
67
|
+
spinner.start('Thinking...');
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
// Send request
|
|
71
|
+
const response = await client.chat({
|
|
72
|
+
messages,
|
|
73
|
+
model: options.model,
|
|
74
|
+
temperature: 0.3,
|
|
75
|
+
max_tokens: 8000,
|
|
76
|
+
stream: false,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
spinner.stop();
|
|
80
|
+
|
|
81
|
+
// Add assistant response to history
|
|
82
|
+
messages.push({ role: 'assistant', content: response });
|
|
83
|
+
|
|
84
|
+
// Display response
|
|
85
|
+
console.log(chalk.green('\nMATEXCodex:'));
|
|
86
|
+
console.log(chalk.white(response));
|
|
87
|
+
console.log();
|
|
88
|
+
|
|
89
|
+
} catch (error: any) {
|
|
90
|
+
spinner.fail('Request failed');
|
|
91
|
+
console.error(chalk.red(`Error: ${error.message}\n`));
|
|
92
|
+
|
|
93
|
+
// Remove the failed user message
|
|
94
|
+
messages.pop();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
} catch (error: any) {
|
|
99
|
+
console.error(chalk.red(`\nā Error: ${error.message}`));
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -6,13 +6,18 @@ import { configCommand } from './commands/config';
|
|
|
6
6
|
import { askCommand } from './commands/ask';
|
|
7
7
|
import { chatCommand } from './commands/chat';
|
|
8
8
|
import { modelsCommand } from './commands/models';
|
|
9
|
+
import { codeCommand } from './commands/code';
|
|
10
|
+
import { devCommand } from './commands/dev';
|
|
11
|
+
import { configManager } from './utils/config';
|
|
12
|
+
import { MatexAPIClient } from './api/client';
|
|
13
|
+
import { spinner } from './utils/spinner';
|
|
9
14
|
|
|
10
15
|
const program = new Command();
|
|
11
16
|
|
|
12
17
|
program
|
|
13
18
|
.name('matex')
|
|
14
19
|
.description('Official CLI tool for MATEX AI - Access powerful AI models from your terminal')
|
|
15
|
-
.version('1.0.
|
|
20
|
+
.version('1.0.2');
|
|
16
21
|
|
|
17
22
|
// ASCII Art Banner
|
|
18
23
|
const banner = `
|
|
@@ -26,9 +31,9 @@ program.on('--help', () => {
|
|
|
26
31
|
console.log(banner);
|
|
27
32
|
console.log(chalk.gray('\nExamples:'));
|
|
28
33
|
console.log(chalk.white(' $ matex config set-key sk-matex-xxxxx'));
|
|
29
|
-
console.log(chalk.white(' $ matex
|
|
30
|
-
console.log(chalk.white(' $ matex
|
|
31
|
-
console.log(chalk.white(' $ matex
|
|
34
|
+
console.log(chalk.white(' $ matex code "Create a React login component"'));
|
|
35
|
+
console.log(chalk.white(' $ matex dev'));
|
|
36
|
+
console.log(chalk.white(' $ matex "build a todo app" # Direct input'))
|
|
32
37
|
console.log();
|
|
33
38
|
console.log(chalk.gray('Get your API key from: ') + chalk.cyan('https://matexai.space/platform'));
|
|
34
39
|
console.log();
|
|
@@ -39,12 +44,57 @@ program.addCommand(configCommand);
|
|
|
39
44
|
program.addCommand(askCommand);
|
|
40
45
|
program.addCommand(chatCommand);
|
|
41
46
|
program.addCommand(modelsCommand);
|
|
47
|
+
program.addCommand(codeCommand);
|
|
48
|
+
program.addCommand(devCommand);
|
|
42
49
|
|
|
43
|
-
//
|
|
44
|
-
|
|
50
|
+
// Handle direct input (no subcommand)
|
|
51
|
+
const args = process.argv.slice(2);
|
|
52
|
+
const knownCommands = ['config', 'ask', 'chat', 'models', 'code', 'dev', 'help', '--help', '-h', '--version', '-V'];
|
|
45
53
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
if (args.length > 0 && !args[0].startsWith('-') && !knownCommands.includes(args[0])) {
|
|
55
|
+
// Direct input mode - treat as code generation
|
|
56
|
+
const prompt = args.join(' ');
|
|
57
|
+
|
|
58
|
+
(async () => {
|
|
59
|
+
try {
|
|
60
|
+
const apiKey = configManager.getAPIKey();
|
|
61
|
+
if (!apiKey) {
|
|
62
|
+
console.error(chalk.red('ā No API key configured.'));
|
|
63
|
+
console.log(chalk.yellow('Run: matex config set-key <your-api-key>'));
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const client = new MatexAPIClient(apiKey, configManager.getBaseURL());
|
|
68
|
+
spinner.start('Generating with MATEXCodex...');
|
|
69
|
+
|
|
70
|
+
const response = await client.chat({
|
|
71
|
+
messages: [
|
|
72
|
+
{ role: 'system', content: 'You are MATEXCodex, an expert coding assistant. Provide complete, production-ready code with explanations.' },
|
|
73
|
+
{ role: 'user', content: prompt }
|
|
74
|
+
],
|
|
75
|
+
model: 'matexcodex',
|
|
76
|
+
temperature: 0.3,
|
|
77
|
+
max_tokens: 8000,
|
|
78
|
+
stream: false,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
spinner.succeed('Done!');
|
|
82
|
+
console.log(chalk.cyan('\nš» MATEXCodex:\n'));
|
|
83
|
+
console.log(chalk.white(response));
|
|
84
|
+
console.log();
|
|
85
|
+
} catch (error: any) {
|
|
86
|
+
spinner.fail('Failed');
|
|
87
|
+
console.error(chalk.red(`\nā ${error.message}`));
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
91
|
+
} else {
|
|
92
|
+
// Parse arguments normally
|
|
93
|
+
program.parse(process.argv);
|
|
94
|
+
|
|
95
|
+
// Show help if no command provided
|
|
96
|
+
if (!args.length) {
|
|
97
|
+
console.log(banner);
|
|
98
|
+
program.outputHelp();
|
|
99
|
+
}
|
|
50
100
|
}
|