@nolimitcli/cli 2.1.0 → 2.1.1
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/index.js +49 -65
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import Conf from 'conf';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import ora from 'ora';
|
|
5
5
|
import open from 'open';
|
|
6
|
-
import
|
|
6
|
+
import { createInterface } from 'readline';
|
|
7
7
|
const API_BASE = 'https://nolimit-production-2589.up.railway.app';
|
|
8
|
-
const VERSION = '2.1.
|
|
8
|
+
const VERSION = '2.1.1';
|
|
9
9
|
// Persistent config storage
|
|
10
10
|
const config = new Conf({
|
|
11
11
|
projectName: 'nolimit',
|
|
@@ -133,7 +133,7 @@ function showWelcome(balance) {
|
|
|
133
133
|
console.log();
|
|
134
134
|
}
|
|
135
135
|
// ============================================================================
|
|
136
|
-
// MAIN
|
|
136
|
+
// MAIN
|
|
137
137
|
// ============================================================================
|
|
138
138
|
async function main() {
|
|
139
139
|
// Get or create API key
|
|
@@ -153,36 +153,29 @@ async function main() {
|
|
|
153
153
|
let balance = balanceData?.balance || 0;
|
|
154
154
|
// Show welcome
|
|
155
155
|
showWelcome(balance);
|
|
156
|
-
// Create readline interface
|
|
157
|
-
const rl =
|
|
156
|
+
// Create readline interface
|
|
157
|
+
const rl = createInterface({
|
|
158
158
|
input: process.stdin,
|
|
159
159
|
output: process.stdout,
|
|
160
160
|
});
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// Main loop
|
|
168
|
-
while (true) {
|
|
169
|
-
let input;
|
|
170
|
-
try {
|
|
171
|
-
input = await rl.question(chalk.green('› '));
|
|
172
|
-
}
|
|
173
|
-
catch {
|
|
174
|
-
// EOF or stream closed
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
161
|
+
// Show prompt
|
|
162
|
+
const showPrompt = () => {
|
|
163
|
+
process.stdout.write(chalk.green('› '));
|
|
164
|
+
};
|
|
165
|
+
// Handle each line
|
|
166
|
+
rl.on('line', async (input) => {
|
|
177
167
|
const trimmed = input.trim();
|
|
178
|
-
if (!trimmed)
|
|
179
|
-
|
|
168
|
+
if (!trimmed) {
|
|
169
|
+
showPrompt();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
180
172
|
// Handle commands
|
|
181
173
|
if (trimmed.startsWith('/')) {
|
|
182
174
|
const cmd = trimmed.toLowerCase();
|
|
183
175
|
if (cmd === '/quit' || cmd === '/exit' || cmd === '/q') {
|
|
184
176
|
console.log(chalk.dim('\n Goodbye.\n'));
|
|
185
|
-
|
|
177
|
+
rl.close();
|
|
178
|
+
process.exit(0);
|
|
186
179
|
}
|
|
187
180
|
if (cmd === '/help' || cmd === '/h') {
|
|
188
181
|
console.log();
|
|
@@ -192,7 +185,8 @@ async function main() {
|
|
|
192
185
|
console.log(chalk.cyan(' /clear') + chalk.dim(' Clear screen'));
|
|
193
186
|
console.log(chalk.cyan(' /quit') + chalk.dim(' Exit'));
|
|
194
187
|
console.log();
|
|
195
|
-
|
|
188
|
+
showPrompt();
|
|
189
|
+
return;
|
|
196
190
|
}
|
|
197
191
|
if (cmd === '/earn' || cmd === '/e') {
|
|
198
192
|
console.log();
|
|
@@ -202,7 +196,8 @@ async function main() {
|
|
|
202
196
|
balance = newData?.balance || balance;
|
|
203
197
|
}
|
|
204
198
|
console.log();
|
|
205
|
-
|
|
199
|
+
showPrompt();
|
|
200
|
+
return;
|
|
206
201
|
}
|
|
207
202
|
if (cmd === '/balance' || cmd === '/b') {
|
|
208
203
|
const data = await getBalance(apiKey);
|
|
@@ -214,35 +209,25 @@ async function main() {
|
|
|
214
209
|
console.log(chalk.dim(' Spent: ') + formatTokens(data.totalSpent));
|
|
215
210
|
console.log();
|
|
216
211
|
}
|
|
217
|
-
|
|
212
|
+
showPrompt();
|
|
213
|
+
return;
|
|
218
214
|
}
|
|
219
215
|
if (cmd === '/clear' || cmd === '/c') {
|
|
220
216
|
showWelcome(balance);
|
|
221
|
-
|
|
217
|
+
showPrompt();
|
|
218
|
+
return;
|
|
222
219
|
}
|
|
223
220
|
console.log(chalk.dim(`\n Unknown: ${trimmed}\n`));
|
|
224
|
-
|
|
221
|
+
showPrompt();
|
|
222
|
+
return;
|
|
225
223
|
}
|
|
226
224
|
// Check if we have enough tokens
|
|
227
225
|
if (balance < 100) {
|
|
228
226
|
console.log();
|
|
229
|
-
console.log(chalk.yellow(' Low tokens.'));
|
|
230
|
-
let answer;
|
|
231
|
-
try {
|
|
232
|
-
answer = await rl.question(chalk.dim(' Watch ad? ') + chalk.cyan('[Y/n] '));
|
|
233
|
-
}
|
|
234
|
-
catch {
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
if (answer.toLowerCase() !== 'n') {
|
|
238
|
-
const success = await watchAd(apiKey);
|
|
239
|
-
if (success) {
|
|
240
|
-
const newData = await getBalance(apiKey);
|
|
241
|
-
balance = newData?.balance || balance;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
227
|
+
console.log(chalk.yellow(' Low tokens. Run /earn to get more.'));
|
|
244
228
|
console.log();
|
|
245
|
-
|
|
229
|
+
showPrompt();
|
|
230
|
+
return;
|
|
246
231
|
}
|
|
247
232
|
// Generate response
|
|
248
233
|
console.log();
|
|
@@ -251,27 +236,15 @@ async function main() {
|
|
|
251
236
|
if (!result) {
|
|
252
237
|
spinner.fail(chalk.red('Failed'));
|
|
253
238
|
console.log();
|
|
254
|
-
|
|
239
|
+
showPrompt();
|
|
240
|
+
return;
|
|
255
241
|
}
|
|
256
242
|
if (result.text === '__INSUFFICIENT_TOKENS__') {
|
|
257
243
|
spinner.stop();
|
|
258
|
-
console.log(chalk.yellow(' Insufficient tokens.'));
|
|
259
|
-
let answer;
|
|
260
|
-
try {
|
|
261
|
-
answer = await rl.question(chalk.dim(' Watch ad? ') + chalk.cyan('[Y/n] '));
|
|
262
|
-
}
|
|
263
|
-
catch {
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
if (answer.toLowerCase() !== 'n') {
|
|
267
|
-
const success = await watchAd(apiKey);
|
|
268
|
-
if (success) {
|
|
269
|
-
const newData = await getBalance(apiKey);
|
|
270
|
-
balance = newData?.balance || balance;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
244
|
+
console.log(chalk.yellow(' Insufficient tokens. Run /earn to get more.'));
|
|
273
245
|
console.log();
|
|
274
|
-
|
|
246
|
+
showPrompt();
|
|
247
|
+
return;
|
|
275
248
|
}
|
|
276
249
|
spinner.stop();
|
|
277
250
|
// Show response (indented for visual hierarchy)
|
|
@@ -284,9 +257,20 @@ async function main() {
|
|
|
284
257
|
balance = Math.max(0, balance - result.tokensUsed);
|
|
285
258
|
console.log(chalk.dim(` ─ ${formatTokens(result.tokensUsed)} tokens · ${formatTokens(balance)} remaining`));
|
|
286
259
|
console.log();
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
260
|
+
showPrompt();
|
|
261
|
+
});
|
|
262
|
+
// Handle close
|
|
263
|
+
rl.on('close', () => {
|
|
264
|
+
console.log(chalk.dim('\n Goodbye.\n'));
|
|
265
|
+
process.exit(0);
|
|
266
|
+
});
|
|
267
|
+
// Handle Ctrl+C
|
|
268
|
+
rl.on('SIGINT', () => {
|
|
269
|
+
console.log(chalk.dim('\n\n Goodbye.\n'));
|
|
270
|
+
process.exit(0);
|
|
271
|
+
});
|
|
272
|
+
// Start
|
|
273
|
+
showPrompt();
|
|
290
274
|
}
|
|
291
275
|
// Run
|
|
292
276
|
main().catch((error) => {
|