neoagent 2.5.2-beta.2 → 2.5.2-beta.4

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.
@@ -9,6 +9,7 @@ const {
9
9
  normalizeOutgoingMessageForPlatform,
10
10
  } = require('../messaging/formatting_guides');
11
11
  const { INTERIM_KINDS, normalizeInterimKind } = require('./interim');
12
+ const { normalizeWhatsAppId } = require('../../utils/whatsapp');
12
13
  const {
13
14
  executeIntegratedTool,
14
15
  getIntegratedToolDefinitions,
@@ -320,6 +321,31 @@ function normalizeMessagingTarget(target = {}) {
320
321
  return { platform, to };
321
322
  }
322
323
 
324
+ function canonicalMessagingAddress(platform, value) {
325
+ const normalizedPlatform = String(platform || '').trim().toLowerCase();
326
+ const raw = String(value || '').trim();
327
+ if (!normalizedPlatform || !raw) return '';
328
+ if (normalizedPlatform !== 'whatsapp') return raw;
329
+
330
+ const lower = raw.toLowerCase();
331
+ const normalizedId = normalizeWhatsAppId(lower);
332
+ if (!normalizedId) return '';
333
+ if (lower.includes('@g.us')) return `group:${normalizedId}`;
334
+ if (lower.includes('@lid')) return `lid:${normalizedId}`;
335
+ return `direct:${normalizedId}`;
336
+ }
337
+
338
+ function isOriginMessagingDelivery({ triggerSource, source, chatId, platform, to }) {
339
+ if (triggerSource !== 'messaging') return true;
340
+ const originPlatform = String(source || '').trim().toLowerCase();
341
+ const targetPlatform = String(platform || '').trim().toLowerCase();
342
+ if (!originPlatform || !targetPlatform || originPlatform !== targetPlatform) return false;
343
+
344
+ const originAddress = canonicalMessagingAddress(originPlatform, chatId);
345
+ const targetAddress = canonicalMessagingAddress(targetPlatform, to);
346
+ return Boolean(originAddress && targetAddress && originAddress === targetAddress);
347
+ }
348
+
323
349
  function buildAndroidUiMatchProperties(extra = {}) {
324
350
  return {
325
351
  x: { type: 'number', description: 'Absolute X coordinate' },
@@ -2244,7 +2270,18 @@ async function executeTool(toolName, args, context, engine) {
2244
2270
  persistConversation: triggerSource === 'schedule' || triggerSource === 'tasks'
2245
2271
  });
2246
2272
  // Track that the agent explicitly sent a message during this run
2247
- if (!suppressReply && sendResult?.suppressed !== true) {
2273
+ if (
2274
+ !suppressReply
2275
+ && sendResult?.success === true
2276
+ && sendResult?.suppressed !== true
2277
+ && isOriginMessagingDelivery({
2278
+ triggerSource,
2279
+ source: context.source,
2280
+ chatId: context.chatId,
2281
+ platform: args.platform,
2282
+ to: args.to,
2283
+ })
2284
+ ) {
2248
2285
  markProactiveMessageSent({ runState, deliveryState, content: normalizedMessage });
2249
2286
  if (runState && triggerSource === 'messaging') {
2250
2287
  runState.explicitMessageSent = true;
@@ -515,6 +515,13 @@ class MessagingManager extends EventEmitter {
515
515
  }
516
516
 
517
517
  const result = await platform.sendMessage(to, normalizedContent, sendOptions);
518
+ if (result?.success === false) {
519
+ const reason = result.error || result.reason || 'platform rejected the message';
520
+ const error = new Error(`Platform ${platformName} delivery failed: ${reason}`);
521
+ error.code = 'MESSAGING_DELIVERY_FAILED';
522
+ error.deliveryResult = result;
523
+ throw error;
524
+ }
518
525
 
519
526
  db.prepare('INSERT INTO messages (user_id, agent_id, run_id, role, content, platform, platform_chat_id, media_path, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)')
520
527
  .run(userId, agentId, runId, 'assistant', normalizedContent, platformName, to, mediaPath, metadata ? JSON.stringify(metadata) : null);