@neuraiproject/neurai-depin-terminal 1.0.1 → 2.0.0
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/README.md +27 -8
- package/dist/index.cjs +143 -188
- package/package.json +11 -10
- package/src/config/ConfigManager.js +43 -26
- package/src/constants.js +18 -5
- package/src/domain/messageTypes.js +26 -0
- package/src/errors.js +17 -0
- package/src/index.js +129 -30
- package/src/messaging/MessagePoller.js +132 -3
- package/src/messaging/MessageSender.js +99 -41
- package/src/messaging/MessageStore.js +26 -0
- package/src/messaging/RecipientDirectory.js +186 -0
- package/src/ui/CharsmUI.js +690 -0
- package/src/ui/RecipientSelector.js +114 -0
- package/src/ui/TabManager.js +162 -0
- package/src/ui/render.js +173 -0
- package/src/utils.js +304 -43
- package/src/ui/TerminalUI.js +0 -272
- package/src/ui/components/ErrorOverlay.js +0 -99
- package/src/ui/components/InputBox.js +0 -63
- package/src/ui/components/MessageBox.js +0 -51
- package/src/ui/components/StatusBar.js +0 -32
- package/src/ui/components/TopBar.js +0 -63
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import blessed from 'blessed';
|
|
2
|
-
import { COLORS } from '../../constants.js';
|
|
3
|
-
|
|
4
|
-
export class ErrorOverlay {
|
|
5
|
-
constructor(screen) {
|
|
6
|
-
this.screen = screen;
|
|
7
|
-
this.timer = null;
|
|
8
|
-
this.timeLeft = 30;
|
|
9
|
-
this.currentErrors = [];
|
|
10
|
-
|
|
11
|
-
this.component = blessed.box({
|
|
12
|
-
top: 'center',
|
|
13
|
-
left: 'center',
|
|
14
|
-
width: '50%',
|
|
15
|
-
height: 'shrink',
|
|
16
|
-
content: '',
|
|
17
|
-
tags: true,
|
|
18
|
-
border: {
|
|
19
|
-
type: 'line'
|
|
20
|
-
},
|
|
21
|
-
style: {
|
|
22
|
-
fg: COLORS.FG_WHITE,
|
|
23
|
-
bg: COLORS.ERROR,
|
|
24
|
-
border: {
|
|
25
|
-
fg: COLORS.FG_WHITE
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
hidden: true
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
this.screen.append(this.component);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Show blocking error overlay
|
|
36
|
-
* @param {string[]} errors - List of error messages
|
|
37
|
-
*/
|
|
38
|
-
show(errors) {
|
|
39
|
-
if (!errors || errors.length === 0) {
|
|
40
|
-
this.hide();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.currentErrors = errors;
|
|
45
|
-
this.timeLeft = 30;
|
|
46
|
-
|
|
47
|
-
// Clear existing timer if any
|
|
48
|
-
if (this.timer) {
|
|
49
|
-
clearInterval(this.timer);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.updateContent();
|
|
53
|
-
this.component.show();
|
|
54
|
-
this.component.setFront();
|
|
55
|
-
this.screen.render();
|
|
56
|
-
|
|
57
|
-
// Start countdown
|
|
58
|
-
this.timer = setInterval(() => {
|
|
59
|
-
this.timeLeft--;
|
|
60
|
-
if (this.timeLeft < 0) this.timeLeft = 0;
|
|
61
|
-
this.updateContent();
|
|
62
|
-
}, 1000);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Update overlay content with current timer
|
|
67
|
-
*/
|
|
68
|
-
updateContent() {
|
|
69
|
-
const content = `\n{bold}CRITICAL ERRORS:{/bold}\n\n` +
|
|
70
|
-
this.currentErrors.map(e => `• ${e}`).join('\n\n') +
|
|
71
|
-
`\n\n{center}Retrying in ${this.timeLeft}s...{/center}\n`;
|
|
72
|
-
|
|
73
|
-
this.component.setContent(content);
|
|
74
|
-
this.screen.render();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Hide blocking error overlay
|
|
79
|
-
*/
|
|
80
|
-
hide() {
|
|
81
|
-
if (this.timer) {
|
|
82
|
-
clearInterval(this.timer);
|
|
83
|
-
this.timer = null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (!this.component.hidden) {
|
|
87
|
-
this.component.hide();
|
|
88
|
-
this.screen.render();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Check if overlay is visible
|
|
94
|
-
* @returns {boolean} True if visible
|
|
95
|
-
*/
|
|
96
|
-
isVisible() {
|
|
97
|
-
return !this.component.hidden;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import blessed from 'blessed';
|
|
2
|
-
import { UI, COLORS, KEY_CODES } from '../../constants.js';
|
|
3
|
-
|
|
4
|
-
export class InputBox {
|
|
5
|
-
constructor(screen, onSend) {
|
|
6
|
-
this.screen = screen;
|
|
7
|
-
this.onSend = onSend;
|
|
8
|
-
|
|
9
|
-
this.component = blessed.textarea({
|
|
10
|
-
bottom: UI.STATUS_BAR_HEIGHT,
|
|
11
|
-
left: 0,
|
|
12
|
-
width: '100%',
|
|
13
|
-
height: UI.INPUT_BOX_HEIGHT,
|
|
14
|
-
inputOnFocus: true,
|
|
15
|
-
keys: true,
|
|
16
|
-
style: {
|
|
17
|
-
fg: COLORS.FG_WHITE,
|
|
18
|
-
bg: COLORS.BG_BLACK,
|
|
19
|
-
border: {
|
|
20
|
-
fg: COLORS.BORDER
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
border: {
|
|
24
|
-
type: 'line'
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
this.setupEvents();
|
|
29
|
-
this.screen.append(this.component);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
setupEvents() {
|
|
33
|
-
this.component.key('enter', () => {
|
|
34
|
-
const message = this.component.getValue().trim();
|
|
35
|
-
if (message) {
|
|
36
|
-
this.onSend(message);
|
|
37
|
-
this.component.clearValue();
|
|
38
|
-
this.screen.render();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
focus() {
|
|
44
|
-
if (!this.disabled) {
|
|
45
|
-
this.component.focus();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
disable() {
|
|
50
|
-
this.disabled = true;
|
|
51
|
-
this.component.inputOnFocus = false;
|
|
52
|
-
// Optional: Change style to indicate disabled state
|
|
53
|
-
this.component.style.border.fg = 'gray';
|
|
54
|
-
this.screen.render();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
enable() {
|
|
58
|
-
this.disabled = false;
|
|
59
|
-
this.component.inputOnFocus = true;
|
|
60
|
-
this.component.style.border.fg = COLORS.BORDER;
|
|
61
|
-
this.screen.render();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import blessed from 'blessed';
|
|
2
|
-
import { UI, COLORS } from '../../constants.js';
|
|
3
|
-
|
|
4
|
-
export class MessageBox {
|
|
5
|
-
constructor(screen) {
|
|
6
|
-
this.screen = screen;
|
|
7
|
-
|
|
8
|
-
this.component = blessed.box({
|
|
9
|
-
top: UI.TOP_BAR_HEIGHT,
|
|
10
|
-
left: 0,
|
|
11
|
-
width: '100%',
|
|
12
|
-
height: `100%-${UI.MESSAGE_BOX_OFFSET}`,
|
|
13
|
-
scrollable: true,
|
|
14
|
-
alwaysScroll: true,
|
|
15
|
-
keys: true,
|
|
16
|
-
vi: true,
|
|
17
|
-
mouse: true,
|
|
18
|
-
tags: true,
|
|
19
|
-
scrollbar: {
|
|
20
|
-
ch: UI.SCROLLBAR_CHAR,
|
|
21
|
-
style: {
|
|
22
|
-
bg: COLORS.BG_BLUE
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
style: {
|
|
26
|
-
fg: COLORS.FG_WHITE,
|
|
27
|
-
bg: COLORS.BG_BLACK
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
this.screen.append(this.component);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
addMessage(formattedLine) {
|
|
35
|
-
const current = this.component.getContent();
|
|
36
|
-
const next = current && current.length > 0 ? `${current}\n${formattedLine}` : formattedLine;
|
|
37
|
-
this.component.setContent(next);
|
|
38
|
-
this.component.setScrollPerc(100);
|
|
39
|
-
this.screen.render();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
scrollUp() {
|
|
43
|
-
this.component.scroll(-1);
|
|
44
|
-
this.screen.render();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
scrollDown() {
|
|
48
|
-
this.component.scroll(1);
|
|
49
|
-
this.screen.render();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import blessed from 'blessed';
|
|
2
|
-
import { UI, COLORS } from '../../constants.js';
|
|
3
|
-
|
|
4
|
-
export class StatusBar {
|
|
5
|
-
constructor(screen) {
|
|
6
|
-
this.screen = screen;
|
|
7
|
-
|
|
8
|
-
this.component = blessed.box({
|
|
9
|
-
bottom: 0,
|
|
10
|
-
left: 0,
|
|
11
|
-
width: '100%',
|
|
12
|
-
height: UI.STATUS_BAR_HEIGHT,
|
|
13
|
-
content: ' Ready',
|
|
14
|
-
tags: true,
|
|
15
|
-
style: {
|
|
16
|
-
fg: COLORS.FG_WHITE,
|
|
17
|
-
bg: COLORS.BG_BLUE
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
this.screen.append(this.component);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
update(message, type = 'info') {
|
|
25
|
-
let color = COLORS.INFO;
|
|
26
|
-
if (type === 'error') color = COLORS.ERROR;
|
|
27
|
-
if (type === 'success') color = COLORS.SUCCESS;
|
|
28
|
-
|
|
29
|
-
this.component.setContent(` {${color}}${message}{/${color}}`);
|
|
30
|
-
this.screen.render();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import blessed from 'blessed';
|
|
2
|
-
import { UI, COLORS, ICONS } from '../../constants.js';
|
|
3
|
-
import { parseRpcHost, formatTimestamp } from '../../utils.js';
|
|
4
|
-
|
|
5
|
-
export class TopBar {
|
|
6
|
-
constructor(screen, config, myAddress) {
|
|
7
|
-
this.screen = screen;
|
|
8
|
-
this.config = config;
|
|
9
|
-
this.myAddress = myAddress;
|
|
10
|
-
this.totalMessages = 0;
|
|
11
|
-
this.encryptionType = 'N/A';
|
|
12
|
-
|
|
13
|
-
this.component = blessed.box({
|
|
14
|
-
top: 0,
|
|
15
|
-
left: 0,
|
|
16
|
-
width: '100%',
|
|
17
|
-
height: UI.TOP_BAR_HEIGHT,
|
|
18
|
-
content: 'Loading...',
|
|
19
|
-
tags: true,
|
|
20
|
-
style: {
|
|
21
|
-
fg: COLORS.FG_WHITE,
|
|
22
|
-
bg: COLORS.BG_BLUE
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
this.screen.append(this.component);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
update(status) {
|
|
30
|
-
const rpcUrl = parseRpcHost(this.config.rpc_url);
|
|
31
|
-
const connectedIndicator = status.connected ?
|
|
32
|
-
`{${COLORS.CONNECTED}}${ICONS.CONNECTED}{/${COLORS.CONNECTED}}` :
|
|
33
|
-
`{${COLORS.DISCONNECTED}}${ICONS.DISCONNECTED}{/${COLORS.DISCONNECTED}}`;
|
|
34
|
-
|
|
35
|
-
const lastPollStr = status.lastPoll ?
|
|
36
|
-
formatTimestamp(status.lastPoll, this.config.timezone) :
|
|
37
|
-
'--:--:--';
|
|
38
|
-
|
|
39
|
-
// Format timezone display
|
|
40
|
-
let timezoneDisplay = this.config.timezone || 'UTC';
|
|
41
|
-
if (timezoneDisplay !== 'UTC') {
|
|
42
|
-
if (!timezoneDisplay.startsWith('+') && !timezoneDisplay.startsWith('-')) {
|
|
43
|
-
timezoneDisplay = `+${timezoneDisplay}`;
|
|
44
|
-
}
|
|
45
|
-
timezoneDisplay = `UTC${timezoneDisplay}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.component.setContent(
|
|
49
|
-
`Neurai DePIN | ${connectedIndicator} RPC: ${rpcUrl} | Token: ${this.config.token} | Time: ${timezoneDisplay}\n` +
|
|
50
|
-
`Address: ${this.myAddress} | Total: ${this.totalMessages} | Encryption: ${this.encryptionType} | Last poll: ${lastPollStr}`
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
this.screen.render();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setTotalMessages(count) {
|
|
57
|
-
this.totalMessages = count;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setEncryptionType(type) {
|
|
61
|
-
this.encryptionType = type;
|
|
62
|
-
}
|
|
63
|
-
}
|