swarm-mail 0.1.0 → 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 (75) hide show
  1. package/README.md +28 -0
  2. package/dist/adapter.d.ts +36 -0
  3. package/dist/adapter.d.ts.map +1 -0
  4. package/dist/index.d.ts +22 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +23131 -0
  7. package/{src/pglite.ts → dist/pglite.d.ts} +7 -93
  8. package/dist/pglite.d.ts.map +1 -0
  9. package/dist/streams/agent-mail.d.ts +139 -0
  10. package/dist/streams/agent-mail.d.ts.map +1 -0
  11. package/dist/streams/debug.d.ts +173 -0
  12. package/dist/streams/debug.d.ts.map +1 -0
  13. package/dist/streams/effect/ask.d.ts +124 -0
  14. package/dist/streams/effect/ask.d.ts.map +1 -0
  15. package/dist/streams/effect/cursor.d.ts +87 -0
  16. package/dist/streams/effect/cursor.d.ts.map +1 -0
  17. package/dist/streams/effect/deferred.d.ts +108 -0
  18. package/dist/streams/effect/deferred.d.ts.map +1 -0
  19. package/{src/streams/effect/index.ts → dist/streams/effect/index.d.ts} +1 -0
  20. package/dist/streams/effect/index.d.ts.map +1 -0
  21. package/{src/streams/effect/layers.ts → dist/streams/effect/layers.d.ts} +8 -33
  22. package/dist/streams/effect/layers.d.ts.map +1 -0
  23. package/dist/streams/effect/lock.d.ts +137 -0
  24. package/dist/streams/effect/lock.d.ts.map +1 -0
  25. package/dist/streams/effect/mailbox.d.ts +98 -0
  26. package/dist/streams/effect/mailbox.d.ts.map +1 -0
  27. package/dist/streams/events.d.ts +487 -0
  28. package/dist/streams/events.d.ts.map +1 -0
  29. package/dist/streams/index.d.ts +106 -0
  30. package/dist/streams/index.d.ts.map +1 -0
  31. package/dist/streams/migrations.d.ts +102 -0
  32. package/dist/streams/migrations.d.ts.map +1 -0
  33. package/dist/streams/projections.d.ts +173 -0
  34. package/dist/streams/projections.d.ts.map +1 -0
  35. package/dist/streams/store.d.ts +171 -0
  36. package/dist/streams/store.d.ts.map +1 -0
  37. package/dist/streams/swarm-mail.d.ts +153 -0
  38. package/dist/streams/swarm-mail.d.ts.map +1 -0
  39. package/dist/types/adapter.d.ts +267 -0
  40. package/dist/types/adapter.d.ts.map +1 -0
  41. package/dist/types/database.d.ts +117 -0
  42. package/dist/types/database.d.ts.map +1 -0
  43. package/{src/types/index.ts → dist/types/index.d.ts} +2 -15
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/package.json +20 -4
  46. package/src/adapter.ts +0 -306
  47. package/src/index.ts +0 -57
  48. package/src/streams/agent-mail.test.ts +0 -777
  49. package/src/streams/agent-mail.ts +0 -535
  50. package/src/streams/debug.test.ts +0 -500
  51. package/src/streams/debug.ts +0 -727
  52. package/src/streams/effect/ask.integration.test.ts +0 -314
  53. package/src/streams/effect/ask.ts +0 -202
  54. package/src/streams/effect/cursor.integration.test.ts +0 -418
  55. package/src/streams/effect/cursor.ts +0 -288
  56. package/src/streams/effect/deferred.test.ts +0 -357
  57. package/src/streams/effect/deferred.ts +0 -445
  58. package/src/streams/effect/lock.test.ts +0 -385
  59. package/src/streams/effect/lock.ts +0 -399
  60. package/src/streams/effect/mailbox.test.ts +0 -260
  61. package/src/streams/effect/mailbox.ts +0 -318
  62. package/src/streams/events.test.ts +0 -924
  63. package/src/streams/events.ts +0 -329
  64. package/src/streams/index.test.ts +0 -229
  65. package/src/streams/index.ts +0 -578
  66. package/src/streams/migrations.test.ts +0 -359
  67. package/src/streams/migrations.ts +0 -362
  68. package/src/streams/projections.test.ts +0 -611
  69. package/src/streams/projections.ts +0 -564
  70. package/src/streams/store.integration.test.ts +0 -658
  71. package/src/streams/store.ts +0 -1129
  72. package/src/streams/swarm-mail.ts +0 -552
  73. package/src/types/adapter.ts +0 -392
  74. package/src/types/database.ts +0 -127
  75. package/tsconfig.json +0 -22
@@ -22,31 +22,8 @@
22
22
  * const swarmMail = createSwarmMailAdapter(db, '/path/to/project');
23
23
  * ```
24
24
  */
25
-
26
25
  import { PGlite } from "@electric-sql/pglite";
27
- import { createSwarmMailAdapter } from "./adapter";
28
- import type { DatabaseAdapter, SwarmMailAdapter } from "./types";
29
- import { existsSync, mkdirSync } from "node:fs";
30
- import { join } from "node:path";
31
- import { homedir } from "node:os";
32
-
33
- /**
34
- * Wrap PGLite to match DatabaseAdapter interface
35
- *
36
- * PGLite has query() and exec() methods that match DatabaseAdapter,
37
- * but TypeScript needs the explicit wrapper for type safety.
38
- * PGLite's exec() returns Results[] but DatabaseAdapter expects void.
39
- */
40
- function wrapPGlite(pglite: PGlite): DatabaseAdapter {
41
- return {
42
- query: <T>(sql: string, params?: unknown[]) => pglite.query<T>(sql, params),
43
- exec: async (sql: string) => {
44
- await pglite.exec(sql);
45
- },
46
- close: () => pglite.close(),
47
- };
48
- }
49
-
26
+ import type { SwarmMailAdapter } from "./types";
50
27
  /**
51
28
  * Get database path (project-local or global fallback)
52
29
  *
@@ -56,31 +33,7 @@ function wrapPGlite(pglite: PGlite): DatabaseAdapter {
56
33
  * @param projectPath - Optional project root path
57
34
  * @returns Absolute path to database directory
58
35
  */
59
- export function getDatabasePath(projectPath?: string): string {
60
- if (projectPath) {
61
- const localDir = join(projectPath, ".opencode");
62
- if (!existsSync(localDir)) {
63
- mkdirSync(localDir, { recursive: true });
64
- }
65
- return join(localDir, "streams");
66
- }
67
- const globalDir = join(homedir(), ".opencode");
68
- if (!existsSync(globalDir)) {
69
- mkdirSync(globalDir, { recursive: true });
70
- }
71
- return join(globalDir, "streams");
72
- }
73
-
74
- /**
75
- * Singleton cache for SwarmMail instances
76
- *
77
- * Key is database path, value is the adapter + PGLite instance
78
- */
79
- const instances = new Map<
80
- string,
81
- { adapter: SwarmMailAdapter; pglite: PGlite }
82
- >();
83
-
36
+ export declare function getDatabasePath(projectPath?: string): string;
84
37
  /**
85
38
  * Get or create SwarmMail instance for a project
86
39
  *
@@ -99,23 +52,7 @@ const instances = new Map<
99
52
  * const swarmMail = await getSwarmMail();
100
53
  * ```
101
54
  */
102
- export async function getSwarmMail(
103
- projectPath?: string,
104
- ): Promise<SwarmMailAdapter> {
105
- const dbPath = getDatabasePath(projectPath);
106
- const projectKey = projectPath || dbPath;
107
-
108
- if (!instances.has(dbPath)) {
109
- const pglite = new PGlite(dbPath);
110
- const db = wrapPGlite(pglite);
111
- const adapter = createSwarmMailAdapter(db, projectKey);
112
- await adapter.runMigrations();
113
- instances.set(dbPath, { adapter, pglite });
114
- }
115
-
116
- return instances.get(dbPath)!.adapter;
117
- }
118
-
55
+ export declare function getSwarmMail(projectPath?: string): Promise<SwarmMailAdapter>;
119
56
  /**
120
57
  * Create in-memory SwarmMail instance (for testing)
121
58
  *
@@ -133,16 +70,7 @@ export async function getSwarmMail(
133
70
  * await swarmMail.close();
134
71
  * ```
135
72
  */
136
- export async function createInMemorySwarmMail(
137
- projectKey = "test",
138
- ): Promise<SwarmMailAdapter> {
139
- const pglite = new PGlite(); // in-memory
140
- const db = wrapPGlite(pglite);
141
- const adapter = createSwarmMailAdapter(db, projectKey);
142
- await adapter.runMigrations();
143
- return adapter;
144
- }
145
-
73
+ export declare function createInMemorySwarmMail(projectKey?: string): Promise<SwarmMailAdapter>;
146
74
  /**
147
75
  * Close specific SwarmMail instance
148
76
  *
@@ -155,15 +83,7 @@ export async function createInMemorySwarmMail(
155
83
  * await closeSwarmMail('/path/to/project');
156
84
  * ```
157
85
  */
158
- export async function closeSwarmMail(projectPath?: string): Promise<void> {
159
- const dbPath = getDatabasePath(projectPath);
160
- const instance = instances.get(dbPath);
161
- if (instance) {
162
- await instance.pglite.close();
163
- instances.delete(dbPath);
164
- }
165
- }
166
-
86
+ export declare function closeSwarmMail(projectPath?: string): Promise<void>;
167
87
  /**
168
88
  * Close all SwarmMail instances
169
89
  *
@@ -178,12 +98,6 @@ export async function closeSwarmMail(projectPath?: string): Promise<void> {
178
98
  * });
179
99
  * ```
180
100
  */
181
- export async function closeAllSwarmMail(): Promise<void> {
182
- for (const [path, instance] of instances) {
183
- await instance.pglite.close();
184
- instances.delete(path);
185
- }
186
- }
187
-
188
- // Re-export PGlite for consumers who need it
101
+ export declare function closeAllSwarmMail(): Promise<void>;
189
102
  export { PGlite };
103
+ //# sourceMappingURL=pglite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pglite.d.ts","sourceRoot":"","sources":["../src/pglite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAsBjE;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAa5D;AAYD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CAChC,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAa3B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,SAAS,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKvD;AAGD,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,139 @@
1
+ export interface AgentMailContext {
2
+ projectKey: string;
3
+ agentName: string;
4
+ }
5
+ export interface InitAgentOptions {
6
+ projectPath: string;
7
+ agentName?: string;
8
+ program?: string;
9
+ model?: string;
10
+ taskDescription?: string;
11
+ }
12
+ export interface SendMessageOptions {
13
+ projectPath: string;
14
+ fromAgent: string;
15
+ toAgents: string[];
16
+ subject: string;
17
+ body: string;
18
+ threadId?: string;
19
+ importance?: "low" | "normal" | "high" | "urgent";
20
+ ackRequired?: boolean;
21
+ }
22
+ export interface SendMessageResult {
23
+ success: boolean;
24
+ messageId: number;
25
+ threadId?: string;
26
+ recipientCount: number;
27
+ }
28
+ export interface GetInboxOptions {
29
+ projectPath: string;
30
+ agentName: string;
31
+ limit?: number;
32
+ urgentOnly?: boolean;
33
+ unreadOnly?: boolean;
34
+ includeBodies?: boolean;
35
+ }
36
+ export interface InboxMessage {
37
+ id: number;
38
+ from_agent: string;
39
+ subject: string;
40
+ body?: string;
41
+ thread_id: string | null;
42
+ importance: string;
43
+ created_at: number;
44
+ }
45
+ export interface InboxResult {
46
+ messages: InboxMessage[];
47
+ total: number;
48
+ }
49
+ export interface ReadMessageOptions {
50
+ projectPath: string;
51
+ messageId: number;
52
+ agentName?: string;
53
+ markAsRead?: boolean;
54
+ }
55
+ export interface ReserveFilesOptions {
56
+ projectPath: string;
57
+ agentName: string;
58
+ paths: string[];
59
+ reason?: string;
60
+ exclusive?: boolean;
61
+ ttlSeconds?: number;
62
+ force?: boolean;
63
+ }
64
+ export interface GrantedReservation {
65
+ id: number;
66
+ path: string;
67
+ expiresAt: number;
68
+ }
69
+ export interface ReservationConflict {
70
+ path: string;
71
+ holder: string;
72
+ pattern: string;
73
+ }
74
+ export interface ReserveFilesResult {
75
+ granted: GrantedReservation[];
76
+ conflicts: ReservationConflict[];
77
+ }
78
+ export interface ReleaseFilesOptions {
79
+ projectPath: string;
80
+ agentName: string;
81
+ paths?: string[];
82
+ reservationIds?: number[];
83
+ }
84
+ export interface ReleaseFilesResult {
85
+ released: number;
86
+ releasedAt: number;
87
+ }
88
+ export interface AcknowledgeOptions {
89
+ projectPath: string;
90
+ messageId: number;
91
+ agentName: string;
92
+ }
93
+ export interface AcknowledgeResult {
94
+ acknowledged: boolean;
95
+ acknowledgedAt: string | null;
96
+ }
97
+ export interface HealthResult {
98
+ healthy: boolean;
99
+ database: "connected" | "disconnected";
100
+ stats?: {
101
+ events: number;
102
+ agents: number;
103
+ messages: number;
104
+ reservations: number;
105
+ };
106
+ }
107
+ /**
108
+ * Initialize an agent for this session
109
+ */
110
+ export declare function initAgent(options: InitAgentOptions): Promise<AgentMailContext>;
111
+ /**
112
+ * Send a message to other agents
113
+ */
114
+ export declare function sendAgentMessage(options: SendMessageOptions): Promise<SendMessageResult>;
115
+ /**
116
+ * Get inbox messages for an agent
117
+ */
118
+ export declare function getAgentInbox(options: GetInboxOptions): Promise<InboxResult>;
119
+ /**
120
+ * Read a single message with full body
121
+ */
122
+ export declare function readAgentMessage(options: ReadMessageOptions): Promise<InboxMessage | null>;
123
+ /**
124
+ * Reserve files for exclusive editing
125
+ */
126
+ export declare function reserveAgentFiles(options: ReserveFilesOptions): Promise<ReserveFilesResult>;
127
+ /**
128
+ * Release file reservations
129
+ */
130
+ export declare function releaseAgentFiles(options: ReleaseFilesOptions): Promise<ReleaseFilesResult>;
131
+ /**
132
+ * Acknowledge a message
133
+ */
134
+ export declare function acknowledgeMessage(options: AcknowledgeOptions): Promise<AcknowledgeResult>;
135
+ /**
136
+ * Check if the agent mail store is healthy
137
+ */
138
+ export declare function checkHealth(projectPath?: string): Promise<HealthResult>;
139
+ //# sourceMappingURL=agent-mail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-mail.d.ts","sourceRoot":"","sources":["../../src/streams/agent-mail.ts"],"names":[],"mappings":"AA+EA,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;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,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAMD;;GAEG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAqB3B;AAMD;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAwC5B;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,WAAW,CAAC,CAqCtB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA8B9B;AAMD;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAuD7B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CA0C7B;AAMD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAkB5B;AAMD;;GAEG;AACH,wBAAsB,WAAW,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAiB7E"}
@@ -0,0 +1,173 @@
1
+ import type { AgentEvent } from "./events";
2
+ export interface DebugEventsOptions {
3
+ projectPath: string;
4
+ types?: AgentEvent["type"][];
5
+ agentName?: string;
6
+ limit?: number;
7
+ since?: number;
8
+ until?: number;
9
+ }
10
+ export interface DebugEventResult {
11
+ id: number;
12
+ sequence: number;
13
+ type: AgentEvent["type"];
14
+ timestamp: number;
15
+ timestamp_human: string;
16
+ agent_name?: string;
17
+ from_agent?: string;
18
+ to_agents?: string[];
19
+ [key: string]: unknown;
20
+ }
21
+ export interface DebugEventsResult {
22
+ events: DebugEventResult[];
23
+ total: number;
24
+ }
25
+ export interface DebugAgentOptions {
26
+ projectPath: string;
27
+ agentName: string;
28
+ includeEvents?: boolean;
29
+ }
30
+ export interface DebugAgentResult {
31
+ agent: {
32
+ name: string;
33
+ program: string;
34
+ model: string;
35
+ task_description: string | null;
36
+ registered_at: number;
37
+ last_active_at: number;
38
+ } | null;
39
+ stats: {
40
+ messagesSent: number;
41
+ messagesReceived: number;
42
+ };
43
+ reservations: Array<{
44
+ id: number;
45
+ path: string;
46
+ reason: string | null;
47
+ expires_at: number;
48
+ }>;
49
+ recentEvents?: DebugEventResult[];
50
+ }
51
+ export interface DebugMessageOptions {
52
+ projectPath: string;
53
+ messageId: number;
54
+ includeEvents?: boolean;
55
+ }
56
+ export interface DebugMessageResult {
57
+ message: {
58
+ id: number;
59
+ from_agent: string;
60
+ subject: string;
61
+ body: string;
62
+ thread_id: string | null;
63
+ importance: string;
64
+ created_at: number;
65
+ } | null;
66
+ recipients: Array<{
67
+ agent_name: string;
68
+ read_at: number | null;
69
+ acked_at: number | null;
70
+ }>;
71
+ events?: DebugEventResult[];
72
+ }
73
+ export interface DebugReservationsOptions {
74
+ projectPath: string;
75
+ checkConflicts?: boolean;
76
+ }
77
+ export interface DebugReservationsResult {
78
+ reservations: Array<{
79
+ id: number;
80
+ agent_name: string;
81
+ path_pattern: string;
82
+ reason: string | null;
83
+ expires_at: number;
84
+ expires_in_human: string;
85
+ }>;
86
+ byAgent: Record<string, Array<{
87
+ path: string;
88
+ expires_at: number;
89
+ }>>;
90
+ conflicts?: Array<{
91
+ path1: string;
92
+ agent1: string;
93
+ path2: string;
94
+ agent2: string;
95
+ }>;
96
+ }
97
+ export interface TimelineEntry {
98
+ time: string;
99
+ type: AgentEvent["type"];
100
+ summary: string;
101
+ agent: string;
102
+ sequence: number;
103
+ }
104
+ export interface TimelineResult {
105
+ timeline: TimelineEntry[];
106
+ }
107
+ export interface InspectStateOptions {
108
+ projectPath: string;
109
+ format?: "object" | "json";
110
+ }
111
+ export interface InspectStateResult {
112
+ agents: Array<{
113
+ name: string;
114
+ program: string;
115
+ model: string;
116
+ task_description: string | null;
117
+ }>;
118
+ messages: Array<{
119
+ id: number;
120
+ from_agent: string;
121
+ subject: string;
122
+ thread_id: string | null;
123
+ }>;
124
+ reservations: Array<{
125
+ id: number;
126
+ agent_name: string;
127
+ path_pattern: string;
128
+ }>;
129
+ eventCount: number;
130
+ latestSequence: number;
131
+ stats: {
132
+ events: number;
133
+ agents: number;
134
+ messages: number;
135
+ reservations: number;
136
+ };
137
+ json?: string;
138
+ }
139
+ /**
140
+ * Get recent events with filtering
141
+ *
142
+ * For large event logs (>100k events), consider using batchSize option
143
+ * to paginate through results instead of loading all events.
144
+ */
145
+ export declare function debugEvents(options: DebugEventsOptions & {
146
+ batchSize?: number;
147
+ }): Promise<DebugEventsResult>;
148
+ /**
149
+ * Get detailed agent information
150
+ */
151
+ export declare function debugAgent(options: DebugAgentOptions): Promise<DebugAgentResult>;
152
+ /**
153
+ * Get detailed message information with audit trail
154
+ */
155
+ export declare function debugMessage(options: DebugMessageOptions): Promise<DebugMessageResult>;
156
+ /**
157
+ * Get current reservation state
158
+ */
159
+ export declare function debugReservations(options: DebugReservationsOptions): Promise<DebugReservationsResult>;
160
+ /**
161
+ * Get event timeline for visualization
162
+ */
163
+ export declare function getEventTimeline(options: {
164
+ projectPath: string;
165
+ since?: number;
166
+ until?: number;
167
+ limit?: number;
168
+ }): Promise<TimelineResult>;
169
+ /**
170
+ * Get complete state snapshot for debugging
171
+ */
172
+ export declare function inspectState(options: InspectStateOptions): Promise<InspectStateResult>;
173
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/streams/debug.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAM3C,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM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;QACf,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAuED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD,OAAO,CAAC,iBAAiB,CAAC,CA6D5B;AAoFD;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAkE3B;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAwE7B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CAuFlC;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,cAAc,CAAC,CAyB1B;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAwD7B"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Ask Pattern - Request/Response over Durable Streams
3
+ *
4
+ * Combines DurableMailbox (message passing) + DurableDeferred (distributed promise)
5
+ * for synchronous-style request/response communication between agents.
6
+ *
7
+ * Based on Kyle Matthews' pattern from Agent Mail.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Agent A asks Agent B for data
12
+ * const result = yield* ask<Request, Response>({
13
+ * mailbox: myMailbox,
14
+ * to: "agent-b",
15
+ * payload: { query: "getUserData", userId: 123 },
16
+ * ttlSeconds: 30,
17
+ * });
18
+ *
19
+ * // Agent B receives request and responds
20
+ * for await (const envelope of mailbox.receive()) {
21
+ * const response = processRequest(envelope.payload);
22
+ * if (envelope.replyTo) {
23
+ * yield* DurableDeferred.resolve(envelope.replyTo, response);
24
+ * }
25
+ * yield* envelope.commit();
26
+ * }
27
+ * ```
28
+ */
29
+ import { Effect } from "effect";
30
+ import { DurableCursor } from "./cursor";
31
+ import { DurableMailbox, type Mailbox } from "./mailbox";
32
+ import { DurableDeferred } from "./deferred";
33
+ import type { TimeoutError, NotFoundError } from "./deferred";
34
+ /**
35
+ * Configuration for ask() request
36
+ */
37
+ export interface AskConfig<Req> {
38
+ /** Mailbox to send message from */
39
+ readonly mailbox: Mailbox;
40
+ /** Recipient agent(s) */
41
+ readonly to: string | string[];
42
+ /** Request payload */
43
+ readonly payload: Req;
44
+ /** Time-to-live in seconds before timeout (default: 60) */
45
+ readonly ttlSeconds?: number;
46
+ /** Optional thread ID for conversation tracking */
47
+ readonly threadId?: string;
48
+ /** Optional importance level */
49
+ readonly importance?: "low" | "normal" | "high" | "urgent";
50
+ /** Optional project path for database isolation */
51
+ readonly projectPath?: string;
52
+ }
53
+ /**
54
+ * Request/response pattern combining mailbox send + deferred await
55
+ *
56
+ * Creates a deferred promise, sends message with replyTo URL, then blocks
57
+ * until the recipient resolves the deferred (or timeout).
58
+ *
59
+ * @template Req - Request payload type
60
+ * @template Res - Response type
61
+ * @param config - Ask configuration
62
+ * @returns Effect that resolves with response or fails with timeout/not-found
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const program = Effect.gen(function* () {
67
+ * const mailbox = yield* DurableMailbox;
68
+ * const myMailbox = yield* mailbox.create({ agent: "worker-1", projectKey: "proj" });
69
+ *
70
+ * const response = yield* ask<Request, Response>({
71
+ * mailbox: myMailbox,
72
+ * to: "worker-2",
73
+ * payload: { task: "getData" },
74
+ * ttlSeconds: 30,
75
+ * });
76
+ *
77
+ * console.log("Got response:", response);
78
+ * });
79
+ * ```
80
+ */
81
+ export declare function ask<Req, Res>(config: AskConfig<Req>): Effect.Effect<Res, TimeoutError | NotFoundError, DurableDeferred>;
82
+ /**
83
+ * Ask pattern with automatic mailbox creation
84
+ *
85
+ * Simpler variant when you don't need to reuse the mailbox.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const response = yield* askWithMailbox({
90
+ * agent: "worker-1",
91
+ * projectKey: "proj",
92
+ * to: "worker-2",
93
+ * payload: { task: "getData" },
94
+ * });
95
+ * ```
96
+ */
97
+ export declare function askWithMailbox<Req, Res>(config: {
98
+ readonly agent: string;
99
+ readonly projectKey: string;
100
+ readonly to: string | string[];
101
+ readonly payload: Req;
102
+ readonly ttlSeconds?: number;
103
+ readonly threadId?: string;
104
+ readonly importance?: "low" | "normal" | "high" | "urgent";
105
+ readonly projectPath?: string;
106
+ }): Effect.Effect<Res, TimeoutError | NotFoundError, DurableDeferred | DurableMailbox | DurableCursor>;
107
+ /**
108
+ * Respond to a message envelope by resolving its replyTo deferred
109
+ *
110
+ * Helper for the receiver side of ask() pattern.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * for await (const envelope of mailbox.receive()) {
115
+ * const response = processRequest(envelope.payload);
116
+ * yield* respond(envelope, response);
117
+ * yield* envelope.commit();
118
+ * }
119
+ * ```
120
+ */
121
+ export declare function respond<T>(envelope: {
122
+ readonly replyTo?: string;
123
+ }, value: T, projectPath?: string): Effect.Effect<void, NotFoundError, DurableDeferred>;
124
+ //# sourceMappingURL=ask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../../src/streams/effect/ask.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,E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U,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC3D,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG,MAAM,CAAC,MAAM,CACf,GAAG,EACH,YAAY,GAAG,aAAa,EAC5B,eAAe,GAAG,cAAc,GAAG,aAAa,CACjD,CAoBA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,QAAQ,EAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,EACvC,KAAK,EAAE,CAAC,EACR,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,eAAe,CAAC,CAUrD"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * DurableCursor - Positioned event stream consumption with checkpointing
3
+ *
4
+ * Effect-TS service that wraps event stream reading with cursor state management.
5
+ * Enables reliable event processing with resumable position tracking.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const program = Effect.gen(function* () {
10
+ * const cursor = yield* DurableCursor;
11
+ * const consumer = yield* cursor.create({
12
+ * stream: "projects/foo/events",
13
+ * checkpoint: "agents/bar/position"
14
+ * });
15
+ *
16
+ * for await (const msg of consumer.consume()) {
17
+ * yield* handleMessage(msg.value);
18
+ * yield* msg.commit();
19
+ * }
20
+ * });
21
+ * ```
22
+ */
23
+ import { Context, Effect } from "effect";
24
+ import type { AgentEvent } from "../events";
25
+ /**
26
+ * Configuration for creating a cursor
27
+ */
28
+ export interface CursorConfig {
29
+ /** Stream identifier (e.g. "projects/foo/events") */
30
+ readonly stream: string;
31
+ /** Checkpoint identifier (e.g. "agents/bar/position") */
32
+ readonly checkpoint: string;
33
+ /** Project path for database location */
34
+ readonly projectPath?: string;
35
+ /** Batch size for reading events (default: 100) */
36
+ readonly batchSize?: number;
37
+ /** Optional filters for event types */
38
+ readonly types?: AgentEvent["type"][];
39
+ }
40
+ /**
41
+ * A message from the cursor with commit capability
42
+ */
43
+ export interface CursorMessage<T = unknown> {
44
+ /** The event value */
45
+ readonly value: T;
46
+ /** Event sequence number */
47
+ readonly sequence: number;
48
+ /** Commit this position to the checkpoint */
49
+ readonly commit: () => Effect.Effect<void>;
50
+ }
51
+ /**
52
+ * A cursor instance for consuming events
53
+ */
54
+ export interface Cursor {
55
+ /** Get current position */
56
+ readonly getPosition: () => Effect.Effect<number>;
57
+ /** Consume events as an async iterable */
58
+ readonly consume: <T = AgentEvent & {
59
+ id: number;
60
+ sequence: number;
61
+ }>() => AsyncIterable<CursorMessage<T>>;
62
+ /** Update checkpoint position */
63
+ readonly commit: (sequence: number) => Effect.Effect<void>;
64
+ }
65
+ /**
66
+ * DurableCursor service interface
67
+ */
68
+ export interface DurableCursorService {
69
+ /** Create a new cursor instance */
70
+ readonly create: (config: CursorConfig) => Effect.Effect<Cursor>;
71
+ }
72
+ declare const DurableCursor_base: Context.TagClass<DurableCursor, "DurableCursor", DurableCursorService>;
73
+ /**
74
+ * DurableCursor Context.Tag
75
+ */
76
+ export declare class DurableCursor extends DurableCursor_base {
77
+ }
78
+ /**
79
+ * Live implementation of DurableCursor service
80
+ */
81
+ export declare const DurableCursorLive: DurableCursorService;
82
+ /**
83
+ * Default layer for DurableCursor service
84
+ */
85
+ export declare const DurableCursorLayer: Context.Context<DurableCursor>;
86
+ export {};
87
+ //# sourceMappingURL=cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../../src/streams/effect/cursor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAGtD,OAAO,KAAK,EAAE,UAAU,EAAE,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