neoagent 2.0.4 → 2.0.6

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.
@@ -137,12 +137,30 @@ function ingestHealthSync(userId, body = {}) {
137
137
  return ingestHealthSyncTx(userId, body);
138
138
  }
139
139
 
140
+ function hydrateRun(row) {
141
+ if (!row) return null;
142
+ return {
143
+ ...row,
144
+ summary: (() => {
145
+ try { return JSON.parse(row.summary_json || '{}'); } catch { return {}; }
146
+ })(),
147
+ };
148
+ }
149
+
140
150
  function getHealthSyncStatus(userId) {
141
151
  const lastRun = db.prepare(`
142
152
  SELECT id, source, provider, sync_window_start, sync_window_end, record_count, summary_json, created_at
143
153
  FROM health_sync_runs
144
154
  WHERE user_id = ?
145
- ORDER BY created_at DESC
155
+ ORDER BY created_at DESC, rowid DESC
156
+ LIMIT 1
157
+ `).get(userId);
158
+
159
+ const lastNonEmptyRun = db.prepare(`
160
+ SELECT id, source, provider, sync_window_start, sync_window_end, record_count, summary_json, created_at
161
+ FROM health_sync_runs
162
+ WHERE user_id = ? AND record_count > 0
163
+ ORDER BY created_at DESC, rowid DESC
146
164
  LIMIT 1
147
165
  `).get(userId);
148
166
 
@@ -155,12 +173,8 @@ function getHealthSyncStatus(userId) {
155
173
  `).all(userId);
156
174
 
157
175
  return {
158
- lastRun: lastRun ? {
159
- ...lastRun,
160
- summary: (() => {
161
- try { return JSON.parse(lastRun.summary_json || '{}'); } catch { return {}; }
162
- })(),
163
- } : null,
176
+ lastRun: hydrateRun(lastRun),
177
+ lastNonEmptyRun: hydrateRun(lastNonEmptyRun),
164
178
  metrics: metrics.map((metric) => ({
165
179
  metricType: metric.metric_type,
166
180
  sampleCount: Number(metric.sample_count || 0),
@@ -180,8 +180,7 @@ async function isAllowedMessagingSender({ io, userId, msg }) {
180
180
  }
181
181
  }
182
182
 
183
- const enforceEmptyWhitelist = msg.platform === 'whatsapp';
184
- const shouldCheckWhitelist = whitelist.length > 0 || enforceEmptyWhitelist;
183
+ const shouldCheckWhitelist = whitelist.length > 0;
185
184
 
186
185
  if (!shouldCheckWhitelist) {
187
186
  return true;
@@ -196,11 +195,22 @@ async function isAllowedMessagingSender({ io, userId, msg }) {
196
195
  console.log(
197
196
  `[Messaging] Blocked ${msg.platform} message from ${msg.sender} (not in whitelist)`
198
197
  );
198
+ const suggestions = [];
199
+ if (msg.platform === 'whatsapp') {
200
+ const normalizedSender = normalizeWhatsAppId(msg.sender || msg.chatId);
201
+ if (normalizedSender) {
202
+ suggestions.push({
203
+ label: `Add sender (${msg.senderName || normalizedSender})`,
204
+ prefixedId: normalizedSender
205
+ });
206
+ }
207
+ }
199
208
  io.to(`user:${userId}`).emit('messaging:blocked_sender', {
200
209
  platform: msg.platform,
201
210
  sender: msg.sender,
202
211
  chatId: msg.chatId,
203
- senderName: msg.senderName || null
212
+ senderName: msg.senderName || null,
213
+ suggestions: suggestions.length > 0 ? suggestions : null
204
214
  });
205
215
  return false;
206
216
  }
@@ -65,6 +65,30 @@ class DiscordPlatform extends BasePlatform {
65
65
 
66
66
  this._client.once('error', (err) => { clearTimeout(timeout); reject(err); });
67
67
  this._client.on('error', (err) => console.error('[Discord] Client error:', err.message));
68
+ this._client.on('shardDisconnect', (event, shardId) => {
69
+ this.status = 'disconnected';
70
+ console.warn(`[Discord] Shard ${shardId} disconnected (${event?.code || 'unknown'})`);
71
+ this.emit('disconnected', {
72
+ manual: false,
73
+ shardId,
74
+ code: event?.code || null,
75
+ reason: event?.reason || null,
76
+ });
77
+ });
78
+ this._client.on('shardReconnecting', (shardId) => {
79
+ this.status = 'connecting';
80
+ console.log(`[Discord] Shard ${shardId} reconnecting`);
81
+ });
82
+ this._client.on('shardResume', (_replayedEvents, shardId) => {
83
+ this.status = 'connected';
84
+ console.log(`[Discord] Shard ${shardId} resumed`);
85
+ this.emit('connected');
86
+ });
87
+ this._client.on('invalidated', () => {
88
+ this.status = 'logged_out';
89
+ console.warn('[Discord] Session invalidated');
90
+ this.emit('logged_out');
91
+ });
68
92
  this._client.on('messageCreate', (msg) => this._handleMessage(msg));
69
93
 
70
94
  this._client.login(this.token).catch((err) => { clearTimeout(timeout); reject(err); });
@@ -88,8 +112,11 @@ class DiscordPlatform extends BasePlatform {
88
112
 
89
113
  /** Returns {allowed, requireMention} */
90
114
  _checkAccess(message) {
91
- // Empty whitelist: block everyone (add via the allow popup)
92
- if (this.allowedEntries.size === 0) return { allowed: false, requireMention: false };
115
+ // Default behavior with no allow-list: respond in DMs and require a mention in guilds.
116
+ if (this.allowedEntries.size === 0) {
117
+ const isDM = message.channel.type === ChannelType.DM;
118
+ return { allowed: true, requireMention: !isDM };
119
+ }
93
120
 
94
121
  // Check prefixed entries
95
122
  const userId = message.author.id;
@@ -86,8 +86,10 @@ class TelegramPlatform extends BasePlatform {
86
86
  _checkAccess(msg) {
87
87
  const userId = String(msg.from.id);
88
88
  const chatId = String(msg.chat.id); // negative for groups
89
+ const isPrivate = msg.chat.type === 'private';
89
90
 
90
- if (this.allowedEntries.size === 0) return { allowed: false, requireMention: false };
91
+ // Default behavior with no allow-list: respond in private chats and require @mention in groups.
92
+ if (this.allowedEntries.size === 0) return { allowed: true, requireMention: !isPrivate };
91
93
 
92
94
  if (super._checkAccess(`user:${userId}`)) return { allowed: true, requireMention: false };
93
95
  if (super._checkAccess(userId)) return { allowed: true, requireMention: false }; // legacy