blun-king-cli 6.3.3 → 6.3.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/bin/blun.js
CHANGED
|
@@ -115,7 +115,7 @@ async function main() {
|
|
|
115
115
|
try {
|
|
116
116
|
const res = await client.sendMessage(question);
|
|
117
117
|
ui.stopSpinner(true);
|
|
118
|
-
const text = (res.data && (res.data.response || res.data.text || res.data.message)) || JSON.stringify(res.data);
|
|
118
|
+
const text = (res.data && (res.data.answer || res.data.response || res.data.text || res.data.message)) || JSON.stringify(res.data);
|
|
119
119
|
ui.renderResponse(text, "agent");
|
|
120
120
|
} catch (e) {
|
|
121
121
|
ui.stopSpinner(false);
|
|
@@ -181,4 +181,4 @@ async function main() {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
main().catch((e) => { console.error("Fatal:", e.message); process.exit(1); });
|
|
184
|
+
main().then(() => { process.exit(0); }).catch((e) => { console.error("Fatal:", e.message); process.exit(1); });
|
package/lib/auth.js
CHANGED
|
@@ -5,7 +5,6 @@ const https = require('https');
|
|
|
5
5
|
const readline = require('readline');
|
|
6
6
|
const chalk = require('chalk');
|
|
7
7
|
const inquirer = require('inquirer');
|
|
8
|
-
const inquirer = require("inquirer");
|
|
9
8
|
|
|
10
9
|
const CREDS_DIR = path.join(os.homedir(), '.blun');
|
|
11
10
|
const CREDS_FILE = path.join(CREDS_DIR, 'credentials.json');
|
|
@@ -42,17 +41,15 @@ function ensureAuth() {
|
|
|
42
41
|
return getStoredCredentials();
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
function httpsRequest(options, body) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (body) req.write(JSON.stringify(body)); req.end();
|
|
55
|
-
});
|
|
44
|
+
async function httpsRequest(options, body) {
|
|
45
|
+
const url = 'https://' + (options.hostname || BASE_URL) + options.path;
|
|
46
|
+
const fetchOpts = { method: options.method || 'GET', headers: options.headers || {} };
|
|
47
|
+
if (body) { fetchOpts.body = JSON.stringify(body); }
|
|
48
|
+
const res = await fetch(url, fetchOpts);
|
|
49
|
+
let data;
|
|
50
|
+
const text = await res.text();
|
|
51
|
+
try { data = JSON.parse(text); } catch { data = text; }
|
|
52
|
+
return { status: res.status, data };
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
function prompt(question) {
|
|
@@ -81,19 +78,19 @@ function promptPassword(question) {
|
|
|
81
78
|
});
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
async function promptMenu(title,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return
|
|
81
|
+
async function promptMenu(title, choices) {
|
|
82
|
+
const { answer } = await inquirer.prompt([{
|
|
83
|
+
type: 'list',
|
|
84
|
+
name: 'answer',
|
|
85
|
+
message: title,
|
|
86
|
+
choices: choices.map(c => ({ name: c.label, value: c.value }))
|
|
87
|
+
}]);
|
|
88
|
+
return answer;
|
|
92
89
|
}
|
|
93
90
|
async function login() {
|
|
94
91
|
console.log(chalk.bold.cyan('\n BLUN Login\n'));
|
|
95
|
-
const email = await prompt(
|
|
96
|
-
const password = await
|
|
92
|
+
const { email } = await inquirer.prompt([{ type: 'input', name: 'email', message: 'Email:' }]);
|
|
93
|
+
const { password } = await inquirer.prompt([{ type: 'password', name: 'password', message: 'Password:', mask: '*' }]);
|
|
97
94
|
if (!email || !password) throw new Error('Email and password required.');
|
|
98
95
|
const res = await httpsRequest({
|
|
99
96
|
hostname: BASE_URL, path: '/api/king/auth/login',
|
|
@@ -114,9 +111,9 @@ async function login() {
|
|
|
114
111
|
|
|
115
112
|
async function register() {
|
|
116
113
|
console.log(chalk.bold.cyan('\n BLUN Registration\n'));
|
|
117
|
-
const name = await prompt(
|
|
118
|
-
const email = await prompt(
|
|
119
|
-
const password = await
|
|
114
|
+
const { name } = await inquirer.prompt([{ type: 'input', name: 'name', message: 'Name:' }]);
|
|
115
|
+
const { email } = await inquirer.prompt([{ type: 'input', name: 'email', message: 'Email:' }]);
|
|
116
|
+
const { password } = await inquirer.prompt([{ type: 'password', name: 'password', message: 'Password:', mask: '*' }]);
|
|
120
117
|
if (!email || !password || !name) throw new Error('Name, email and password required.');
|
|
121
118
|
const res = await httpsRequest({
|
|
122
119
|
hostname: BASE_URL, path: '/api/king/auth/register',
|
package/lib/chat.js
CHANGED
|
@@ -10,14 +10,20 @@ async function startChat() {
|
|
|
10
10
|
ui.renderBanner();
|
|
11
11
|
|
|
12
12
|
if (!auth.isAuthenticated()) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
try {
|
|
14
|
+
const result = await auth.showWelcomeMenu();
|
|
15
|
+
if (result === 'local') localMode = true;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.log(chalk.red('\n ' + e.message));
|
|
18
|
+
console.log(chalk.yellow(' Trying again...\n'));
|
|
19
|
+
try {
|
|
20
|
+
const retry = await auth.showWelcomeMenu();
|
|
21
|
+
if (retry === 'local') localMode = true;
|
|
22
|
+
} catch (e2) {
|
|
23
|
+
console.log(chalk.red('\n ' + e2.message));
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
|
-
if (result === 'local') localMode = true;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
const creds = auth.getStoredCredentials();
|
|
@@ -38,6 +44,7 @@ async function startChat() {
|
|
|
38
44
|
console.log(' Type /help for commands, /exit to quit.\n');
|
|
39
45
|
rl.prompt();
|
|
40
46
|
|
|
47
|
+
return new Promise((resolveChat) => {
|
|
41
48
|
rl.on('line', async (line) => {
|
|
42
49
|
const input = line.trim();
|
|
43
50
|
if (!input) { rl.prompt(); return; }
|
|
@@ -123,7 +130,7 @@ async function startChat() {
|
|
|
123
130
|
const res = await client.sendMessage(input, { model: settings.model || 'auto' });
|
|
124
131
|
ui.stopSpinner(true, 'Response received');
|
|
125
132
|
if (res.status === 200 && res.data) {
|
|
126
|
-
const text = res.data.response || res.data.text || res.data.message || JSON.stringify(res.data);
|
|
133
|
+
const text = res.data.answer || res.data.response || res.data.text || res.data.message || JSON.stringify(res.data);
|
|
127
134
|
ui.renderResponse(text, 'agent');
|
|
128
135
|
if (res.data.usage) ui.addTokens(res.data.usage.total_tokens || 0, 0.000003);
|
|
129
136
|
} else if (res.status === 401 || res.status === 403) {
|
|
@@ -138,7 +145,8 @@ async function startChat() {
|
|
|
138
145
|
rl.prompt();
|
|
139
146
|
});
|
|
140
147
|
|
|
141
|
-
rl.on('close', () => { console.log('');
|
|
148
|
+
rl.on('close', () => { console.log(''); resolveChat(); });
|
|
149
|
+
});
|
|
142
150
|
}
|
|
143
151
|
|
|
144
152
|
module.exports = { startChat };
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# 1.0.0 - 2016-01-07
|
|
2
|
-
|
|
3
|
-
- Removed: unused speed test
|
|
4
|
-
- Added: Automatic routing between previously unsupported conversions
|
|
5
|
-
([#27](https://github.com/Qix-/color-convert/pull/27))
|
|
6
|
-
- Removed: `xxx2xxx()` and `xxx2xxxRaw()` functions
|
|
7
|
-
([#27](https://github.com/Qix-/color-convert/pull/27))
|
|
8
|
-
- Removed: `convert()` class
|
|
9
|
-
([#27](https://github.com/Qix-/color-convert/pull/27))
|
|
10
|
-
- Changed: all functions to lookup dictionary
|
|
11
|
-
([#27](https://github.com/Qix-/color-convert/pull/27))
|
|
12
|
-
- Changed: `ansi` to `ansi256`
|
|
13
|
-
([#27](https://github.com/Qix-/color-convert/pull/27))
|
|
14
|
-
- Fixed: argument grouping for functions requiring only one argument
|
|
15
|
-
([#27](https://github.com/Qix-/color-convert/pull/27))
|
|
16
|
-
|
|
17
|
-
# 0.6.0 - 2015-07-23
|
|
18
|
-
|
|
19
|
-
- Added: methods to handle
|
|
20
|
-
[ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) 16/256 colors:
|
|
21
|
-
- rgb2ansi16
|
|
22
|
-
- rgb2ansi
|
|
23
|
-
- hsl2ansi16
|
|
24
|
-
- hsl2ansi
|
|
25
|
-
- hsv2ansi16
|
|
26
|
-
- hsv2ansi
|
|
27
|
-
- hwb2ansi16
|
|
28
|
-
- hwb2ansi
|
|
29
|
-
- cmyk2ansi16
|
|
30
|
-
- cmyk2ansi
|
|
31
|
-
- keyword2ansi16
|
|
32
|
-
- keyword2ansi
|
|
33
|
-
- ansi162rgb
|
|
34
|
-
- ansi162hsl
|
|
35
|
-
- ansi162hsv
|
|
36
|
-
- ansi162hwb
|
|
37
|
-
- ansi162cmyk
|
|
38
|
-
- ansi162keyword
|
|
39
|
-
- ansi2rgb
|
|
40
|
-
- ansi2hsl
|
|
41
|
-
- ansi2hsv
|
|
42
|
-
- ansi2hwb
|
|
43
|
-
- ansi2cmyk
|
|
44
|
-
- ansi2keyword
|
|
45
|
-
([#18](https://github.com/harthur/color-convert/pull/18))
|
|
46
|
-
|
|
47
|
-
# 0.5.3 - 2015-06-02
|
|
48
|
-
|
|
49
|
-
- Fixed: hsl2hsv does not return `NaN` anymore when using `[0,0,0]`
|
|
50
|
-
([#15](https://github.com/harthur/color-convert/issues/15))
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
Check out commit logs for older releases
|