squidclaw 0.6.0 → 0.6.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/lib/channels/hub.js +44 -1
- package/lib/engine.js +31 -1
- package/package.json +1 -1
package/lib/channels/hub.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
import { logger } from '../core/logger.js';
|
|
7
7
|
|
|
8
8
|
export class ChannelHub {
|
|
9
|
-
constructor(agentManager, whatsappManager, storage) {
|
|
9
|
+
constructor(agentManager, whatsappManager, storage, telegramManager) {
|
|
10
10
|
this.agentManager = agentManager;
|
|
11
11
|
this.whatsappManager = whatsappManager;
|
|
12
12
|
this.storage = storage;
|
|
13
|
+
this.telegramManager = telegramManager || null;
|
|
13
14
|
|
|
14
15
|
// Wire up WhatsApp message handler
|
|
15
16
|
this.whatsappManager.onMessage = this._handleWhatsAppMessage.bind(this);
|
|
@@ -42,6 +43,41 @@ export class ChannelHub {
|
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
// Handle /status command
|
|
47
|
+
if (message.trim() === '/status' || message.trim().toLowerCase() === 'status') {
|
|
48
|
+
const uptime = process.uptime();
|
|
49
|
+
const h = Math.floor(uptime / 3600);
|
|
50
|
+
const m = Math.floor((uptime % 3600) / 60);
|
|
51
|
+
const usage = await this.storage.getUsage(agentId) || {};
|
|
52
|
+
const convos = await this.storage.getConversationCount?.(agentId) || 0;
|
|
53
|
+
const config = agent.config || {};
|
|
54
|
+
|
|
55
|
+
const status = [
|
|
56
|
+
'🦑 *' + (agent.name || agentId) + ' Status*',
|
|
57
|
+
'────────────────────',
|
|
58
|
+
'🧠 Model: ' + (agent.model || 'unknown'),
|
|
59
|
+
'⏱️ Uptime: ' + h + 'h ' + m + 'm',
|
|
60
|
+
'💬 Messages: ' + (usage.messages || 0),
|
|
61
|
+
'🪙 Tokens: ' + formatTokens((usage.input_tokens || 0) + (usage.output_tokens || 0)),
|
|
62
|
+
'💰 Cost: $' + (usage.cost_usd || 0).toFixed(4),
|
|
63
|
+
'────────────────────',
|
|
64
|
+
'📱 WhatsApp: ' + (metadata.platform === 'whatsapp' ? '✅ connected' : '—'),
|
|
65
|
+
'✈️ Telegram: ' + (metadata.platform === 'telegram' ? '✅ connected' : '—'),
|
|
66
|
+
'────────────────────',
|
|
67
|
+
'⚡ Skills: web search, page reader, vision, voice, memory',
|
|
68
|
+
'🗣️ Language: ' + (agent.language || 'bilingual'),
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
if (metadata.platform === 'telegram' || metadata._ctx) {
|
|
73
|
+
await this.telegramManager?.sendMessage(agentId, contactId, status.join('\n'), metadata);
|
|
74
|
+
} else {
|
|
75
|
+
await this.whatsappManager?.sendMessage(agentId, contactId, status.join('\n'));
|
|
76
|
+
}
|
|
77
|
+
} catch {}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
45
81
|
// Process message through agent
|
|
46
82
|
const result = await agent.processMessage(contactId, message, metadata);
|
|
47
83
|
|
|
@@ -101,3 +137,10 @@ export class ChannelHub {
|
|
|
101
137
|
}
|
|
102
138
|
}
|
|
103
139
|
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
function formatTokens(n) {
|
|
143
|
+
if (n >= 1000000) return (n / 1000000).toFixed(1) + 'M';
|
|
144
|
+
if (n >= 1000) return (n / 1000).toFixed(1) + 'K';
|
|
145
|
+
return String(n);
|
|
146
|
+
}
|
package/lib/engine.js
CHANGED
|
@@ -93,6 +93,36 @@ export class SquidclawEngine {
|
|
|
93
93
|
if (!allowed) return;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// Handle /status command
|
|
97
|
+
if (message.trim() === '/status' || message.trim().toLowerCase() === 'status') {
|
|
98
|
+
const uptime = process.uptime();
|
|
99
|
+
const h = Math.floor(uptime / 3600);
|
|
100
|
+
const m = Math.floor((uptime % 3600) / 60);
|
|
101
|
+
const usage = await this.storage.getUsage(agentId) || {};
|
|
102
|
+
const tokens = (usage.input_tokens || 0) + (usage.output_tokens || 0);
|
|
103
|
+
const fmtT = tokens >= 1000000 ? (tokens/1000000).toFixed(1)+'M' : tokens >= 1000 ? (tokens/1000).toFixed(1)+'K' : String(tokens);
|
|
104
|
+
const waOn = Object.values(this.whatsappManager?.getStatuses() || {}).some(s => s.connected);
|
|
105
|
+
|
|
106
|
+
const lines = [
|
|
107
|
+
`🦑 *${agent.name || agentId} Status*`,
|
|
108
|
+
'────────────────────',
|
|
109
|
+
`🧠 Model: ${agent.model || 'unknown'}`,
|
|
110
|
+
`⏱️ Uptime: ${h}h ${m}m`,
|
|
111
|
+
`💬 Messages: ${usage.messages || 0}`,
|
|
112
|
+
`🪙 Tokens: ${fmtT}`,
|
|
113
|
+
`💰 Cost: $${(usage.cost_usd || 0).toFixed(4)}`,
|
|
114
|
+
'────────────────────',
|
|
115
|
+
`📱 WhatsApp: ${waOn ? '✅' : '❌'}`,
|
|
116
|
+
'✈️ Telegram: ✅ connected',
|
|
117
|
+
'────────────────────',
|
|
118
|
+
'⚡ Skills: search, reader, vision, voice, memory',
|
|
119
|
+
`🗣️ Language: ${agent.language || 'bilingual'}`,
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
await this.telegramManager.sendMessage(agentId, contactId, lines.join('\n'), metadata);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
96
126
|
const result = await agent.processMessage(contactId, message, metadata);
|
|
97
127
|
|
|
98
128
|
if (result.reaction && metadata.messageId) {
|
|
@@ -138,7 +168,7 @@ export class SquidclawEngine {
|
|
|
138
168
|
console.log(` 📱 WhatsApp: ${connected}/${agents.length} connected`);
|
|
139
169
|
|
|
140
170
|
// 5. Channel Hub
|
|
141
|
-
this.channelHub = new ChannelHub(this.agentManager, this.whatsappManager, this.storage);
|
|
171
|
+
this.channelHub = new ChannelHub(this.agentManager, this.whatsappManager, this.storage, this.telegramManager);
|
|
142
172
|
addMediaSupport(this.channelHub, this.config, this.home);
|
|
143
173
|
|
|
144
174
|
// 6. Heartbeat
|