npm-noxyai 1.0.3 → 1.0.5
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/{index.js → index-noxyai.js} +35 -42
- package/package.json +4 -7
|
@@ -4,7 +4,6 @@ const fs = require('fs');
|
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
|
|
7
|
-
// Canonical URL to avoid 308 redirects that strip Auth headers
|
|
8
7
|
const BASE_URL = 'https://www.noxyai.com';
|
|
9
8
|
const CONFIG_FILE = path.join(os.homedir(), '.noxyai.json');
|
|
10
9
|
|
|
@@ -26,30 +25,31 @@ function getToken() {
|
|
|
26
25
|
async function login() {
|
|
27
26
|
console.log('Initializing login...');
|
|
28
27
|
try {
|
|
29
|
-
const initRes = await fetch(
|
|
28
|
+
const initRes = await fetch(BASE_URL + '/api/cli/init', { method: 'POST' });
|
|
30
29
|
const { deviceCode, verificationUrl, interval } = await initRes.json();
|
|
31
30
|
|
|
32
31
|
console.log('\n=============================================');
|
|
33
32
|
console.log('Action Required: Please authenticate your terminal');
|
|
34
|
-
console.log(
|
|
33
|
+
console.log('Open this URL in your browser:\n\n -> ' + verificationUrl + ' <-');
|
|
35
34
|
console.log('=============================================\n');
|
|
36
35
|
console.log('Waiting for confirmation...');
|
|
37
36
|
|
|
38
37
|
const pollInterval = setInterval(async () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const data = await pollRes.json();
|
|
46
|
-
|
|
47
|
-
if (data.status === 'success') {
|
|
48
|
-
clearInterval(pollInterval);
|
|
49
|
-
saveToken(data.token);
|
|
38
|
+
try {
|
|
39
|
+
const pollRes = await fetch(BASE_URL + '/api/cli/poll', {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify({ deviceCode })
|
|
43
|
+
});
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
const data = await pollRes.json();
|
|
46
|
+
|
|
47
|
+
if (data.status === 'success') {
|
|
48
|
+
clearInterval(pollInterval);
|
|
49
|
+
saveToken(data.token);
|
|
50
|
+
|
|
51
|
+
console.clear();
|
|
52
|
+
console.log('\x1b[36m' +
|
|
53
53
|
` ___ ___ ___ ___ ___
|
|
54
54
|
/\\__\\ /\\ \\ |\\__\\ |\\__\\ /\\ \\ ___
|
|
55
55
|
/::| | /::\\ \\ |:| | |:| | /::\\ \\ /\\ \\
|
|
@@ -60,16 +60,16 @@ async function login() {
|
|
|
60
60
|
|:/:/ / \\:\\ /:/ / ~~|:|~~| /:/ / \\::/ / \\::/__/
|
|
61
61
|
|::/ / \\:\\/:/ / |:| | \\/__/ /:/ / \\:\\__\\
|
|
62
62
|
/:/ / \\::/ / |:| | /:/ / \\/__/
|
|
63
|
-
\\/__/ \\/__/ \\|__| \\/__
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
63
|
+
\\/__/ \\/__/ \\|__| \\/__/` + '\x1b[0m');
|
|
64
|
+
console.log('\n✅ Login successful! Terminal connected.');
|
|
65
|
+
console.log('Try running: noxyai chat "Hello, world!"\n');
|
|
66
|
+
process.exit(0);
|
|
67
|
+
} else if (data.error) {
|
|
68
|
+
clearInterval(pollInterval);
|
|
69
|
+
console.error('\n❌ Login failed: ' + data.error);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {}
|
|
73
73
|
}, interval * 1000);
|
|
74
74
|
|
|
75
75
|
} catch (error) {
|
|
@@ -85,29 +85,29 @@ async function chat(prompt) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (!prompt) {
|
|
88
|
-
console.error('❌ Please provide a prompt.
|
|
88
|
+
console.error('❌ Please provide a prompt.');
|
|
89
89
|
process.exit(1);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const model = 'auto';
|
|
93
93
|
|
|
94
94
|
try {
|
|
95
|
-
const res = await fetch(
|
|
95
|
+
const res = await fetch(BASE_URL + '/api/cli/execute', {
|
|
96
96
|
method: 'POST',
|
|
97
97
|
headers: {
|
|
98
98
|
'Content-Type': 'application/json',
|
|
99
|
-
'Authorization':
|
|
99
|
+
'Authorization': 'Bearer ' + token
|
|
100
100
|
},
|
|
101
101
|
body: JSON.stringify({ prompt, model })
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
if (!res.ok) {
|
|
105
105
|
const errorText = await res.text();
|
|
106
|
-
console.error(
|
|
106
|
+
console.error('\n❌ API Error: ' + errorText);
|
|
107
107
|
process.exit(1);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
console.log(
|
|
110
|
+
console.log('\n🤖 NoxyAI (' + model + '):\n');
|
|
111
111
|
|
|
112
112
|
const reader = res.body.getReader();
|
|
113
113
|
const decoder = new TextDecoder('utf-8');
|
|
@@ -117,13 +117,13 @@ async function chat(prompt) {
|
|
|
117
117
|
if (done) break;
|
|
118
118
|
|
|
119
119
|
const chunk = decoder.decode(value, { stream: true });
|
|
120
|
-
const lines = chunk.split('
|
|
120
|
+
const lines = chunk.split('\n');
|
|
121
121
|
|
|
122
122
|
for (const line of lines) {
|
|
123
123
|
if (line.startsWith('data: ')) {
|
|
124
124
|
const data = line.slice(6).trim();
|
|
125
125
|
if (data === '[DONE]') {
|
|
126
|
-
console.log('
|
|
126
|
+
console.log('\n');
|
|
127
127
|
process.exit(0);
|
|
128
128
|
}
|
|
129
129
|
try {
|
|
@@ -136,7 +136,7 @@ async function chat(prompt) {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
} catch (error) {
|
|
139
|
-
console.error('
|
|
139
|
+
console.error('\n❌ Connection error: ' + error.message);
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -146,12 +146,5 @@ if (command === 'login') {
|
|
|
146
146
|
const prompt = args.slice(1).join(' ');
|
|
147
147
|
chat(prompt);
|
|
148
148
|
} else {
|
|
149
|
-
console.log(
|
|
150
|
-
Usage:
|
|
151
|
-
noxyai login - Authenticate your terminal
|
|
152
|
-
noxyai chat <prompt> - Chat with NoxyAI
|
|
153
|
-
|
|
154
|
-
Example:
|
|
155
|
-
noxyai chat "How do I reverse a string in JS?"
|
|
156
|
-
\`);
|
|
149
|
+
console.log('\nUsage:\n noxyai login\n noxyai chat <prompt>\n');
|
|
157
150
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-noxyai",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "CLI for NoxyAI",
|
|
5
|
+
"main": "index-noxyai.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"noxyai": "./index.js"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
"noxyai": "./index-noxyai.js"
|
|
11
8
|
},
|
|
12
9
|
"author": "Mohammad Junaid Rather",
|
|
13
10
|
"license": "ISC"
|