Implementation:23blocks OS Ai maestro Message Delivery
| 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:
- Applies content security screening (wraps unverified content in `<external-content>`)
- Writes to the recipient's AMP inbox (disk persistence — source of truth for "delivered")
- Fans out via WebSocket (supplementary, not a wake route)
- Runs the wake chain to notify the agent, with PROVEN arrival required to stop the chain
- Records the wake in the wake-state ledger
- 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}`)
}