novaprime 1.2.9 → 1.3.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/package.json +1 -1
- package/src/agent.js +1 -1
- package/src/prompt.js +27 -53
package/package.json
CHANGED
package/src/agent.js
CHANGED
|
@@ -36,7 +36,7 @@ async function streamMessage(server, key, messages) {
|
|
|
36
36
|
res = await fetch(server.replace(/\/$/, '') + '/v1/messages', {
|
|
37
37
|
method: 'POST',
|
|
38
38
|
headers: { 'content-type': 'application/json', 'x-novaprime-key': key },
|
|
39
|
-
body: JSON.stringify({ max_tokens:
|
|
39
|
+
body: JSON.stringify({ max_tokens: 8192, system: SYSTEM_PROMPT, tools: tools.definitions, messages, stream: true }),
|
|
40
40
|
});
|
|
41
41
|
} catch (err) { stopSpin(); return { error: 'Could not reach NovaPrime: ' + err.message }; }
|
|
42
42
|
|
package/src/prompt.js
CHANGED
|
@@ -1,66 +1,40 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const
|
|
2
|
+
const readline = require('readline');
|
|
3
|
+
|
|
4
|
+
// Use Node's readline — it correctly handles long lines, wrapping, editing and paste.
|
|
5
|
+
let rl = null;
|
|
6
|
+
function getRl() {
|
|
7
|
+
if (!rl) {
|
|
8
|
+
rl = readline.createInterface({ input: process.stdin, output: process.stdout, historySize: 200 });
|
|
9
|
+
rl.on('SIGINT', () => { try { process.stdout.write('\n'); } catch (_) {} process.exit(0); });
|
|
10
|
+
}
|
|
11
|
+
return rl;
|
|
12
|
+
}
|
|
3
13
|
|
|
4
|
-
|
|
5
|
-
// and (unlike readline) never clears the lines below — so a box border stays visible.
|
|
6
|
-
function readRaw(prompt, opts = {}) {
|
|
14
|
+
function ask(prompt) {
|
|
7
15
|
return new Promise((resolve) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
// Non-TTY fallback (piped / one-shot): just read a line.
|
|
11
|
-
if (!stdin.isTTY) {
|
|
12
|
-
stdin.resume(); stdin.setEncoding('utf8');
|
|
13
|
-
let acc = '';
|
|
14
|
-
const onData = (d) => {
|
|
15
|
-
acc += d;
|
|
16
|
-
const nl = acc.indexOf('\n');
|
|
17
|
-
if (nl >= 0) { stdin.removeListener('data', onData); stdin.pause(); resolve(acc.slice(0, nl).replace(/\r$/, '')); }
|
|
18
|
-
};
|
|
19
|
-
stdin.on('data', onData);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let buf = '';
|
|
24
|
-
if (opts.draw) opts.draw();
|
|
25
|
-
stdin.setRawMode(true); stdin.resume(); stdin.setEncoding('utf8');
|
|
26
|
-
const redraw = () => stdout.write('\r' + ESC + '[2K' + prompt + buf);
|
|
27
|
-
redraw();
|
|
28
|
-
|
|
29
|
-
const done = (val) => {
|
|
30
|
-
stdin.setRawMode(false); stdin.pause(); stdin.removeListener('data', onData);
|
|
31
|
-
if (opts.after) opts.after();
|
|
32
|
-
resolve(val);
|
|
33
|
-
};
|
|
34
|
-
function onData(s) {
|
|
35
|
-
let i = 0;
|
|
36
|
-
while (i < s.length) {
|
|
37
|
-
const ch = s[i], code = s.charCodeAt(i);
|
|
38
|
-
if (ch === '\r' || ch === '\n') { return done(buf); }
|
|
39
|
-
if (code === 3) { stdin.setRawMode(false); stdout.write('\n'); process.exit(0); } // Ctrl+C
|
|
40
|
-
if (code === 4) { return done(buf.length ? buf : null); } // Ctrl+D
|
|
41
|
-
if (code === 127 || code === 8) { buf = buf.slice(0, -1); redraw(); i++; continue; } // backspace
|
|
42
|
-
if (code === 27) { i += (s[i + 1] === '[') ? 3 : 1; continue; } // skip arrow/escape seq
|
|
43
|
-
if (code < 32) { i++; continue; }
|
|
44
|
-
buf += ch; redraw(); i++;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
stdin.on('data', onData);
|
|
16
|
+
const r = getRl();
|
|
17
|
+
r.question(prompt || '', (answer) => resolve(answer));
|
|
48
18
|
});
|
|
49
19
|
}
|
|
50
20
|
|
|
51
|
-
function
|
|
52
|
-
|
|
21
|
+
function confirm(message) {
|
|
22
|
+
return ask(message + ' (y/N) ').then((a) => /^y(es)?$/i.test((a || '').trim()));
|
|
23
|
+
}
|
|
53
24
|
|
|
54
|
-
//
|
|
25
|
+
// Chat input: top border above (safe), readline handles the input line,
|
|
26
|
+
// and the bottom border is drawn AFTER submit so the message shows as a complete box.
|
|
55
27
|
function boxInput(top, bottom, prompt) {
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
process.stdout.write(top + '\n');
|
|
30
|
+
const r = getRl();
|
|
31
|
+
r.question(prompt, (answer) => {
|
|
32
|
+
process.stdout.write(bottom + '\n');
|
|
33
|
+
resolve(answer);
|
|
34
|
+
});
|
|
59
35
|
});
|
|
60
36
|
}
|
|
61
37
|
|
|
62
|
-
function close() {
|
|
63
|
-
try { if (process.stdin.isTTY) process.stdin.setRawMode(false); process.stdin.pause(); } catch (_) {}
|
|
64
|
-
}
|
|
38
|
+
function close() { if (rl) { rl.close(); rl = null; } }
|
|
65
39
|
|
|
66
40
|
module.exports = { ask, confirm, boxInput, close };
|