npm-noxyai 1.0.3 → 1.0.4
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 +13 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -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
|
|
|
@@ -49,7 +48,7 @@ async function login() {
|
|
|
49
48
|
saveToken(data.token);
|
|
50
49
|
|
|
51
50
|
console.clear();
|
|
52
|
-
console.log('\
|
|
51
|
+
console.log('\x1b[36m' +
|
|
53
52
|
` ___ ___ ___ ___ ___
|
|
54
53
|
/\\__\\ /\\ \\ |\\__\\ |\\__\\ /\\ \\ ___
|
|
55
54
|
/::| | /::\\ \\ |:| | |:| | /::\\ \\ /\\ \\
|
|
@@ -60,14 +59,13 @@ async function login() {
|
|
|
60
59
|
|:/:/ / \\:\\ /:/ / ~~|:|~~| /:/ / \\::/ / \\::/__/
|
|
61
60
|
|::/ / \\:\\/:/ / |:| | \\/__/ /:/ / \\:\\__\\
|
|
62
61
|
/:/ / \\::/ / |:| | /:/ / \\/__/
|
|
63
|
-
\\/__/ \\/__/ \\|__| \\/__
|
|
64
|
-
+ '\x1b[0m');
|
|
62
|
+
\\/__/ \\/__/ \\|__| \\/__/` + '\x1b[0m');
|
|
65
63
|
console.log('\n✅ Login successful! Terminal connected.');
|
|
66
64
|
console.log('Try running: noxyai chat "Hello, world!"\n');
|
|
67
65
|
process.exit(0);
|
|
68
66
|
} else if (data.error) {
|
|
69
67
|
clearInterval(pollInterval);
|
|
70
|
-
console.error(
|
|
68
|
+
console.error('\n❌ Login failed:', data.error);
|
|
71
69
|
process.exit(1);
|
|
72
70
|
}
|
|
73
71
|
}, interval * 1000);
|
|
@@ -85,29 +83,29 @@ async function chat(prompt) {
|
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
if (!prompt) {
|
|
88
|
-
console.error('❌ Please provide a prompt.
|
|
86
|
+
console.error('❌ Please provide a prompt.');
|
|
89
87
|
process.exit(1);
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
const model = 'auto';
|
|
93
91
|
|
|
94
92
|
try {
|
|
95
|
-
const res = await fetch(
|
|
93
|
+
const res = await fetch(`${BASE_URL}/api/cli/execute`, {
|
|
96
94
|
method: 'POST',
|
|
97
95
|
headers: {
|
|
98
96
|
'Content-Type': 'application/json',
|
|
99
|
-
'Authorization':
|
|
97
|
+
'Authorization': `Bearer ${token}`
|
|
100
98
|
},
|
|
101
99
|
body: JSON.stringify({ prompt, model })
|
|
102
100
|
});
|
|
103
101
|
|
|
104
102
|
if (!res.ok) {
|
|
105
103
|
const errorText = await res.text();
|
|
106
|
-
console.error(
|
|
104
|
+
console.error(`\n❌ API Error: ${errorText}`);
|
|
107
105
|
process.exit(1);
|
|
108
106
|
}
|
|
109
107
|
|
|
110
|
-
console.log(
|
|
108
|
+
console.log(`\n🤖 NoxyAI (${model}):\n`);
|
|
111
109
|
|
|
112
110
|
const reader = res.body.getReader();
|
|
113
111
|
const decoder = new TextDecoder('utf-8');
|
|
@@ -117,13 +115,13 @@ async function chat(prompt) {
|
|
|
117
115
|
if (done) break;
|
|
118
116
|
|
|
119
117
|
const chunk = decoder.decode(value, { stream: true });
|
|
120
|
-
const lines = chunk.split('
|
|
118
|
+
const lines = chunk.split('\n');
|
|
121
119
|
|
|
122
120
|
for (const line of lines) {
|
|
123
121
|
if (line.startsWith('data: ')) {
|
|
124
122
|
const data = line.slice(6).trim();
|
|
125
123
|
if (data === '[DONE]') {
|
|
126
|
-
console.log('
|
|
124
|
+
console.log('\n');
|
|
127
125
|
process.exit(0);
|
|
128
126
|
}
|
|
129
127
|
try {
|
|
@@ -136,7 +134,7 @@ async function chat(prompt) {
|
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
} catch (error) {
|
|
139
|
-
console.error('
|
|
137
|
+
console.error('\n❌ Connection error:', error.message);
|
|
140
138
|
}
|
|
141
139
|
}
|
|
142
140
|
|
|
@@ -146,12 +144,9 @@ if (command === 'login') {
|
|
|
146
144
|
const prompt = args.slice(1).join(' ');
|
|
147
145
|
chat(prompt);
|
|
148
146
|
} else {
|
|
149
|
-
console.log(
|
|
147
|
+
console.log(`
|
|
150
148
|
Usage:
|
|
151
149
|
noxyai login - Authenticate your terminal
|
|
152
150
|
noxyai chat <prompt> - Chat with NoxyAI
|
|
153
|
-
|
|
154
|
-
Example:
|
|
155
|
-
noxyai chat "How do I reverse a string in JS?"
|
|
156
|
-
\`);
|
|
151
|
+
`);
|
|
157
152
|
}
|