diff options
Diffstat (limited to 'modules/core/module-debug-supervisor.js')
| -rw-r--r-- | modules/core/module-debug-supervisor.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/modules/core/module-debug-supervisor.js b/modules/core/module-debug-supervisor.js index 79c9acc..25e0566 100644 --- a/modules/core/module-debug-supervisor.js +++ b/modules/core/module-debug-supervisor.js @@ -134,6 +134,7 @@ class DebugSupervisorModule { const err = new Error((j && j.error) || ('HTTP ' + resp.status)); err.status = resp.status; err.code = (j && j.code) || ''; + err.retryAfterMs = (j && j.retry_after_ms) || null; throw err; } const st = { token: token, cursor: j.epoch || 0, thread: j.thread || '' }; @@ -141,7 +142,7 @@ class DebugSupervisorModule { return j; } - _chatPoll(force) { + _chatPoll(force, silent) { const st = this._chatThread(); const token = st.token; if (!token) return Promise.resolve(null); @@ -162,7 +163,7 @@ class DebugSupervisorModule { if ((m.epoch || 0) > (this._chatThread().cursor || 0)) { this._chatSaveState({ token: token, cursor: m.epoch || 0, thread: j.thread || '' }); } - if (m.author === 'hermes') this.terminal.print('π€ ' + m.text, ''); + if (m.author === 'hermes' && !silent) this.terminal.print('π€ ' + m.text, ''); }); return j; }) @@ -961,7 +962,7 @@ class DebugSupervisorModule { _cmdFeedback(args) { const msg = (Array.isArray(args) ? args.join(' ') : String(args || '')).trim(); if (!msg) { - this.terminal.print('usage: feedback <message> (alias: chat <message>)', 'error'); + this.terminal.print('usage: hermes <message> (alias: feedback <message>)', 'error'); return; } this.terminal.print('π¨ Sendingβ¦', ''); @@ -971,9 +972,10 @@ class DebugSupervisorModule { ' β reply arrives here; `hermes-poll` to check now', 'success')) .catch(e => { // 503 is nginx's limit_req, not ours: it arrives as HTML, so status is all we have. - const hint = e.status === 429 ? ' (rate limited β retry later)' + const wait = e.retryAfterMs ? ' in ' + Math.ceil(e.retryAfterMs / 1000) + 's' : ' later'; + const hint = e.status === 429 ? ' (rate limited β retry' + wait + ')' : e.status === 503 ? ' (host busy β retry)' - : e.status === 401 ? ' (bad token β try chat-reset)' + : e.status === 401 ? ' (bad token β try hermes-reset)' : ''; this.terminal.print('β ' + e.message + hint, 'error'); }); @@ -981,10 +983,15 @@ class DebugSupervisorModule { _cmdFeedbackInbox() { this.terminal.print('π¬ Checkingβ¦', ''); + // _chatPoll prints the π€ lines (once); this loop skips hermes so it is not shown + // twice. Making the poll silent instead would print the reply nowhere. this._chatPoll(true).then(j => { if (!j) { this.terminal.print('β no answer from the chat endpoint', 'error'); return; } - const msgs = j.messages || []; - if (!msgs.length) this.terminal.print('(no new messages)', 'info'); + const incoming = j.messages || []; + // hermes lines were already printed by the poll above; only count them as + // 'new' so the box does not say "no new messages" right under a new one + const msgs = incoming.filter(m => m.author !== 'hermes'); + if (!incoming.length) this.terminal.print('(no new messages)', 'info'); msgs.forEach(m => this.terminal.print( (m.author === 'hermes' ? 'π€ ' : m.author === 'agent' ? 'π§ ' : 'π€ ') + m.text, '')); if (j.awaiting) this.terminal.print('β³ waiting for Hermes', 'info'); |