npm-noxyai 1.0.1 → 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 (2) hide show
  1. package/index.js +32 -28
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4,19 +4,17 @@ const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
6
 
7
- // Change this to http://localhost:3000 if you are testing locally first
8
- const BASE_URL = 'https://noxyai.com';
7
+ // Canonical URL to avoid 308 redirects that strip Auth headers
8
+ const BASE_URL = 'https://www.noxyai.com';
9
9
  const CONFIG_FILE = path.join(os.homedir(), '.noxyai.json');
10
10
 
11
11
  const args = process.argv.slice(2);
12
12
  const command = args[0];
13
13
 
14
- // Helper: Save token to ~/.noxyai.json
15
14
  function saveToken(token) {
16
15
  fs.writeFileSync(CONFIG_FILE, JSON.stringify({ token }));
17
16
  }
18
17
 
19
- // Helper: Read token
20
18
  function getToken() {
21
19
  if (fs.existsSync(CONFIG_FILE)) {
22
20
  const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
@@ -25,7 +23,6 @@ function getToken() {
25
23
  return null;
26
24
  }
27
25
 
28
- // --- COMMAND: login ---
29
26
  async function login() {
30
27
  console.log('Initializing login...');
31
28
  try {
@@ -38,7 +35,6 @@ async function login() {
38
35
  console.log('=============================================\n');
39
36
  console.log('Waiting for confirmation...');
40
37
 
41
- // Poll the server to see if the user clicked "Authorize"
42
38
  const pollInterval = setInterval(async () => {
43
39
  const pollRes = await fetch(`${BASE_URL}/api/cli/poll`, {
44
40
  method: 'POST',
@@ -51,12 +47,27 @@ async function login() {
51
47
  if (data.status === 'success') {
52
48
  clearInterval(pollInterval);
53
49
  saveToken(data.token);
54
- console.log('\n✅ Login successful! You are now connected to NoxyAI.');
55
- console.log('Try running: noxyai chat "Hello, world!"');
50
+
51
+ console.clear();
52
+ console.log('\n\x1b[36m' +
53
+ ` ___ ___ ___ ___ ___
54
+ /\\__\\ /\\ \\ |\\__\\ |\\__\\ /\\ \\ ___
55
+ /::| | /::\\ \\ |:| | |:| | /::\\ \\ /\\ \\
56
+ /:|:| | /:/\\:\\ \\ |:| | |:| | /:/\\:\\ \\ \\:\\ \\
57
+ /:/|:| |__ /:/ \\:\\ \\ |:|__|__ |:|__|__ /::\\~\\:\\ \\ /::\\__\\
58
+ /:/ |:| /\\__\\ /:/__/ \\:\\__\\ ____/::::\\__\\ /::::\\__\\ /:/\\:\\ \\:\\__\\ __/:/\\/__/
59
+ \\/__|:|/:/ / \\:\\ \\ /:/ / \\::::/~~/~ /:/~~/~ \\/__\\:\\/:/ / /\\/:/ /
60
+ |:/:/ / \\:\\ /:/ / ~~|:|~~| /:/ / \\::/ / \\::/__/
61
+ |::/ / \\:\\/:/ / |:| | \\/__/ /:/ / \\:\\__\\
62
+ /:/ / \\::/ / |:| | /:/ / \\/__/
63
+ \\/__/ \\/__/ \\|__| \\/__/ `
64
+ + '\x1b[0m');
65
+ console.log('\n✅ Login successful! Terminal connected.');
66
+ console.log('Try running: noxyai chat "Hello, world!"\n');
56
67
  process.exit(0);
57
68
  } else if (data.error) {
58
69
  clearInterval(pollInterval);
59
- console.error(`\n❌ Login failed: ${data.error}`);
70
+ console.error(\`\\n❌ Login failed: \${data.error}\`);
60
71
  process.exit(1);
61
72
  }
62
73
  }, interval * 1000);
@@ -66,7 +77,6 @@ async function login() {
66
77
  }
67
78
  }
68
79
 
69
- // --- COMMAND: chat ---
70
80
  async function chat(prompt) {
71
81
  const token = getToken();
72
82
  if (!token) {
@@ -79,28 +89,26 @@ async function chat(prompt) {
79
89
  process.exit(1);
80
90
  }
81
91
 
82
- // Defaulting to auto model, but you can add CLI flags (e.g. --model deepseek) later
83
92
  const model = 'auto';
84
93
 
85
94
  try {
86
- const res = await fetch(`${BASE_URL}/api/cli/execute`, {
95
+ const res = await fetch(\`\${BASE_URL}/api/cli/execute\`, {
87
96
  method: 'POST',
88
97
  headers: {
89
98
  'Content-Type': 'application/json',
90
- 'Authorization': `Bearer ${token}`
99
+ 'Authorization': \`Bearer \${token}\`
91
100
  },
92
101
  body: JSON.stringify({ prompt, model })
93
102
  });
94
103
 
95
104
  if (!res.ok) {
96
105
  const errorText = await res.text();
97
- console.error(`\n❌ API Error: ${errorText}`);
106
+ console.error(\`\\n❌ API Error: \${errorText}\`);
98
107
  process.exit(1);
99
108
  }
100
109
 
101
- console.log(`\n🤖 NoxyAI (${model}):\n`);
110
+ console.log(\`\\n🤖 NoxyAI (\${model}):\\n\`);
102
111
 
103
- // Parse the Server-Sent Events (SSE) stream
104
112
  const reader = res.body.getReader();
105
113
  const decoder = new TextDecoder('utf-8');
106
114
 
@@ -109,45 +117,41 @@ async function chat(prompt) {
109
117
  if (done) break;
110
118
 
111
119
  const chunk = decoder.decode(value, { stream: true });
112
- const lines = chunk.split('\n');
120
+ const lines = chunk.split('\\n');
113
121
 
114
122
  for (const line of lines) {
115
123
  if (line.startsWith('data: ')) {
116
124
  const data = line.slice(6).trim();
117
125
  if (data === '[DONE]') {
118
- console.log('\n'); // Add final newline
126
+ console.log('\\n');
119
127
  process.exit(0);
120
128
  }
121
129
  try {
122
130
  const parsed = JSON.parse(data);
123
131
  if (parsed.text) {
124
- process.stdout.write(parsed.text); // Print exactly as it streams
132
+ process.stdout.write(parsed.text);
125
133
  }
126
- } catch (e) {
127
- // Ignore parse errors on partial chunks
128
- }
134
+ } catch (e) {}
129
135
  }
130
136
  }
131
137
  }
132
138
  } catch (error) {
133
- console.error('\n❌ Connection error:', error.message);
139
+ console.error('\\n❌ Connection error:', error.message);
134
140
  }
135
141
  }
136
142
 
137
- // --- ROUTER ---
138
143
  if (command === 'login') {
139
144
  login();
140
145
  } else if (command === 'chat') {
141
- const prompt = args.slice(1).join(' '); // Capture everything after "chat"
146
+ const prompt = args.slice(1).join(' ');
142
147
  chat(prompt);
143
148
  } else {
144
- console.log(`
149
+ console.log(\`
145
150
  Usage:
146
151
  noxyai login - Authenticate your terminal
147
152
  noxyai chat <prompt> - Chat with NoxyAI
148
153
 
149
154
  Example:
150
155
  noxyai chat "How do I reverse a string in JS?"
151
- `);
156
+ \`);
152
157
  }
153
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-noxyai",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {