agent-relay-server 0.10.15 → 0.10.17

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/db.ts +12 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-relay-server",
3
- "version": "0.10.15",
3
+ "version": "0.10.17",
4
4
  "description": "Lightweight HTTP message relay for inter-agent communication across machines",
5
5
  "module": "src/index.ts",
6
6
  "type": "module",
package/src/db.ts CHANGED
@@ -2555,10 +2555,18 @@ export function listQueuedMessages(target: string, limit = 100): Message[] {
2555
2555
  export function resolveQueuedPolicyMessages(policyName: string, agentId: string): Message[] {
2556
2556
  const target = `policy:${policyName}`;
2557
2557
  const rows = db.prepare(`
2558
- SELECT id FROM messages
2559
- WHERE to_target = ? AND delivery_status = 'queued'
2560
- ORDER BY queued_at ASC, id ASC
2561
- `).all(target) as Array<{ id: number }>;
2558
+ SELECT m.id
2559
+ FROM messages m
2560
+ WHERE m.to_target = ?
2561
+ AND m.delivery_status IN ('queued', 'pending')
2562
+ AND NOT EXISTS (SELECT 1 FROM message_reads mr WHERE mr.message_id = m.id)
2563
+ AND (
2564
+ m.delivery_status = 'queued'
2565
+ OR m.resolved_to_agent IS NULL
2566
+ OR m.resolved_to_agent != ?
2567
+ )
2568
+ ORDER BY COALESCE(m.queued_at, m.created_at) ASC, m.id ASC
2569
+ `).all(target, agentId) as Array<{ id: number }>;
2562
2570
  if (rows.length === 0) return [];
2563
2571
  const ids = rows.map((row) => row.id);
2564
2572
  const placeholders = ids.map(() => "?").join(",");