neoagent 2.5.1 → 2.5.2-beta.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.
@@ -67,24 +67,42 @@ router.post('/notification', async (req, res) => {
67
67
  }
68
68
 
69
69
  // Fire-and-forget after response is sent — errors here must never touch res.
70
- Promise.resolve().then(() => {
71
- const agentEngine = req.app.locals.agentEngine;
72
- if (!agentEngine) return;
73
- const defaultAgentId = db.prepare('SELECT id FROM agents WHERE user_id = ? ORDER BY is_default DESC LIMIT 1').get(req.session.userId)?.id;
74
- if (!defaultAgentId) return;
75
- const prompt = [
76
- `A notification arrived on your device.`,
77
- `App: ${app_package || 'unknown'}`,
78
- title ? `Title: ${title}` : '',
79
- body ? `Body: ${body}` : '',
80
- `Evaluate whether this notification requires action or a reply. If it is routine or low-priority, do nothing.`,
81
- ].filter(Boolean).join('\n');
82
- return agentEngine.run(req.session.userId, prompt, {
83
- agentId: defaultAgentId,
84
- triggerSource: 'tasks',
85
- context: { source: 'notification', app_package, title, body, action_taken },
86
- });
87
- }).catch(err => console.error('[Triggers] Notification agent run failed:', err.message));
70
+ Promise.resolve().then(async () => {
71
+ const taskRuntime = req.app.locals.taskRuntime;
72
+ if (!taskRuntime) return;
73
+
74
+ const tasks = taskRuntime.taskRepository.listEnabledByTriggerTypes(['android_notification_received']) || [];
75
+ for (const task of tasks) {
76
+ if (task.user_id !== req.session.userId) continue;
77
+
78
+ let config = {};
79
+ try {
80
+ config = JSON.parse(task.trigger_config || '{}');
81
+ } catch (e) {}
82
+
83
+ if (config.appPackage && config.appPackage.trim() && config.appPackage.trim() !== app_package) {
84
+ continue;
85
+ }
86
+
87
+ const payload = {
88
+ fingerprint: `notification:${Date.now()}:${Math.random().toString(36).substr(2, 5)}`,
89
+ timestamp: new Date().toISOString(),
90
+ context: {
91
+ triggerEvent: {
92
+ provider: 'android_notification',
93
+ appPackage: app_package,
94
+ title: title,
95
+ body: body,
96
+ actionTaken: action_taken
97
+ }
98
+ }
99
+ };
100
+
101
+ await taskRuntime.fireTaskFromTrigger(task.id, task.user_id, payload).catch(err => {
102
+ console.error('[Triggers] Notification task trigger failed:', err.message);
103
+ });
104
+ }
105
+ }).catch(err => console.error('[Triggers] Notification background processing failed:', err.message));
88
106
  });
89
107
 
90
108
  module.exports = router;