agent-inbox 0.0.1 → 0.1.2
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/CLAUDE.md +113 -0
- package/README.md +195 -1
- package/dist/federation/address.d.ts +24 -0
- package/dist/federation/address.d.ts.map +1 -0
- package/dist/federation/address.js +54 -0
- package/dist/federation/address.js.map +1 -0
- package/dist/federation/connection-manager.d.ts +118 -0
- package/dist/federation/connection-manager.d.ts.map +1 -0
- package/dist/federation/connection-manager.js +369 -0
- package/dist/federation/connection-manager.js.map +1 -0
- package/dist/federation/delivery-queue.d.ts +66 -0
- package/dist/federation/delivery-queue.d.ts.map +1 -0
- package/dist/federation/delivery-queue.js +199 -0
- package/dist/federation/delivery-queue.js.map +1 -0
- package/dist/federation/index.d.ts +7 -0
- package/dist/federation/index.d.ts.map +1 -0
- package/dist/federation/index.js +6 -0
- package/dist/federation/index.js.map +1 -0
- package/dist/federation/routing-engine.d.ts +74 -0
- package/dist/federation/routing-engine.d.ts.map +1 -0
- package/dist/federation/routing-engine.js +158 -0
- package/dist/federation/routing-engine.js.map +1 -0
- package/dist/federation/trust.d.ts +39 -0
- package/dist/federation/trust.d.ts.map +1 -0
- package/dist/federation/trust.js +64 -0
- package/dist/federation/trust.js.map +1 -0
- package/dist/index.d.ts +60 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +217 -18
- package/dist/index.js.map +1 -1
- package/dist/ipc/ipc-server.d.ts +21 -0
- package/dist/ipc/ipc-server.d.ts.map +1 -0
- package/dist/ipc/ipc-server.js +173 -0
- package/dist/ipc/ipc-server.js.map +1 -0
- package/dist/jsonrpc/mail-server.d.ts +45 -0
- package/dist/jsonrpc/mail-server.d.ts.map +1 -0
- package/dist/jsonrpc/mail-server.js +284 -0
- package/dist/jsonrpc/mail-server.js.map +1 -0
- package/dist/map/map-client.d.ts +91 -0
- package/dist/map/map-client.d.ts.map +1 -0
- package/dist/map/map-client.js +202 -0
- package/dist/map/map-client.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +23 -0
- package/dist/mcp/mcp-server.d.ts.map +1 -0
- package/dist/mcp/mcp-server.js +226 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/push/notifier.d.ts +49 -0
- package/dist/push/notifier.d.ts.map +1 -0
- package/dist/push/notifier.js +150 -0
- package/dist/push/notifier.js.map +1 -0
- package/dist/registry/warm-registry.d.ts +63 -0
- package/dist/registry/warm-registry.d.ts.map +1 -0
- package/dist/registry/warm-registry.js +173 -0
- package/dist/registry/warm-registry.js.map +1 -0
- package/dist/router/message-router.d.ts +44 -0
- package/dist/router/message-router.d.ts.map +1 -0
- package/dist/router/message-router.js +137 -0
- package/dist/router/message-router.js.map +1 -0
- package/dist/storage/interface.d.ts +31 -0
- package/dist/storage/interface.d.ts.map +1 -0
- package/dist/storage/interface.js +2 -0
- package/dist/storage/interface.js.map +1 -0
- package/dist/storage/memory.d.ts +28 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +118 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/sqlite.d.ts +35 -0
- package/dist/storage/sqlite.d.ts.map +1 -0
- package/dist/storage/sqlite.js +445 -0
- package/dist/storage/sqlite.js.map +1 -0
- package/dist/traceability/traceability.d.ts +29 -0
- package/dist/traceability/traceability.d.ts.map +1 -0
- package/dist/traceability/traceability.js +150 -0
- package/dist/traceability/traceability.js.map +1 -0
- package/dist/types.d.ts +261 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/docs/DESIGN.md +1156 -0
- package/docs/PLAN.md +545 -0
- package/hooks/inbox-hook.mjs +119 -0
- package/hooks/register-hook.mjs +69 -0
- package/package.json +33 -25
- package/rules/agent-inbox.md +78 -0
- package/src/federation/address.ts +61 -0
- package/src/federation/connection-manager.ts +458 -0
- package/src/federation/delivery-queue.ts +222 -0
- package/src/federation/index.ts +6 -0
- package/src/federation/routing-engine.ts +188 -0
- package/src/federation/trust.ts +71 -0
- package/src/index.ts +299 -0
- package/src/ipc/ipc-server.ts +207 -0
- package/src/jsonrpc/mail-server.ts +356 -0
- package/src/map/map-client.ts +260 -0
- package/src/mcp/mcp-server.ts +272 -0
- package/src/push/notifier.ts +192 -0
- package/src/registry/warm-registry.ts +210 -0
- package/src/router/message-router.ts +175 -0
- package/src/storage/interface.ts +48 -0
- package/src/storage/memory.ts +145 -0
- package/src/storage/sqlite.ts +645 -0
- package/src/traceability/traceability.ts +183 -0
- package/src/types.ts +297 -0
- package/test/federation/address.test.ts +101 -0
- package/test/federation/connection-manager.test.ts +546 -0
- package/test/federation/delivery-queue.test.ts +159 -0
- package/test/federation/integration.test.ts +823 -0
- package/test/federation/routing-engine.test.ts +117 -0
- package/test/federation/sdk-integration.test.ts +748 -0
- package/test/federation/trust.test.ts +89 -0
- package/test/ipc-jsonrpc.test.ts +113 -0
- package/test/ipc-server.test.ts +197 -0
- package/test/mail-server.test.ts +208 -0
- package/test/map-client.test.ts +408 -0
- package/test/message-router.test.ts +184 -0
- package/test/push-notifier.test.ts +139 -0
- package/test/registry/warm-registry.test.ts +171 -0
- package/test/sqlite-storage.test.ts +243 -0
- package/test/storage.test.ts +196 -0
- package/test/traceability.test.ts +123 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +10 -0
- package/vitest.config.ts +8 -0
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Agent,
|
|
3
|
+
Message,
|
|
4
|
+
Conversation,
|
|
5
|
+
Turn,
|
|
6
|
+
Thread,
|
|
7
|
+
} from "../types.js";
|
|
8
|
+
import type { Storage, InboxQuery, ThreadQuery } from "./interface.js";
|
|
9
|
+
|
|
10
|
+
export class InMemoryStorage implements Storage {
|
|
11
|
+
private agents = new Map<string, Agent>();
|
|
12
|
+
private messages = new Map<string, Message>();
|
|
13
|
+
private conversations = new Map<string, Conversation>();
|
|
14
|
+
private turns: Turn[] = [];
|
|
15
|
+
private threads = new Map<string, Thread>();
|
|
16
|
+
|
|
17
|
+
// --- Agents ---
|
|
18
|
+
|
|
19
|
+
getAgent(agentId: string): Agent | undefined {
|
|
20
|
+
return this.agents.get(agentId);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
putAgent(agent: Agent): void {
|
|
24
|
+
this.agents.set(agent.agent_id, agent);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
listAgents(scope?: string): Agent[] {
|
|
28
|
+
const all = Array.from(this.agents.values());
|
|
29
|
+
if (!scope) return all;
|
|
30
|
+
return all.filter((a) => a.scope === scope);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
removeAgent(agentId: string): boolean {
|
|
34
|
+
return this.agents.delete(agentId);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// --- Messages ---
|
|
38
|
+
|
|
39
|
+
getMessage(id: string): Message | undefined {
|
|
40
|
+
return this.messages.get(id);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
putMessage(message: Message): Message {
|
|
44
|
+
this.messages.set(message.id, message);
|
|
45
|
+
return message;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getInbox(agentId: string, opts?: InboxQuery): Message[] {
|
|
49
|
+
const results: Message[] = [];
|
|
50
|
+
for (const msg of this.messages.values()) {
|
|
51
|
+
const recipient = msg.recipients.find((r) => r.agent_id === agentId);
|
|
52
|
+
if (!recipient) continue;
|
|
53
|
+
if (opts?.unreadOnly && recipient.read_at) continue;
|
|
54
|
+
if (opts?.since && msg.created_at < opts.since) continue;
|
|
55
|
+
results.push(msg);
|
|
56
|
+
}
|
|
57
|
+
results.sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
58
|
+
if (opts?.limit) return results.slice(0, opts.limit);
|
|
59
|
+
return results;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getThread(query: ThreadQuery): Message[] {
|
|
63
|
+
const results: Message[] = [];
|
|
64
|
+
for (const msg of this.messages.values()) {
|
|
65
|
+
if (msg.thread_tag === query.threadTag && msg.scope === query.scope) {
|
|
66
|
+
results.push(msg);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return results.sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getSentMessages(agentId: string, limit?: number): Message[] {
|
|
73
|
+
const results: Message[] = [];
|
|
74
|
+
for (const msg of this.messages.values()) {
|
|
75
|
+
if (msg.sender_id === agentId) results.push(msg);
|
|
76
|
+
}
|
|
77
|
+
results.sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
78
|
+
if (limit) return results.slice(0, limit);
|
|
79
|
+
return results;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
searchMessages(query: string, scope?: string): Message[] {
|
|
83
|
+
const lower = query.toLowerCase();
|
|
84
|
+
const results: Message[] = [];
|
|
85
|
+
for (const msg of this.messages.values()) {
|
|
86
|
+
if (scope && msg.scope !== scope) continue;
|
|
87
|
+
const text =
|
|
88
|
+
msg.content.type === "text" ? (msg.content as { text: string }).text : "";
|
|
89
|
+
const subject = msg.subject ?? "";
|
|
90
|
+
if (
|
|
91
|
+
text.toLowerCase().includes(lower) ||
|
|
92
|
+
subject.toLowerCase().includes(lower)
|
|
93
|
+
) {
|
|
94
|
+
results.push(msg);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return results.sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// --- Conversations ---
|
|
101
|
+
|
|
102
|
+
getConversation(id: string): Conversation | undefined {
|
|
103
|
+
return this.conversations.get(id);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
putConversation(conversation: Conversation): Conversation {
|
|
107
|
+
this.conversations.set(conversation.id, conversation);
|
|
108
|
+
return conversation;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
listConversations(scope?: string): Conversation[] {
|
|
112
|
+
const all = Array.from(this.conversations.values());
|
|
113
|
+
if (!scope) return all;
|
|
114
|
+
return all.filter((c) => c.scope === scope);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// --- Turns ---
|
|
118
|
+
|
|
119
|
+
addTurn(turn: Turn): void {
|
|
120
|
+
this.turns.push(turn);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getTurns(conversationId: string): Turn[] {
|
|
124
|
+
return this.turns
|
|
125
|
+
.filter((t) => t.conversation_id === conversationId)
|
|
126
|
+
.sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// --- Threads ---
|
|
130
|
+
|
|
131
|
+
getThread2(id: string): Thread | undefined {
|
|
132
|
+
return this.threads.get(id);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
putThread(thread: Thread): Thread {
|
|
136
|
+
this.threads.set(thread.id, thread);
|
|
137
|
+
return thread;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getThreadsByConversation(conversationId: string): Thread[] {
|
|
141
|
+
return Array.from(this.threads.values()).filter(
|
|
142
|
+
(t) => t.conversation_id === conversationId
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|