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.
Files changed (126) hide show
  1. package/CLAUDE.md +113 -0
  2. package/README.md +195 -1
  3. package/dist/federation/address.d.ts +24 -0
  4. package/dist/federation/address.d.ts.map +1 -0
  5. package/dist/federation/address.js +54 -0
  6. package/dist/federation/address.js.map +1 -0
  7. package/dist/federation/connection-manager.d.ts +118 -0
  8. package/dist/federation/connection-manager.d.ts.map +1 -0
  9. package/dist/federation/connection-manager.js +369 -0
  10. package/dist/federation/connection-manager.js.map +1 -0
  11. package/dist/federation/delivery-queue.d.ts +66 -0
  12. package/dist/federation/delivery-queue.d.ts.map +1 -0
  13. package/dist/federation/delivery-queue.js +199 -0
  14. package/dist/federation/delivery-queue.js.map +1 -0
  15. package/dist/federation/index.d.ts +7 -0
  16. package/dist/federation/index.d.ts.map +1 -0
  17. package/dist/federation/index.js +6 -0
  18. package/dist/federation/index.js.map +1 -0
  19. package/dist/federation/routing-engine.d.ts +74 -0
  20. package/dist/federation/routing-engine.d.ts.map +1 -0
  21. package/dist/federation/routing-engine.js +158 -0
  22. package/dist/federation/routing-engine.js.map +1 -0
  23. package/dist/federation/trust.d.ts +39 -0
  24. package/dist/federation/trust.d.ts.map +1 -0
  25. package/dist/federation/trust.js +64 -0
  26. package/dist/federation/trust.js.map +1 -0
  27. package/dist/index.d.ts +60 -2
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +217 -18
  30. package/dist/index.js.map +1 -1
  31. package/dist/ipc/ipc-server.d.ts +21 -0
  32. package/dist/ipc/ipc-server.d.ts.map +1 -0
  33. package/dist/ipc/ipc-server.js +173 -0
  34. package/dist/ipc/ipc-server.js.map +1 -0
  35. package/dist/jsonrpc/mail-server.d.ts +45 -0
  36. package/dist/jsonrpc/mail-server.d.ts.map +1 -0
  37. package/dist/jsonrpc/mail-server.js +284 -0
  38. package/dist/jsonrpc/mail-server.js.map +1 -0
  39. package/dist/map/map-client.d.ts +91 -0
  40. package/dist/map/map-client.d.ts.map +1 -0
  41. package/dist/map/map-client.js +202 -0
  42. package/dist/map/map-client.js.map +1 -0
  43. package/dist/mcp/mcp-server.d.ts +23 -0
  44. package/dist/mcp/mcp-server.d.ts.map +1 -0
  45. package/dist/mcp/mcp-server.js +226 -0
  46. package/dist/mcp/mcp-server.js.map +1 -0
  47. package/dist/push/notifier.d.ts +49 -0
  48. package/dist/push/notifier.d.ts.map +1 -0
  49. package/dist/push/notifier.js +150 -0
  50. package/dist/push/notifier.js.map +1 -0
  51. package/dist/registry/warm-registry.d.ts +63 -0
  52. package/dist/registry/warm-registry.d.ts.map +1 -0
  53. package/dist/registry/warm-registry.js +173 -0
  54. package/dist/registry/warm-registry.js.map +1 -0
  55. package/dist/router/message-router.d.ts +44 -0
  56. package/dist/router/message-router.d.ts.map +1 -0
  57. package/dist/router/message-router.js +137 -0
  58. package/dist/router/message-router.js.map +1 -0
  59. package/dist/storage/interface.d.ts +31 -0
  60. package/dist/storage/interface.d.ts.map +1 -0
  61. package/dist/storage/interface.js +2 -0
  62. package/dist/storage/interface.js.map +1 -0
  63. package/dist/storage/memory.d.ts +28 -0
  64. package/dist/storage/memory.d.ts.map +1 -0
  65. package/dist/storage/memory.js +118 -0
  66. package/dist/storage/memory.js.map +1 -0
  67. package/dist/storage/sqlite.d.ts +35 -0
  68. package/dist/storage/sqlite.d.ts.map +1 -0
  69. package/dist/storage/sqlite.js +445 -0
  70. package/dist/storage/sqlite.js.map +1 -0
  71. package/dist/traceability/traceability.d.ts +29 -0
  72. package/dist/traceability/traceability.d.ts.map +1 -0
  73. package/dist/traceability/traceability.js +150 -0
  74. package/dist/traceability/traceability.js.map +1 -0
  75. package/dist/types.d.ts +261 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +3 -0
  78. package/dist/types.js.map +1 -0
  79. package/docs/DESIGN.md +1156 -0
  80. package/docs/PLAN.md +545 -0
  81. package/hooks/inbox-hook.mjs +119 -0
  82. package/hooks/register-hook.mjs +69 -0
  83. package/package.json +33 -25
  84. package/rules/agent-inbox.md +78 -0
  85. package/src/federation/address.ts +61 -0
  86. package/src/federation/connection-manager.ts +458 -0
  87. package/src/federation/delivery-queue.ts +222 -0
  88. package/src/federation/index.ts +6 -0
  89. package/src/federation/routing-engine.ts +188 -0
  90. package/src/federation/trust.ts +71 -0
  91. package/src/index.ts +299 -0
  92. package/src/ipc/ipc-server.ts +207 -0
  93. package/src/jsonrpc/mail-server.ts +356 -0
  94. package/src/map/map-client.ts +260 -0
  95. package/src/mcp/mcp-server.ts +272 -0
  96. package/src/push/notifier.ts +192 -0
  97. package/src/registry/warm-registry.ts +210 -0
  98. package/src/router/message-router.ts +175 -0
  99. package/src/storage/interface.ts +48 -0
  100. package/src/storage/memory.ts +145 -0
  101. package/src/storage/sqlite.ts +645 -0
  102. package/src/traceability/traceability.ts +183 -0
  103. package/src/types.ts +297 -0
  104. package/test/federation/address.test.ts +101 -0
  105. package/test/federation/connection-manager.test.ts +546 -0
  106. package/test/federation/delivery-queue.test.ts +159 -0
  107. package/test/federation/integration.test.ts +823 -0
  108. package/test/federation/routing-engine.test.ts +117 -0
  109. package/test/federation/sdk-integration.test.ts +748 -0
  110. package/test/federation/trust.test.ts +89 -0
  111. package/test/ipc-jsonrpc.test.ts +113 -0
  112. package/test/ipc-server.test.ts +197 -0
  113. package/test/mail-server.test.ts +208 -0
  114. package/test/map-client.test.ts +408 -0
  115. package/test/message-router.test.ts +184 -0
  116. package/test/push-notifier.test.ts +139 -0
  117. package/test/registry/warm-registry.test.ts +171 -0
  118. package/test/sqlite-storage.test.ts +243 -0
  119. package/test/storage.test.ts +196 -0
  120. package/test/traceability.test.ts +123 -0
  121. package/tsconfig.json +20 -0
  122. package/tsup.config.ts +10 -0
  123. package/vitest.config.ts +8 -0
  124. package/dist/index.d.mts +0 -2
  125. package/dist/index.mjs +0 -1
  126. 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
+ }