Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Message Delivery

From Leeroopedia
Knowledge Sources
Domains Agent_Messaging, Delivery
Last Updated 2026-10-26 10:00 GMT

Overview

Concrete tool for local message delivery with proven arrival, provided by AI Maestro's `lib/message-delivery.ts`.

Description

The deliver function is the single local delivery function. Both the AMP route (`/api/v1/route`) and the web UI (`/api/messages`) call it. It:

  1. Applies content security screening (wraps unverified content in `<external-content>`)
  2. Writes to the recipient's AMP inbox (disk persistence — source of truth for "delivered")
  3. Fans out via WebSocket (supplementary, not a wake route)
  4. Runs the wake chain to notify the agent, with PROVEN arrival required to stop the chain
  5. Records the wake in the wake-state ledger
  6. If the wake is unconfirmed, enqueues a retry in the wake queue

No route may report a delivery it cannot prove. `verified` on `DeliveryResult` distinguishes "sent, unconfirmed" from proven arrival.

Usage

Call `deliver` after routing resolves to a local agent. Do not call it for remote agents (those go through federation relay).

Code Reference

Source Location

  • Repository: ai-maestro
  • File: lib/message-delivery.ts (L69-220)
  • Supporting: lib/content-security.ts, lib/amp-inbox-writer.ts, lib/amp-websocket.ts, lib/wake-chain.ts, lib/wake-queue.ts, lib/notification-service.ts, lib/wake-state.ts

Signature

export async function deliver(input: DeliveryInput): Promise<DeliveryResult>

interface DeliveryInput {
  envelope: AMPEnvelope
  payload: AMPPayload
  recipientAgentName: string
  recipientAgentId?: string
  senderPublicKeyHex?: string
  verification?: VerificationRecord
  senderName: string
  senderHost?: string
  subject: string
  priority?: string
  messageType?: string
}

interface DeliveryResult {
  delivered: boolean
  notified: boolean
  verified?: boolean         // proven arrival (acknowledged channel or pane readback)
  verifiedBy?: string       // which route proved it
  deferred?: boolean        // queued for idle transition
  wakeAttempts?: WakeOutcome[]
  error?: string
}

Import

import { deliver } from '@/lib/message-delivery'

I/O Contract

Inputs

Name Type Required Description
input.envelope AMPEnvelope Yes Signed AMP envelope
input.payload AMPPayload Yes Message payload (type, message, context)
input.recipientAgentId string Yes Recipient agent UUID (for inbox path)
input.senderName string Yes Sender display name

Outputs

Name Type Description
delivered boolean Inbox write succeeded (disk persistence)
notified boolean A wake route accepted the message
verified boolean A wake route PROVED arrival

Usage Examples

import { deliver } from '@/lib/message-delivery'

const result = await deliver({
  envelope: signedEnvelope,
  payload: messagePayload,
  recipientAgentName: 'website',
  recipientAgentId: 'agent-uuid',
  senderName: 'api',
  senderHost: 'macbook',
  subject: 'Deploy when ready',
  senderPublicKeyHex: 'abc123...',
  verification: { state: 'verified', trust: 'verified', method: 'ed25519' },
})

if (result.delivered && result.verified) {
  console.log(`Proven delivery via ${result.verifiedBy}`)
}

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment