@askexenow/exe-os 0.9.263 → 0.9.265

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 (148) hide show
  1. package/deploy/stack-manifests/v0.9.json +1 -1
  2. package/dist/backfill-metadata-WM46YQZL.js +597 -0
  3. package/dist/bin/agentic-ontology-backfill.js +1 -1
  4. package/dist/bin/agentic-reflection-backfill.js +1 -1
  5. package/dist/bin/agentic-semantic-label.js +1 -1
  6. package/dist/bin/backfill-conversations.js +1 -1
  7. package/dist/bin/backfill-responses.js +1 -1
  8. package/dist/bin/backfill-vectors.js +2 -2
  9. package/dist/bin/bulk-sync-postgres.js +1 -1
  10. package/dist/bin/cleanup-stale-review-tasks.js +2 -2
  11. package/dist/bin/cli.js +5 -5
  12. package/dist/bin/exe-assign.js +1 -1
  13. package/dist/bin/exe-boot.js +3 -3
  14. package/dist/bin/exe-dispatch.js +2 -2
  15. package/dist/bin/exe-doctor.js +1 -1
  16. package/dist/bin/exe-export-behaviors.js +2 -2
  17. package/dist/bin/exe-forget.js +3 -3
  18. package/dist/bin/exe-gateway.js +5 -5
  19. package/dist/bin/exe-heartbeat.js +3 -3
  20. package/dist/bin/exe-kill.js +3 -3
  21. package/dist/bin/exe-launch-agent.js +3 -3
  22. package/dist/bin/exe-pending-messages.js +3 -3
  23. package/dist/bin/exe-pending-notifications.js +2 -2
  24. package/dist/bin/exe-pending-reviews.js +6 -4
  25. package/dist/bin/exe-review.js +3 -3
  26. package/dist/bin/exe-search.js +2 -2
  27. package/dist/bin/exe-session-cleanup.js +5 -5
  28. package/dist/bin/exe-start-codex.js +1 -1
  29. package/dist/bin/exe-start-opencode.js +1 -1
  30. package/dist/bin/exe-status.js +3 -3
  31. package/dist/bin/exe-support.js +1 -1
  32. package/dist/bin/exe-team.js +1 -1
  33. package/dist/bin/git-sweep.js +2 -2
  34. package/dist/bin/graph-backfill.js +1 -1
  35. package/dist/bin/graph-export.js +2 -2
  36. package/dist/bin/import-history.js +2 -2
  37. package/dist/bin/intercom-check.js +5 -4
  38. package/dist/bin/mcp-sessions.js +2 -2
  39. package/dist/bin/orchestration-metrics.js +1 -1
  40. package/dist/bin/scan-tasks.js +2 -2
  41. package/dist/bin/shard-migrate.js +1 -1
  42. package/dist/capacity-monitor-FZORNXTA.js +49 -0
  43. package/dist/catchup-brief-PRKHIRWW.js +151 -0
  44. package/dist/chunk-2GU3NYMB.js +813 -0
  45. package/dist/chunk-2VT7Z2E2.js +197 -0
  46. package/dist/chunk-3L6XLN4V.js +1090 -0
  47. package/dist/chunk-3T4PNG5O.js +447 -0
  48. package/dist/chunk-3W324KN7.js +13696 -0
  49. package/dist/{chunk-BJYXHSFN.js → chunk-3X555IGG.js} +1 -1
  50. package/dist/chunk-4IATAIAF.js +89 -0
  51. package/dist/chunk-5M4F2FVD.js +204 -0
  52. package/dist/chunk-5TANMPI4.js +377 -0
  53. package/dist/chunk-67E5WIMW.js +333 -0
  54. package/dist/chunk-6NRJIARA.js +346 -0
  55. package/dist/chunk-6O22GTSE.js +1148 -0
  56. package/dist/chunk-7O5CMDP6.js +1345 -0
  57. package/dist/chunk-7P2JKEO3.js +382 -0
  58. package/dist/chunk-A4UY44T7.js +486 -0
  59. package/dist/chunk-AZHPQGSI.js +159 -0
  60. package/dist/chunk-BQAC3GCO.js +127 -0
  61. package/dist/chunk-CIWJRYIC.js +244 -0
  62. package/dist/chunk-CZO2DGGF.js +214 -0
  63. package/dist/chunk-D55SXO3N.js +3951 -0
  64. package/dist/chunk-EPDSRI6O.js +284 -0
  65. package/dist/chunk-EU34R2A3.js +1073 -0
  66. package/dist/chunk-G4KEDLSM.js +488 -0
  67. package/dist/{chunk-235ZCOYB.js → chunk-IBGC6JFX.js} +2 -2
  68. package/dist/chunk-IODP4JNE.js +551 -0
  69. package/dist/chunk-IZ6LCET7.js +58 -0
  70. package/dist/chunk-LPG3U5UW.js +731 -0
  71. package/dist/chunk-NH6TPXZV.js +13696 -0
  72. package/dist/chunk-O5TZI7OZ.js +50 -0
  73. package/dist/chunk-Q3N4KHLM.js +330 -0
  74. package/dist/chunk-QHQTMWYH.js +54 -0
  75. package/dist/chunk-QNYOPM2L.js +1921 -0
  76. package/dist/chunk-SPOA7EOD.js +81 -0
  77. package/dist/chunk-TK23WXKB.js +128 -0
  78. package/dist/chunk-TOVXER6J.js +76 -0
  79. package/dist/chunk-UIPAZYP7.js +171 -0
  80. package/dist/chunk-WXW4GF6M.js +495 -0
  81. package/dist/{chunk-KQNVIDBP.js → chunk-XLYBSXWS.js} +4 -3
  82. package/dist/core-memory-QXMQ5I7S.js +110 -0
  83. package/dist/crm-webhook-CH5W633Y.js +10 -0
  84. package/dist/cto-delegation-gate-XY3NMGTE.js +206 -0
  85. package/dist/daemon-orchestration-LS62JMTI.js +135 -0
  86. package/dist/dreaming-ZBKE2GFX.js +32 -0
  87. package/dist/exe-export-JNSQRIWI.js +73 -0
  88. package/dist/exe-import-AVGWQZLU.js +76 -0
  89. package/dist/exe-key-WR6QEHYO.js +579 -0
  90. package/dist/exe-snapshot-U6K3J6BD.js +164 -0
  91. package/dist/fast-db-init-ZHRRYI7M.js +7 -0
  92. package/dist/gateway/index.js +6 -6
  93. package/dist/git-task-sweep-64KSWRUI.js +40 -0
  94. package/dist/hooks/bug-report-worker.js +4 -4
  95. package/dist/hooks/codex-stop-task-finalizer.js +4 -4
  96. package/dist/hooks/commit-complete.js +4 -4
  97. package/dist/hooks/error-recall.js +2 -2
  98. package/dist/hooks/ingest.js +2 -2
  99. package/dist/hooks/instructions-loaded.js +1 -1
  100. package/dist/hooks/manifest.json +18 -18
  101. package/dist/hooks/notification.js +1 -1
  102. package/dist/hooks/post-compact.js +2 -2
  103. package/dist/hooks/post-tool-combined.js +2 -2
  104. package/dist/hooks/pre-compact.js +3 -3
  105. package/dist/hooks/pre-tool-use.js +6 -6
  106. package/dist/hooks/prompt-submit.js +16 -11
  107. package/dist/hooks/session-end.js +5 -5
  108. package/dist/hooks/session-start.js +6 -6
  109. package/dist/hooks/stop.js +5 -5
  110. package/dist/hooks/subagent-stop.js +2 -2
  111. package/dist/hooks/summary-worker.js +5 -5
  112. package/dist/index.js +9 -9
  113. package/dist/lib/consolidation.js +2 -2
  114. package/dist/lib/exe-daemon.js +17 -17
  115. package/dist/lib/hybrid-search.js +2 -2
  116. package/dist/lib/messaging.js +2 -2
  117. package/dist/lib/schedules.js +2 -2
  118. package/dist/lib/store.js +1 -1
  119. package/dist/lib/tasks.js +3 -3
  120. package/dist/lib/tmux-routing.js +1 -1
  121. package/dist/mcp/register-tools.js +25 -25
  122. package/dist/mcp/server.js +26 -26
  123. package/dist/mcp/tools/create-task.js +4 -4
  124. package/dist/mcp/tools/list-tasks.js +4 -4
  125. package/dist/mcp/tools/send-message.js +3 -3
  126. package/dist/mcp/tools/update-task.js +4 -4
  127. package/dist/notifications-45QSHDFA.js +45 -0
  128. package/dist/orchestrator-7XBMFK7D.js +33 -0
  129. package/dist/pipeline-router-MQKRNCTR.js +13 -0
  130. package/dist/reranker-CJW3UYE2.js +19 -0
  131. package/dist/review-polling-RL75XLAY.js +124 -0
  132. package/dist/runtime/index.js +3 -3
  133. package/dist/session-events-ZULAN4XL.js +36 -0
  134. package/dist/session-scope-V2RSOTDU.js +86 -0
  135. package/dist/skill-refinement-BSX6Q6IN.js +157 -0
  136. package/dist/{support-outbox-SZVLHHZG.js → support-outbox-SO73Q5H2.js} +202 -7
  137. package/dist/task-enforcement-JRTAOYZT.js +333 -0
  138. package/dist/task-scope-GNCB2GAM.js +35 -0
  139. package/dist/tasks-crud-MZIOYF3R.js +77 -0
  140. package/dist/tasks-notify-7KNZ4ULO.js +38 -0
  141. package/dist/tasks-review-U5VEV4Y7.js +47 -0
  142. package/dist/telemetry-upload-BIB5TJA4.js +739 -0
  143. package/dist/tui/App.js +7 -7
  144. package/dist/tui-data-ZSB5DDEY.js +258 -0
  145. package/dist/worker-gate-TXLX33PX.js +21 -0
  146. package/dist/workflow-engine-3PIT3Y56.js +28 -0
  147. package/package.json +1 -1
  148. package/release-notes.json +27 -24
@@ -0,0 +1,50 @@
1
+ import {
2
+ sendMessage
3
+ } from "./chunk-Q3N4KHLM.js";
4
+ import {
5
+ getActiveAgent
6
+ } from "./chunk-YG7PIB2R.js";
7
+
8
+ // src/mcp/tools/send-message.ts
9
+ import { z } from "zod";
10
+ function registerSendMessage(server) {
11
+ server.registerTool(
12
+ "send_message",
13
+ {
14
+ title: "Send Message",
15
+ description: "Send a structured message to another agent. Messages are queued and delivered via intercom. NOTE: messages are fire-and-forget \u2014 do NOT use for actionable work dispatch. Use create_task instead to assign work to employees.",
16
+ inputSchema: {
17
+ target_agent: z.string().describe("Recipient agent name"),
18
+ content: z.string().describe("Message content"),
19
+ target_project: z.string().optional().describe("Project context (optional)"),
20
+ priority: z.enum(["normal", "urgent"]).default("normal").describe("Message priority (default: normal)"),
21
+ target_device: z.string().optional().describe("Target device ID for cross-machine delivery (default: local)")
22
+ }
23
+ },
24
+ async ({ target_agent, content, target_project, priority, target_device }) => {
25
+ const { agentId } = getActiveAgent();
26
+ const msg = await sendMessage({
27
+ fromAgent: agentId,
28
+ targetAgent: target_agent,
29
+ targetProject: target_project,
30
+ targetDevice: target_device,
31
+ content,
32
+ priority
33
+ });
34
+ const statusText = msg.status === "delivered" ? "delivered" : msg.status === "failed" ? `failed: ${msg.failureReason}` : "queued (pending delivery)";
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: `Message sent to ${target_agent}: ${statusText}
40
+ ID: ${msg.id}`
41
+ }
42
+ ]
43
+ };
44
+ }
45
+ );
46
+ }
47
+
48
+ export {
49
+ registerSendMessage
50
+ };
@@ -0,0 +1,330 @@
1
+ import {
2
+ employeeSessionName,
3
+ isEmployeeAlive,
4
+ resolveExeSession,
5
+ sendIntercom,
6
+ strictSessionScopeFilter
7
+ } from "./chunk-D55SXO3N.js";
8
+ import {
9
+ parseMessage,
10
+ serializeMessage
11
+ } from "./chunk-4JERP7NT.js";
12
+ import {
13
+ recordOrchestrationEventBestEffort
14
+ } from "./chunk-JTADPL6X.js";
15
+ import {
16
+ getClient
17
+ } from "./chunk-QQZMP6QL.js";
18
+
19
+ // src/lib/messaging.ts
20
+ import crypto from "crypto";
21
+ function generateUlid() {
22
+ const timestamp = Date.now().toString(36).padStart(10, "0");
23
+ const random = crypto.randomBytes(10).toString("hex").slice(0, 16);
24
+ return (timestamp + random).toUpperCase();
25
+ }
26
+ function rowToMessage(row) {
27
+ return {
28
+ id: row.id,
29
+ fromAgent: row.from_agent,
30
+ fromDevice: row.from_device,
31
+ targetAgent: row.target_agent,
32
+ targetProject: row.target_project ?? null,
33
+ targetDevice: row.target_device,
34
+ sessionScope: row.session_scope ?? null,
35
+ content: row.content,
36
+ priority: row.priority ?? "normal",
37
+ status: row.status ?? "pending",
38
+ serverSeq: row.server_seq != null ? Number(row.server_seq) : null,
39
+ retryCount: Number(row.retry_count ?? 0),
40
+ createdAt: row.created_at,
41
+ deliveredAt: row.delivered_at ?? null,
42
+ processedAt: row.processed_at ?? null,
43
+ failedAt: row.failed_at ?? null,
44
+ failureReason: row.failure_reason ?? null
45
+ };
46
+ }
47
+ var MAX_RETRIES = 10;
48
+ async function sendMessage(input) {
49
+ const client = getClient();
50
+ const id = generateUlid();
51
+ const now = (/* @__PURE__ */ new Date()).toISOString();
52
+ const targetDevice = input.targetDevice ?? "local";
53
+ const sessionScope = input.sessionScope === void 0 ? resolveExeSession() : input.sessionScope;
54
+ await client.execute({
55
+ sql: `INSERT INTO messages (id, from_agent, from_device, target_agent, target_project, target_device, session_scope, content, priority, status, founder_id, created_at)
56
+ VALUES (?, ?, 'local', ?, ?, ?, ?, ?, ?, 'pending', ?, ?)`,
57
+ args: [
58
+ id,
59
+ input.fromAgent,
60
+ input.targetAgent,
61
+ input.targetProject ?? null,
62
+ targetDevice,
63
+ sessionScope,
64
+ input.content,
65
+ input.priority ?? "normal",
66
+ input.founderId ?? null,
67
+ now
68
+ ]
69
+ });
70
+ recordOrchestrationEventBestEffort({
71
+ eventType: "message.sent",
72
+ source: "messaging.sendMessage",
73
+ agentId: input.fromAgent,
74
+ payload: { targetAgent: input.targetAgent, priority: input.priority ?? "normal", targetDevice },
75
+ sessionScope: sessionScope ?? null
76
+ });
77
+ try {
78
+ if (targetDevice !== "local") {
79
+ await deliverCrossMachineMessage(id, targetDevice);
80
+ } else {
81
+ await deliverLocalMessage(id);
82
+ }
83
+ } catch {
84
+ }
85
+ const sentScope = strictSessionScopeFilter(sessionScope);
86
+ const result = await client.execute({
87
+ sql: `SELECT * FROM messages WHERE id = ?${sentScope.sql}`,
88
+ args: [id, ...sentScope.args]
89
+ });
90
+ return rowToMessage(result.rows[0]);
91
+ }
92
+ var _wsClientSend = null;
93
+ function setWsClientSend(fn) {
94
+ _wsClientSend = fn;
95
+ }
96
+ async function deliverCrossMachineMessage(messageId, targetDevice) {
97
+ const client = getClient();
98
+ const result = await client.execute({
99
+ sql: "SELECT * FROM messages WHERE id = ?",
100
+ args: [messageId]
101
+ });
102
+ if (result.rows.length === 0) return false;
103
+ const msg = rowToMessage(result.rows[0]);
104
+ if (msg.status !== "pending") return false;
105
+ if (!_wsClientSend) {
106
+ return false;
107
+ }
108
+ const payload = JSON.stringify({
109
+ id: msg.id,
110
+ fromAgent: msg.fromAgent,
111
+ targetAgent: msg.targetAgent,
112
+ targetProject: msg.targetProject,
113
+ sessionScope: msg.sessionScope,
114
+ content: msg.content,
115
+ priority: msg.priority,
116
+ createdAt: msg.createdAt
117
+ });
118
+ const sent = _wsClientSend(targetDevice, payload);
119
+ if (sent) {
120
+ await client.execute({
121
+ sql: "UPDATE messages SET status = 'synced' WHERE id = ?",
122
+ args: [messageId]
123
+ });
124
+ return true;
125
+ }
126
+ return false;
127
+ }
128
+ async function deliverLocalMessage(messageId) {
129
+ const client = getClient();
130
+ const result = await client.execute({
131
+ sql: "SELECT * FROM messages WHERE id = ?",
132
+ args: [messageId]
133
+ });
134
+ if (result.rows.length === 0) return false;
135
+ const msg = rowToMessage(result.rows[0]);
136
+ if (msg.status !== "pending") return false;
137
+ const targetAgent = msg.targetAgent;
138
+ const now = (/* @__PURE__ */ new Date()).toISOString();
139
+ try {
140
+ const exeSession = resolveExeSession();
141
+ if (!exeSession) {
142
+ throw new Error("No coordinator session found");
143
+ }
144
+ process.stderr.write(`[messaging] ENTER deliverLocal: target=${targetAgent} exeSession=${exeSession}
145
+ `);
146
+ const { isCoordinatorName: isCoord } = await import("./lib/employees.js");
147
+ const isCOO = isCoord(targetAgent);
148
+ process.stderr.write(`[messaging] COO check: targetAgent="${targetAgent}" isCOO=${isCOO}
149
+ `);
150
+ const sessionName = isCOO ? exeSession : employeeSessionName(targetAgent, exeSession);
151
+ process.stderr.write(`[messaging] delivery attempt: target=${targetAgent} session=${sessionName} isCOO=${isCOO}
152
+ `);
153
+ if (!isCOO && !isEmployeeAlive(sessionName)) {
154
+ throw new Error("Session not running \u2014 message stays queued");
155
+ }
156
+ const intercomResult = sendIntercom(sessionName, { force: true, reason: "message" });
157
+ process.stderr.write(`[messaging] intercom result for ${sessionName}: ${intercomResult}
158
+ `);
159
+ await client.execute({
160
+ sql: "UPDATE messages SET status = 'delivered', delivered_at = ? WHERE id = ?",
161
+ args: [now, messageId]
162
+ });
163
+ recordOrchestrationEventBestEffort({
164
+ eventType: "message.delivered",
165
+ source: "messaging.deliverLocalMessage",
166
+ agentId: msg.targetAgent,
167
+ payload: { fromAgent: msg.fromAgent, priority: msg.priority }
168
+ });
169
+ return true;
170
+ } catch (err) {
171
+ process.stderr.write(
172
+ `[messaging] delivery failed for message ${messageId}: ${err instanceof Error ? err.message : String(err)}
173
+ `
174
+ );
175
+ const newRetryCount = msg.retryCount + 1;
176
+ if (newRetryCount >= MAX_RETRIES) {
177
+ await markFailed(messageId, "session unavailable after 10 retries", msg.sessionScope);
178
+ } else {
179
+ await client.execute({
180
+ sql: "UPDATE messages SET retry_count = ? WHERE id = ?",
181
+ args: [newRetryCount, messageId]
182
+ });
183
+ }
184
+ return false;
185
+ }
186
+ }
187
+ async function getPendingMessages(targetAgent, sessionScope) {
188
+ const client = getClient();
189
+ const scope = strictSessionScopeFilter(sessionScope);
190
+ const result = await client.execute({
191
+ sql: `SELECT * FROM messages
192
+ WHERE target_agent = ? AND status IN ('pending', 'delivered')${scope.sql}
193
+ ORDER BY id`,
194
+ args: [targetAgent, ...scope.args]
195
+ });
196
+ return result.rows.map((row) => rowToMessage(row));
197
+ }
198
+ async function markRead(messageId, sessionScope) {
199
+ const client = getClient();
200
+ const scope = strictSessionScopeFilter(sessionScope);
201
+ await client.execute({
202
+ sql: `UPDATE messages SET status = 'read'
203
+ WHERE id = ? AND status IN ('pending', 'delivered')${scope.sql}`,
204
+ args: [messageId, ...scope.args]
205
+ });
206
+ recordOrchestrationEventBestEffort({
207
+ eventType: "message.read",
208
+ source: "messaging.markRead",
209
+ payload: { messageId }
210
+ });
211
+ }
212
+ async function markAcknowledged(messageId, sessionScope) {
213
+ const client = getClient();
214
+ const scope = strictSessionScopeFilter(sessionScope);
215
+ await client.execute({
216
+ sql: `UPDATE messages SET status = 'acknowledged', processed_at = ?
217
+ WHERE id = ? AND status = 'read'${scope.sql}`,
218
+ args: [(/* @__PURE__ */ new Date()).toISOString(), messageId, ...scope.args]
219
+ });
220
+ }
221
+ async function markProcessed(messageId, sessionScope) {
222
+ const client = getClient();
223
+ const scope = strictSessionScopeFilter(sessionScope);
224
+ await client.execute({
225
+ sql: `UPDATE messages SET status = 'processed', processed_at = ?
226
+ WHERE id = ?${scope.sql}`,
227
+ args: [(/* @__PURE__ */ new Date()).toISOString(), messageId, ...scope.args]
228
+ });
229
+ }
230
+ async function getMessageStatus(messageId, sessionScope) {
231
+ const client = getClient();
232
+ const scope = strictSessionScopeFilter(sessionScope);
233
+ const result = await client.execute({
234
+ sql: `SELECT status FROM messages WHERE id = ?${scope.sql}`,
235
+ args: [messageId, ...scope.args]
236
+ });
237
+ return result.rows[0]?.status ?? null;
238
+ }
239
+ async function getUnacknowledgedMessages(targetAgent, sessionScope) {
240
+ const client = getClient();
241
+ const scope = strictSessionScopeFilter(sessionScope);
242
+ const result = await client.execute({
243
+ sql: `SELECT * FROM messages
244
+ WHERE target_agent = ? AND status IN ('pending', 'delivered', 'read')${scope.sql}
245
+ ORDER BY id`,
246
+ args: [targetAgent, ...scope.args]
247
+ });
248
+ return result.rows.map((row) => rowToMessage(row));
249
+ }
250
+ async function getReadMessages(targetAgent, sessionScope) {
251
+ const client = getClient();
252
+ const scope = strictSessionScopeFilter(sessionScope);
253
+ const result = await client.execute({
254
+ sql: `SELECT * FROM messages
255
+ WHERE target_agent = ? AND status = 'read'${scope.sql}
256
+ ORDER BY id`,
257
+ args: [targetAgent, ...scope.args]
258
+ });
259
+ return result.rows.map((row) => rowToMessage(row));
260
+ }
261
+ async function markFailed(messageId, reason, sessionScope) {
262
+ const client = getClient();
263
+ const scope = strictSessionScopeFilter(sessionScope);
264
+ await client.execute({
265
+ sql: `UPDATE messages SET status = 'failed', failed_at = ?, failure_reason = ?
266
+ WHERE id = ?${scope.sql}`,
267
+ args: [(/* @__PURE__ */ new Date()).toISOString(), reason, messageId, ...scope.args]
268
+ });
269
+ }
270
+ async function getFailedMessages(sessionScope) {
271
+ const client = getClient();
272
+ const scope = strictSessionScopeFilter(sessionScope);
273
+ const result = await client.execute({
274
+ sql: `SELECT * FROM messages WHERE status = 'failed'${scope.sql} ORDER BY created_at DESC`,
275
+ args: [...scope.args]
276
+ });
277
+ return result.rows.map((row) => rowToMessage(row));
278
+ }
279
+ async function retryPendingMessages(sessionScope) {
280
+ const client = getClient();
281
+ const scope = strictSessionScopeFilter(sessionScope);
282
+ const result = await client.execute({
283
+ sql: `SELECT * FROM messages
284
+ WHERE status = 'pending' AND retry_count < ?${scope.sql}
285
+ ORDER BY id`,
286
+ args: [MAX_RETRIES, ...scope.args]
287
+ });
288
+ let delivered = 0;
289
+ for (const row of result.rows) {
290
+ const msg = rowToMessage(row);
291
+ try {
292
+ const success = await deliverLocalMessage(msg.id);
293
+ if (success) delivered++;
294
+ } catch {
295
+ }
296
+ }
297
+ return delivered;
298
+ }
299
+ async function sendTypedMessage(envelope, targetAgent, opts) {
300
+ return sendMessage({
301
+ fromAgent: envelope.from,
302
+ targetAgent,
303
+ targetProject: opts?.targetProject,
304
+ targetDevice: opts?.targetDevice,
305
+ content: serializeMessage(envelope),
306
+ priority: opts?.priority,
307
+ sessionScope: opts?.sessionScope
308
+ });
309
+ }
310
+ function parseIncomingMessage(content) {
311
+ return parseMessage(content);
312
+ }
313
+
314
+ export {
315
+ sendMessage,
316
+ setWsClientSend,
317
+ deliverLocalMessage,
318
+ getPendingMessages,
319
+ markRead,
320
+ markAcknowledged,
321
+ markProcessed,
322
+ getMessageStatus,
323
+ getUnacknowledgedMessages,
324
+ getReadMessages,
325
+ markFailed,
326
+ getFailedMessages,
327
+ retryPendingMessages,
328
+ sendTypedMessage,
329
+ parseIncomingMessage
330
+ };
@@ -0,0 +1,54 @@
1
+ import {
2
+ processCRMEvent
3
+ } from "./chunk-7P2JKEO3.js";
4
+
5
+ // src/gateway/adapters/crm-webhook.ts
6
+ function parseTwentyWebhook(payload) {
7
+ if (!payload || typeof payload !== "object") return null;
8
+ const p = payload;
9
+ const eventName = p.eventName;
10
+ if (!eventName || typeof eventName !== "string") return null;
11
+ const dotIndex = eventName.indexOf(".");
12
+ if (dotIndex === -1) return null;
13
+ const objectType = eventName.slice(0, dotIndex);
14
+ const eventType = eventName.slice(dotIndex + 1);
15
+ if (!objectType || !eventType) return null;
16
+ const normalizedObjectType = objectType.charAt(0).toUpperCase() + objectType.slice(1);
17
+ const record = p.record ?? {};
18
+ if (typeof record !== "object") return null;
19
+ return {
20
+ eventType,
21
+ objectType: normalizedObjectType,
22
+ record
23
+ };
24
+ }
25
+ function createCRMWebhookHandler(options) {
26
+ return async (body) => {
27
+ const event = parseTwentyWebhook(body);
28
+ if (!event) {
29
+ console.warn(
30
+ "[crm-webhook] Malformed CRM webhook payload \u2014 skipping"
31
+ );
32
+ return;
33
+ }
34
+ console.log(
35
+ `[crm-webhook] ${event.objectType}.${event.eventType} received`
36
+ );
37
+ try {
38
+ const logs = await processCRMEvent(event, options?.executor, options?.triggers);
39
+ if (logs.length > 0 && options?.onFired) {
40
+ options.onFired(logs);
41
+ }
42
+ } catch (err) {
43
+ console.error(
44
+ "[crm-webhook] Error processing CRM event:",
45
+ err instanceof Error ? err.message : err
46
+ );
47
+ }
48
+ };
49
+ }
50
+
51
+ export {
52
+ parseTwentyWebhook,
53
+ createCRMWebhookHandler
54
+ };