agent-relay-server 0.10.14 → 0.10.16

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 (3) hide show
  1. package/package.json +1 -1
  2. package/src/bus.ts +1 -0
  3. 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.14",
3
+ "version": "0.10.16",
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/bus.ts CHANGED
@@ -360,6 +360,7 @@ function messageMatchesAgent(msg: Message, agentId: string): boolean {
360
360
  const agent = getAgent(agentId);
361
361
  if (!agent) return false;
362
362
  if (msg.claimable && msg.claimedBy && msg.claimedBy !== agentId) return false;
363
+ if (msg.resolvedToAgent === agentId) return true;
363
364
  if (msg.to === agentId || msg.from === agentId) return true;
364
365
  return targetMatchesAgent(msg.to, agentId, agent);
365
366
  }
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(",");