agent-mailbox-core 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +126 -0
- package/dist/database.d.ts +7 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/format.d.ts +10 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +556 -0
- package/dist/mailbox.d.ts +66 -0
- package/dist/mailbox.d.ts.map +1 -0
- package/dist/plugin.d.ts +149 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +13111 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lleontor705
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# agent-mailbox
|
|
2
|
+
|
|
3
|
+
Production-grade inter-agent messaging for multi-agent AI systems. SQLite-backed with zero external dependencies.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Embedded SQLite** — No broker, no server. Pure `bun:sqlite`.
|
|
8
|
+
- **Visibility timeouts** — SQS-style message claiming. Un-acked messages re-appear automatically.
|
|
9
|
+
- **Dead letter queue** — Messages that fail N times are moved to DLQ for inspection/replay.
|
|
10
|
+
- **Idempotency** — Deduplication keys prevent duplicate message processing.
|
|
11
|
+
- **Full-text search** — FTS5 with graceful LIKE fallback.
|
|
12
|
+
- **Rate limiting** — Per-agent, per-minute rate limits.
|
|
13
|
+
- **Message TTL** — Per-message expiration with automatic cleanup.
|
|
14
|
+
- **Typed payloads** — Full TypeScript types for all operations.
|
|
15
|
+
- **Priority ordering** — High/normal/low priority with priority-based inbox ordering.
|
|
16
|
+
- **Threading** — Conversation threads with participant tracking.
|
|
17
|
+
- **Broadcast** — Send to all agents at once.
|
|
18
|
+
- **Agent registry** — Dynamic agent discovery (auto-registered on first message).
|
|
19
|
+
- **Trace IDs** — Cross-workflow observability.
|
|
20
|
+
- **Metrics** — Queue depths, delivery times, per-agent stats.
|
|
21
|
+
- **OpenCode plugin** — Drop-in plugin for OpenCode CLI.
|
|
22
|
+
- **WAL mode** — Concurrent read/write for multi-agent workloads.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bun add agent-mailbox
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Standalone (library)
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Mailbox } from "agent-mailbox";
|
|
36
|
+
|
|
37
|
+
const mailbox = new Mailbox({ dbPath: "./mailbox.db" });
|
|
38
|
+
|
|
39
|
+
// Send
|
|
40
|
+
const { messageId, threadId } = mailbox.send({
|
|
41
|
+
from: "architect",
|
|
42
|
+
to: "developer",
|
|
43
|
+
subject: "API spec ready",
|
|
44
|
+
body: "OpenAPI spec finalized. Proceed with implementation.",
|
|
45
|
+
priority: "high",
|
|
46
|
+
traceId: "workflow-42",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Read inbox (with visibility timeout)
|
|
50
|
+
const messages = mailbox.readInbox({ agent: "developer" });
|
|
51
|
+
|
|
52
|
+
// Acknowledge (prevents re-delivery)
|
|
53
|
+
mailbox.acknowledge(messages[0].id, {
|
|
54
|
+
from: "developer",
|
|
55
|
+
body: "Got it, starting implementation.",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Search
|
|
59
|
+
const { messages: results } = mailbox.search({ query: "API spec" });
|
|
60
|
+
|
|
61
|
+
// Metrics
|
|
62
|
+
console.log(mailbox.metrics());
|
|
63
|
+
|
|
64
|
+
mailbox.close();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### OpenCode Plugin
|
|
68
|
+
|
|
69
|
+
In your `opencode.json`:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"plugin": ["agent-mailbox/plugin"]
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Configure via environment variables:
|
|
78
|
+
|
|
79
|
+
| Variable | Default | Description |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `AGENT_MAILBOX_DB` | `~/.agent-mailbox/mailbox.db` | Database path |
|
|
82
|
+
| `AGENT_MAILBOX_TTL` | `86400` | Default message TTL (seconds) |
|
|
83
|
+
| `AGENT_MAILBOX_VIS_TIMEOUT` | `300` | Visibility timeout (seconds) |
|
|
84
|
+
| `AGENT_MAILBOX_MAX_RETRIES` | `3` | Max retries before DLQ |
|
|
85
|
+
| `AGENT_MAILBOX_MAX_BODY` | `65536` | Max message body size (bytes) |
|
|
86
|
+
| `AGENT_MAILBOX_RATE_LIMIT` | `60` | Messages per agent per minute |
|
|
87
|
+
|
|
88
|
+
## API
|
|
89
|
+
|
|
90
|
+
### `new Mailbox(config?)`
|
|
91
|
+
|
|
92
|
+
Create a mailbox instance.
|
|
93
|
+
|
|
94
|
+
### `mailbox.send(opts)` — Send a message
|
|
95
|
+
### `mailbox.broadcast(opts)` — Send to all agents
|
|
96
|
+
### `mailbox.readInbox(opts)` — Read inbox (claims messages with visibility timeout)
|
|
97
|
+
### `mailbox.markRead(id)` — Mark as read
|
|
98
|
+
### `mailbox.acknowledge(id, response?)` — Acknowledge processing, optionally reply
|
|
99
|
+
### `mailbox.search(opts)` — Full-text search
|
|
100
|
+
### `mailbox.listThreads(agent, limit?)` — List conversation threads
|
|
101
|
+
### `mailbox.getThread(threadId)` — Get all messages in a thread
|
|
102
|
+
### `mailbox.request(opts)` — Send and wait for reply (exponential backoff)
|
|
103
|
+
### `mailbox.registerAgent(name, role?)` — Register agent in registry
|
|
104
|
+
### `mailbox.listAgents()` — List registered agents
|
|
105
|
+
### `mailbox.getDeadLetters(limit?)` — View dead letter queue
|
|
106
|
+
### `mailbox.replayDeadLetter(id)` — Re-send a dead letter
|
|
107
|
+
### `mailbox.metrics()` — Get queue metrics
|
|
108
|
+
### `mailbox.cleanup()` — Manual cleanup (runs automatically on interval)
|
|
109
|
+
### `mailbox.close()` — Close database and stop timers
|
|
110
|
+
|
|
111
|
+
## Architecture
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
Agent A ──msg_send──> SQLite ──msg_read_inbox──> Agent B
|
|
115
|
+
│
|
|
116
|
+
┌────┴────┐
|
|
117
|
+
│ FTS5 │ ← Full-text search index
|
|
118
|
+
│ DLQ │ ← Dead letter queue
|
|
119
|
+
│ Rate │ ← Per-agent rate limits
|
|
120
|
+
│ Trace │ ← Cross-workflow IDs
|
|
121
|
+
└─────────┘
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database initialization and schema management for Agent Mailbox
|
|
3
|
+
*/
|
|
4
|
+
import { Database } from "bun:sqlite";
|
|
5
|
+
import type { ResolvedConfig } from "./types.js";
|
|
6
|
+
export declare function initDatabase(config: ResolvedConfig): Database;
|
|
7
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAuG7D"}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message formatting utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { Message, Thread, AgentInfo, DeadLetter, MailboxMetrics } from "./types.js";
|
|
5
|
+
export declare function formatMessages(rows: Message[]): string;
|
|
6
|
+
export declare function formatThreads(threads: Thread[]): string;
|
|
7
|
+
export declare function formatAgents(agents: AgentInfo[]): string;
|
|
8
|
+
export declare function formatDeadLetters(dls: DeadLetter[]): string;
|
|
9
|
+
export declare function formatMetrics(m: MailboxMetrics): string;
|
|
10
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEzF,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAgBtD;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAUvD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAUxD;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,MAAM,CAa3D;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAevD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-mailbox — Production-grade inter-agent messaging for multi-agent AI systems
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Mailbox } from "agent-mailbox";
|
|
7
|
+
*
|
|
8
|
+
* const mailbox = new Mailbox({ dbPath: "./mailbox.db" });
|
|
9
|
+
*
|
|
10
|
+
* // Send a message
|
|
11
|
+
* const { messageId, threadId } = mailbox.send({
|
|
12
|
+
* from: "architect",
|
|
13
|
+
* to: "developer",
|
|
14
|
+
* subject: "API schema ready",
|
|
15
|
+
* body: "The OpenAPI spec is finalized. Proceed with implementation.",
|
|
16
|
+
* priority: "high",
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Read inbox
|
|
20
|
+
* const messages = mailbox.readInbox({ agent: "developer" });
|
|
21
|
+
*
|
|
22
|
+
* // Acknowledge
|
|
23
|
+
* mailbox.acknowledge(messages[0].id);
|
|
24
|
+
*
|
|
25
|
+
* // Search
|
|
26
|
+
* const { messages: results } = mailbox.search({ query: "API schema" });
|
|
27
|
+
*
|
|
28
|
+
* // Metrics
|
|
29
|
+
* console.log(mailbox.metrics());
|
|
30
|
+
*
|
|
31
|
+
* mailbox.close();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export { Mailbox } from "./mailbox.js";
|
|
35
|
+
export { formatMessages, formatThreads, formatAgents, formatDeadLetters, formatMetrics } from "./format.js";
|
|
36
|
+
export type { Priority, DeliveryStatus, MailboxConfig, Message, SendOptions, SendResult, InboxOptions, SearchOptions, Thread, DeadLetter, MailboxMetrics, AgentInfo, } from "./types.js";
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5G,YAAY,EACV,QAAQ,EACR,cAAc,EACd,aAAa,EACb,OAAO,EACP,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,MAAM,EACN,UAAU,EACV,cAAc,EACd,SAAS,GACV,MAAM,YAAY,CAAC"}
|