fix: use gateway call agent for notification delivery (#381)

Switches notification delivery from sessions_send to gateway call agent command. No longer requires session_key — uses agent name (recipient) directly. Timeout increased 10s to 30s.
This commit is contained in:
Héctor Arriola 2026-03-15 05:31:05 -06:00 committed by GitHub
parent 8d671cb782
commit d980fc1a4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 13 deletions

View File

@ -7,8 +7,8 @@ import { logger } from '@/lib/logger';
/** /**
* POST /api/notifications/deliver - Notification delivery daemon endpoint * POST /api/notifications/deliver - Notification delivery daemon endpoint
* *
* Polls undelivered notifications and sends them to agent sessions * Polls undelivered notifications and sends them to agents
* via OpenClaw sessions_send command * via OpenClaw gateway call agent command
*/ */
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
const auth = requireRole(request, 'operator'); const auth = requireRole(request, 'operator');
@ -64,12 +64,12 @@ export async function POST(request: NextRequest) {
for (const notification of undeliveredNotifications) { for (const notification of undeliveredNotifications) {
try { try {
// Skip if agent doesn't have session key // Skip if agent is not registered in the agents table
if (!notification.session_key) { if (!notification.recipient) {
errors.push({ errors.push({
notification_id: notification.id, notification_id: notification.id,
recipient: notification.recipient, recipient: notification.recipient,
error: 'Agent has no session key configured' error: 'Notification has no recipient'
}); });
errorCount++; errorCount++;
continue; continue;
@ -79,20 +79,26 @@ export async function POST(request: NextRequest) {
const message = formatNotificationMessage(notification); const message = formatNotificationMessage(notification);
if (!dry_run) { if (!dry_run) {
// Send notification via OpenClaw sessions_send // Send notification via OpenClaw gateway call agent
try { try {
const invokeParams = {
message,
agentId: notification.recipient,
idempotencyKey: `notification-${notification.id}-${Date.now()}`,
deliver: false,
};
const { stdout, stderr } = await runOpenClaw( const { stdout, stderr } = await runOpenClaw(
[ [
'gateway', 'gateway',
'sessions_send', 'call',
'--session', 'agent',
notification.session_key, '--params',
'--message', JSON.stringify(invokeParams),
message '--json'
], ],
{ timeoutMs: 10000 } { timeoutMs: 30000 }
); );
if (stderr && stderr.includes('error')) { if (stderr && stderr.includes('error')) {
throw new Error(`OpenClaw error: ${stderr}`); throw new Error(`OpenClaw error: ${stderr}`);
} }