@jungjaehoon/mama-os 0.53.0 → 0.57.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.
Files changed (1717) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +62 -259
  3. package/db/migrations/001-connector-event-index.sql +251 -0
  4. package/dist/agent/claude-native-tool-policy.d.ts +17 -0
  5. package/dist/agent/claude-native-tool-policy.d.ts.map +1 -0
  6. package/dist/agent/claude-native-tool-policy.js +88 -0
  7. package/dist/agent/claude-native-tool-policy.js.map +1 -0
  8. package/dist/api/attachment-actions.d.ts +16 -0
  9. package/dist/api/attachment-actions.d.ts.map +1 -0
  10. package/dist/api/attachment-actions.js +278 -0
  11. package/dist/api/attachment-actions.js.map +1 -0
  12. package/dist/api/auth-middleware.d.ts +15 -55
  13. package/dist/api/auth-middleware.d.ts.map +1 -1
  14. package/dist/api/auth-middleware.js +56 -233
  15. package/dist/api/auth-middleware.js.map +1 -1
  16. package/dist/api/cf-access.d.ts +6 -0
  17. package/dist/api/cf-access.d.ts.map +1 -0
  18. package/dist/api/cf-access.js +121 -0
  19. package/dist/api/cf-access.js.map +1 -0
  20. package/dist/api/file-delivery.d.ts +29 -0
  21. package/dist/api/file-delivery.d.ts.map +1 -0
  22. package/dist/api/file-delivery.js +90 -0
  23. package/dist/api/file-delivery.js.map +1 -0
  24. package/dist/api/owner-timezone-actions.d.ts +10 -0
  25. package/dist/api/owner-timezone-actions.d.ts.map +1 -0
  26. package/dist/api/owner-timezone-actions.js +73 -0
  27. package/dist/api/owner-timezone-actions.js.map +1 -0
  28. package/dist/api/report-actions.d.ts +22 -0
  29. package/dist/api/report-actions.d.ts.map +1 -0
  30. package/dist/api/report-actions.js +137 -0
  31. package/dist/api/report-actions.js.map +1 -0
  32. package/dist/api/report-handler.d.ts +15 -11
  33. package/dist/api/report-handler.d.ts.map +1 -1
  34. package/dist/api/report-handler.js +48 -120
  35. package/dist/api/report-handler.js.map +1 -1
  36. package/dist/api/report-persistence.d.ts +3 -3
  37. package/dist/api/report-persistence.d.ts.map +1 -1
  38. package/dist/api/report-persistence.js +35 -10
  39. package/dist/api/report-persistence.js.map +1 -1
  40. package/dist/api/report-source-actions.d.ts +11 -0
  41. package/dist/api/report-source-actions.d.ts.map +1 -0
  42. package/dist/api/report-source-actions.js +309 -0
  43. package/dist/api/report-source-actions.js.map +1 -0
  44. package/dist/api/security-events.d.ts +23 -0
  45. package/dist/api/security-events.d.ts.map +1 -0
  46. package/dist/api/security-events.js +71 -0
  47. package/dist/api/security-events.js.map +1 -0
  48. package/dist/api/source-actions.d.ts +9 -0
  49. package/dist/api/source-actions.d.ts.map +1 -0
  50. package/dist/api/source-actions.js +274 -0
  51. package/dist/api/source-actions.js.map +1 -0
  52. package/dist/api/stored-source-reader.d.ts +21 -0
  53. package/dist/api/stored-source-reader.d.ts.map +1 -0
  54. package/dist/api/stored-source-reader.js +269 -0
  55. package/dist/api/stored-source-reader.js.map +1 -0
  56. package/dist/api/viewer-data.d.ts +143 -0
  57. package/dist/api/viewer-data.d.ts.map +1 -0
  58. package/dist/api/viewer-data.js +518 -0
  59. package/dist/api/viewer-data.js.map +1 -0
  60. package/dist/api/viewer-request-security.d.ts +12 -0
  61. package/dist/api/viewer-request-security.d.ts.map +1 -0
  62. package/dist/api/viewer-request-security.js +217 -0
  63. package/dist/api/viewer-request-security.js.map +1 -0
  64. package/dist/api/viewer-server.d.ts +55 -0
  65. package/dist/api/viewer-server.d.ts.map +1 -0
  66. package/dist/api/viewer-server.js +933 -0
  67. package/dist/api/viewer-server.js.map +1 -0
  68. package/dist/api/wiki-actions.d.ts +20 -0
  69. package/dist/api/wiki-actions.d.ts.map +1 -0
  70. package/dist/api/wiki-actions.js +296 -0
  71. package/dist/api/wiki-actions.js.map +1 -0
  72. package/dist/api/work-actions.d.ts +109 -0
  73. package/dist/api/work-actions.d.ts.map +1 -0
  74. package/dist/api/work-actions.js +987 -0
  75. package/dist/api/work-actions.js.map +1 -0
  76. package/dist/cli/commands/daemon.d.ts +90 -0
  77. package/dist/cli/commands/daemon.d.ts.map +1 -0
  78. package/dist/cli/commands/daemon.js +620 -0
  79. package/dist/cli/commands/daemon.js.map +1 -0
  80. package/dist/cli/commands/init.d.ts +7 -18
  81. package/dist/cli/commands/init.d.ts.map +1 -1
  82. package/dist/cli/commands/init.js +357 -273
  83. package/dist/cli/commands/init.js.map +1 -1
  84. package/dist/cli/commands/replay.d.ts +12 -0
  85. package/dist/cli/commands/replay.d.ts.map +1 -0
  86. package/dist/cli/commands/replay.js +145 -0
  87. package/dist/cli/commands/replay.js.map +1 -0
  88. package/dist/cli/commands/secret.d.ts +6 -0
  89. package/dist/cli/commands/secret.d.ts.map +1 -0
  90. package/dist/cli/commands/secret.js +24 -0
  91. package/dist/cli/commands/secret.js.map +1 -0
  92. package/dist/cli/index.d.ts +0 -5
  93. package/dist/cli/index.d.ts.map +1 -1
  94. package/dist/cli/index.js +52 -95
  95. package/dist/cli/index.js.map +1 -1
  96. package/dist/cli/launch-files.d.ts +10 -0
  97. package/dist/cli/launch-files.d.ts.map +1 -0
  98. package/dist/cli/launch-files.js +74 -0
  99. package/dist/cli/launch-files.js.map +1 -0
  100. package/dist/cli/prompt.d.ts +15 -0
  101. package/dist/cli/prompt.d.ts.map +1 -0
  102. package/dist/cli/prompt.js +64 -0
  103. package/dist/cli/prompt.js.map +1 -0
  104. package/dist/cli/runtime/action-mcp-config.d.ts +15 -0
  105. package/dist/cli/runtime/action-mcp-config.d.ts.map +1 -0
  106. package/dist/cli/runtime/action-mcp-config.js +56 -0
  107. package/dist/cli/runtime/action-mcp-config.js.map +1 -0
  108. package/dist/cli/runtime/claude-caller-config.d.ts +4 -0
  109. package/dist/cli/runtime/claude-caller-config.d.ts.map +1 -0
  110. package/dist/cli/runtime/claude-caller-config.js +46 -0
  111. package/dist/cli/runtime/claude-caller-config.js.map +1 -0
  112. package/dist/cli/secrets.d.ts +9 -0
  113. package/dist/cli/secrets.d.ts.map +1 -0
  114. package/dist/cli/secrets.js +94 -0
  115. package/dist/cli/secrets.js.map +1 -0
  116. package/dist/connectors/calendar/index.d.ts +11 -10
  117. package/dist/connectors/calendar/index.d.ts.map +1 -1
  118. package/dist/connectors/calendar/index.js +171 -97
  119. package/dist/connectors/calendar/index.js.map +1 -1
  120. package/dist/connectors/chatwork/index.d.ts +31 -5
  121. package/dist/connectors/chatwork/index.d.ts.map +1 -1
  122. package/dist/connectors/chatwork/index.js +184 -20
  123. package/dist/connectors/chatwork/index.js.map +1 -1
  124. package/dist/connectors/claude-code/index.d.ts +0 -2
  125. package/dist/connectors/claude-code/index.d.ts.map +1 -1
  126. package/dist/connectors/claude-code/index.js +94 -70
  127. package/dist/connectors/claude-code/index.js.map +1 -1
  128. package/dist/connectors/config-loader.d.ts +1 -6
  129. package/dist/connectors/config-loader.d.ts.map +1 -1
  130. package/dist/connectors/config-loader.js +154 -134
  131. package/dist/connectors/config-loader.js.map +1 -1
  132. package/dist/connectors/discord/index.d.ts +8 -1
  133. package/dist/connectors/discord/index.d.ts.map +1 -1
  134. package/dist/connectors/discord/index.js +110 -32
  135. package/dist/connectors/discord/index.js.map +1 -1
  136. package/dist/connectors/drive/index.d.ts +10 -5
  137. package/dist/connectors/drive/index.d.ts.map +1 -1
  138. package/dist/connectors/drive/index.js +145 -88
  139. package/dist/connectors/drive/index.js.map +1 -1
  140. package/dist/connectors/framework/attachment-io.d.ts +5 -0
  141. package/dist/connectors/framework/attachment-io.d.ts.map +1 -0
  142. package/dist/connectors/framework/attachment-io.js +72 -0
  143. package/dist/connectors/framework/attachment-io.js.map +1 -0
  144. package/dist/connectors/framework/attachments.d.ts +32 -0
  145. package/dist/connectors/framework/attachments.d.ts.map +1 -0
  146. package/dist/connectors/framework/attachments.js +14 -0
  147. package/dist/connectors/framework/attachments.js.map +1 -0
  148. package/dist/connectors/framework/connector-event-types.d.ts +136 -0
  149. package/dist/connectors/framework/connector-event-types.d.ts.map +1 -0
  150. package/dist/connectors/framework/connector-event-types.js +3 -0
  151. package/dist/connectors/framework/connector-event-types.js.map +1 -0
  152. package/dist/connectors/framework/connector-state.d.ts +3 -0
  153. package/dist/connectors/framework/connector-state.d.ts.map +1 -0
  154. package/dist/connectors/framework/connector-state.js +47 -0
  155. package/dist/connectors/framework/connector-state.js.map +1 -0
  156. package/dist/connectors/framework/event-index.d.ts +28 -0
  157. package/dist/connectors/framework/event-index.d.ts.map +1 -0
  158. package/dist/connectors/framework/event-index.js +354 -0
  159. package/dist/connectors/framework/event-index.js.map +1 -0
  160. package/dist/connectors/framework/gws-utils.d.ts +3 -8
  161. package/dist/connectors/framework/gws-utils.d.ts.map +1 -1
  162. package/dist/connectors/framework/gws-utils.js +23 -30
  163. package/dist/connectors/framework/gws-utils.js.map +1 -1
  164. package/dist/connectors/framework/index.d.ts +4 -2
  165. package/dist/connectors/framework/index.d.ts.map +1 -1
  166. package/dist/connectors/framework/index.js +8 -6
  167. package/dist/connectors/framework/index.js.map +1 -1
  168. package/dist/connectors/framework/polling-scheduler.d.ts +71 -52
  169. package/dist/connectors/framework/polling-scheduler.d.ts.map +1 -1
  170. package/dist/connectors/framework/polling-scheduler.js +227 -168
  171. package/dist/connectors/framework/polling-scheduler.js.map +1 -1
  172. package/dist/connectors/framework/raw-query.d.ts +44 -0
  173. package/dist/connectors/framework/raw-query.d.ts.map +1 -0
  174. package/dist/connectors/framework/raw-query.js +584 -0
  175. package/dist/connectors/framework/raw-query.js.map +1 -0
  176. package/dist/connectors/framework/stored-index-read.d.ts +16 -0
  177. package/dist/connectors/framework/stored-index-read.d.ts.map +1 -0
  178. package/dist/connectors/framework/stored-index-read.js +66 -0
  179. package/dist/connectors/framework/stored-index-read.js.map +1 -0
  180. package/dist/connectors/framework/types.d.ts +17 -61
  181. package/dist/connectors/framework/types.d.ts.map +1 -1
  182. package/dist/connectors/framework/types.js +0 -4
  183. package/dist/connectors/framework/types.js.map +1 -1
  184. package/dist/connectors/gmail/index.d.ts +3 -2
  185. package/dist/connectors/gmail/index.d.ts.map +1 -1
  186. package/dist/connectors/gmail/index.js +74 -27
  187. package/dist/connectors/gmail/index.js.map +1 -1
  188. package/dist/connectors/ical/index.d.ts +29 -0
  189. package/dist/connectors/ical/index.d.ts.map +1 -0
  190. package/dist/connectors/ical/index.js +220 -0
  191. package/dist/connectors/ical/index.js.map +1 -0
  192. package/dist/connectors/ical/parser.d.ts +13 -0
  193. package/dist/connectors/ical/parser.d.ts.map +1 -0
  194. package/dist/connectors/ical/parser.js +117 -0
  195. package/dist/connectors/ical/parser.js.map +1 -0
  196. package/dist/connectors/imessage/index.d.ts +3 -1
  197. package/dist/connectors/imessage/index.d.ts.map +1 -1
  198. package/dist/connectors/imessage/index.js +31 -16
  199. package/dist/connectors/imessage/index.js.map +1 -1
  200. package/dist/connectors/index.d.ts +12 -5
  201. package/dist/connectors/index.d.ts.map +1 -1
  202. package/dist/connectors/index.js +67 -18
  203. package/dist/connectors/index.js.map +1 -1
  204. package/dist/connectors/kagemusha/index.d.ts +7 -19
  205. package/dist/connectors/kagemusha/index.d.ts.map +1 -1
  206. package/dist/connectors/kagemusha/index.js +123 -173
  207. package/dist/connectors/kagemusha/index.js.map +1 -1
  208. package/dist/connectors/notion/index.d.ts.map +1 -1
  209. package/dist/connectors/notion/index.js +79 -36
  210. package/dist/connectors/notion/index.js.map +1 -1
  211. package/dist/connectors/obsidian/index.d.ts +1 -1
  212. package/dist/connectors/obsidian/index.d.ts.map +1 -1
  213. package/dist/connectors/obsidian/index.js +59 -57
  214. package/dist/connectors/obsidian/index.js.map +1 -1
  215. package/dist/connectors/sheets/index.d.ts +8 -4
  216. package/dist/connectors/sheets/index.d.ts.map +1 -1
  217. package/dist/connectors/sheets/index.js +155 -143
  218. package/dist/connectors/sheets/index.js.map +1 -1
  219. package/dist/connectors/slack/index.d.ts +24 -5
  220. package/dist/connectors/slack/index.d.ts.map +1 -1
  221. package/dist/connectors/slack/index.js +177 -39
  222. package/dist/connectors/slack/index.js.map +1 -1
  223. package/dist/connectors/telegram/index.d.ts +9 -2
  224. package/dist/connectors/telegram/index.d.ts.map +1 -1
  225. package/dist/connectors/telegram/index.js +119 -70
  226. package/dist/connectors/telegram/index.js.map +1 -1
  227. package/dist/connectors/trello/index.d.ts +10 -3
  228. package/dist/connectors/trello/index.d.ts.map +1 -1
  229. package/dist/connectors/trello/index.js +88 -39
  230. package/dist/connectors/trello/index.js.map +1 -1
  231. package/dist/gateways/base-gateway.d.ts +9 -33
  232. package/dist/gateways/base-gateway.d.ts.map +1 -1
  233. package/dist/gateways/base-gateway.js +7 -28
  234. package/dist/gateways/base-gateway.js.map +1 -1
  235. package/dist/gateways/conversation-record.d.ts +52 -0
  236. package/dist/gateways/conversation-record.d.ts.map +1 -0
  237. package/dist/gateways/conversation-record.js +220 -0
  238. package/dist/gateways/conversation-record.js.map +1 -0
  239. package/dist/gateways/discord.d.ts +33 -135
  240. package/dist/gateways/discord.d.ts.map +1 -1
  241. package/dist/gateways/discord.js +258 -778
  242. package/dist/gateways/discord.js.map +1 -1
  243. package/dist/gateways/session-store.d.ts +28 -9
  244. package/dist/gateways/session-store.d.ts.map +1 -1
  245. package/dist/gateways/session-store.js +192 -60
  246. package/dist/gateways/session-store.js.map +1 -1
  247. package/dist/gateways/slack.d.ts +35 -105
  248. package/dist/gateways/slack.d.ts.map +1 -1
  249. package/dist/gateways/slack.js +282 -440
  250. package/dist/gateways/slack.js.map +1 -1
  251. package/dist/gateways/telegram-attachments.d.ts +32 -0
  252. package/dist/gateways/telegram-attachments.d.ts.map +1 -0
  253. package/dist/gateways/telegram-attachments.js +113 -0
  254. package/dist/gateways/telegram-attachments.js.map +1 -0
  255. package/dist/gateways/telegram-errors.d.ts +3 -0
  256. package/dist/gateways/telegram-errors.d.ts.map +1 -0
  257. package/dist/gateways/telegram-errors.js +10 -0
  258. package/dist/gateways/telegram-errors.js.map +1 -0
  259. package/dist/gateways/telegram-format.d.ts.map +1 -1
  260. package/dist/gateways/telegram-format.js +9 -1
  261. package/dist/gateways/telegram-format.js.map +1 -1
  262. package/dist/gateways/telegram-message-ledger.d.ts +31 -25
  263. package/dist/gateways/telegram-message-ledger.d.ts.map +1 -1
  264. package/dist/gateways/telegram-message-ledger.js +122 -146
  265. package/dist/gateways/telegram-message-ledger.js.map +1 -1
  266. package/dist/gateways/telegram-response-presenter.d.ts +3 -1
  267. package/dist/gateways/telegram-response-presenter.d.ts.map +1 -1
  268. package/dist/gateways/telegram-response-presenter.js +14 -0
  269. package/dist/gateways/telegram-response-presenter.js.map +1 -1
  270. package/dist/gateways/telegram-text-entities.d.ts +2 -3
  271. package/dist/gateways/telegram-text-entities.d.ts.map +1 -1
  272. package/dist/gateways/telegram-text-entities.js +4 -5
  273. package/dist/gateways/telegram-text-entities.js.map +1 -1
  274. package/dist/gateways/telegram.d.ts +39 -101
  275. package/dist/gateways/telegram.d.ts.map +1 -1
  276. package/dist/gateways/telegram.js +406 -919
  277. package/dist/gateways/telegram.js.map +1 -1
  278. package/dist/gateways/turn-contract.d.ts +27 -87
  279. package/dist/gateways/turn-contract.d.ts.map +1 -1
  280. package/dist/gateways/types.d.ts +14 -299
  281. package/dist/gateways/types.d.ts.map +1 -1
  282. package/dist/gateways/types.js +0 -3
  283. package/dist/gateways/types.js.map +1 -1
  284. package/dist/index.d.ts +1 -6
  285. package/dist/index.d.ts.map +1 -1
  286. package/dist/index.js +0 -23
  287. package/dist/index.js.map +1 -1
  288. package/dist/operator/board-read-views.d.ts +8 -10
  289. package/dist/operator/board-read-views.d.ts.map +1 -1
  290. package/dist/operator/board-read-views.js +4 -13
  291. package/dist/operator/board-read-views.js.map +1 -1
  292. package/dist/operator/board-slot-instructions.d.ts +10 -11
  293. package/dist/operator/board-slot-instructions.d.ts.map +1 -1
  294. package/dist/operator/board-slot-instructions.js +22 -21
  295. package/dist/operator/board-slot-instructions.js.map +1 -1
  296. package/dist/replay/import-manifest.d.ts +21 -0
  297. package/dist/replay/import-manifest.d.ts.map +1 -0
  298. package/dist/replay/import-manifest.js +157 -0
  299. package/dist/replay/import-manifest.js.map +1 -0
  300. package/dist/replay/jev-client.d.ts +35 -0
  301. package/dist/replay/jev-client.d.ts.map +1 -0
  302. package/dist/replay/jev-client.js +141 -0
  303. package/dist/replay/jev-client.js.map +1 -0
  304. package/dist/replay/kagemusha-import.d.ts +35 -0
  305. package/dist/replay/kagemusha-import.d.ts.map +1 -0
  306. package/dist/replay/kagemusha-import.js +543 -0
  307. package/dist/replay/kagemusha-import.js.map +1 -0
  308. package/dist/replay/replay-cursor.d.ts +31 -0
  309. package/dist/replay/replay-cursor.d.ts.map +1 -0
  310. package/dist/replay/replay-cursor.js +189 -0
  311. package/dist/replay/replay-cursor.js.map +1 -0
  312. package/dist/replay/replay-feeder.d.ts +55 -0
  313. package/dist/replay/replay-feeder.d.ts.map +1 -0
  314. package/dist/replay/replay-feeder.js +214 -0
  315. package/dist/replay/replay-feeder.js.map +1 -0
  316. package/dist/replay/replay-ledger.d.ts +32 -0
  317. package/dist/replay/replay-ledger.d.ts.map +1 -0
  318. package/dist/replay/replay-ledger.js +91 -0
  319. package/dist/replay/replay-ledger.js.map +1 -0
  320. package/dist/replay/replay-source-catalog.d.ts +66 -0
  321. package/dist/replay/replay-source-catalog.d.ts.map +1 -0
  322. package/dist/replay/replay-source-catalog.js +332 -0
  323. package/dist/replay/replay-source-catalog.js.map +1 -0
  324. package/dist/replay/trello-import.d.ts +33 -0
  325. package/dist/replay/trello-import.d.ts.map +1 -0
  326. package/dist/replay/trello-import.js +204 -0
  327. package/dist/replay/trello-import.js.map +1 -0
  328. package/dist/replay/window-queue.d.ts +116 -0
  329. package/dist/replay/window-queue.d.ts.map +1 -0
  330. package/dist/replay/window-queue.js +497 -0
  331. package/dist/replay/window-queue.js.map +1 -0
  332. package/dist/runtime/action-mcp-server.d.ts +30 -0
  333. package/dist/runtime/action-mcp-server.d.ts.map +1 -0
  334. package/dist/runtime/action-mcp-server.js +179 -0
  335. package/dist/runtime/action-mcp-server.js.map +1 -0
  336. package/dist/runtime/action-surface.d.ts +47 -0
  337. package/dist/runtime/action-surface.d.ts.map +1 -0
  338. package/dist/runtime/action-surface.js +182 -0
  339. package/dist/runtime/action-surface.js.map +1 -0
  340. package/dist/runtime/backend-security.d.ts +7 -0
  341. package/dist/runtime/backend-security.d.ts.map +1 -0
  342. package/dist/runtime/backend-security.js +28 -0
  343. package/dist/runtime/backend-security.js.map +1 -0
  344. package/dist/runtime/claude-caller-hook.d.ts +20 -0
  345. package/dist/runtime/claude-caller-hook.d.ts.map +1 -0
  346. package/dist/runtime/claude-caller-hook.js +41 -0
  347. package/dist/runtime/claude-caller-hook.js.map +1 -0
  348. package/dist/runtime/config.d.ts +84 -0
  349. package/dist/runtime/config.d.ts.map +1 -0
  350. package/dist/runtime/config.js +361 -0
  351. package/dist/runtime/config.js.map +1 -0
  352. package/dist/runtime/connectors.d.ts +41 -0
  353. package/dist/runtime/connectors.d.ts.map +1 -0
  354. package/dist/runtime/connectors.js +187 -0
  355. package/dist/runtime/connectors.js.map +1 -0
  356. package/dist/runtime/core-db.d.ts +8 -0
  357. package/dist/runtime/core-db.d.ts.map +1 -0
  358. package/dist/runtime/core-db.js +19 -0
  359. package/dist/runtime/core-db.js.map +1 -0
  360. package/dist/runtime/model-cache.d.ts +9 -0
  361. package/dist/runtime/model-cache.d.ts.map +1 -0
  362. package/dist/runtime/model-cache.js +22 -0
  363. package/dist/runtime/model-cache.js.map +1 -0
  364. package/dist/runtime/native-session.d.ts +80 -0
  365. package/dist/runtime/native-session.d.ts.map +1 -0
  366. package/dist/runtime/native-session.js +284 -0
  367. package/dist/runtime/native-session.js.map +1 -0
  368. package/dist/runtime/owner-policy.d.ts +10 -0
  369. package/dist/runtime/owner-policy.d.ts.map +1 -0
  370. package/dist/runtime/owner-policy.js +35 -0
  371. package/dist/runtime/owner-policy.js.map +1 -0
  372. package/dist/runtime/owner-runtime.d.ts +78 -0
  373. package/dist/runtime/owner-runtime.d.ts.map +1 -0
  374. package/dist/runtime/owner-runtime.js +255 -0
  375. package/dist/runtime/owner-runtime.js.map +1 -0
  376. package/dist/runtime/owner-system-prompt.d.ts +17 -0
  377. package/dist/runtime/owner-system-prompt.d.ts.map +1 -0
  378. package/dist/runtime/owner-system-prompt.js +122 -0
  379. package/dist/runtime/owner-system-prompt.js.map +1 -0
  380. package/dist/runtime/recent-owner-exchanges.d.ts +10 -0
  381. package/dist/runtime/recent-owner-exchanges.d.ts.map +1 -0
  382. package/dist/runtime/recent-owner-exchanges.js +53 -0
  383. package/dist/runtime/recent-owner-exchanges.js.map +1 -0
  384. package/dist/runtime/report-prompts.d.ts +14 -0
  385. package/dist/runtime/report-prompts.d.ts.map +1 -0
  386. package/dist/runtime/report-prompts.js +69 -0
  387. package/dist/runtime/report-prompts.js.map +1 -0
  388. package/dist/runtime/report-scheduler.d.ts +24 -0
  389. package/dist/runtime/report-scheduler.d.ts.map +1 -0
  390. package/dist/runtime/report-scheduler.js +97 -0
  391. package/dist/runtime/report-scheduler.js.map +1 -0
  392. package/dist/runtime/session-credential.d.ts +5 -0
  393. package/dist/runtime/session-credential.d.ts.map +1 -0
  394. package/dist/runtime/session-credential.js +19 -0
  395. package/dist/runtime/session-credential.js.map +1 -0
  396. package/dist/runtime/stimulus-delivery.d.ts +85 -0
  397. package/dist/runtime/stimulus-delivery.d.ts.map +1 -0
  398. package/dist/runtime/stimulus-delivery.js +590 -0
  399. package/dist/runtime/stimulus-delivery.js.map +1 -0
  400. package/dist/runtime/timezone.d.ts +13 -0
  401. package/dist/runtime/timezone.d.ts.map +1 -0
  402. package/dist/runtime/timezone.js +119 -0
  403. package/dist/runtime/timezone.js.map +1 -0
  404. package/dist/sqlite.d.ts +7 -32
  405. package/dist/sqlite.d.ts.map +1 -1
  406. package/dist/sqlite.js +10 -48
  407. package/dist/sqlite.js.map +1 -1
  408. package/dist/storage/migrations/raw-item-revisions.d.ts +6 -0
  409. package/dist/storage/migrations/raw-item-revisions.d.ts.map +1 -0
  410. package/dist/storage/migrations/raw-item-revisions.js +109 -0
  411. package/dist/storage/migrations/raw-item-revisions.js.map +1 -0
  412. package/dist/storage/migrations-source.d.ts +5 -0
  413. package/dist/storage/migrations-source.d.ts.map +1 -0
  414. package/dist/storage/migrations-source.js +24 -0
  415. package/dist/storage/migrations-source.js.map +1 -0
  416. package/dist/storage/source-archive.d.ts +123 -0
  417. package/dist/storage/source-archive.d.ts.map +1 -0
  418. package/dist/storage/source-archive.js +595 -0
  419. package/dist/storage/source-archive.js.map +1 -0
  420. package/dist/storage-sqlite.d.ts +59 -0
  421. package/dist/storage-sqlite.d.ts.map +1 -0
  422. package/dist/storage-sqlite.js +75 -0
  423. package/dist/storage-sqlite.js.map +1 -0
  424. package/dist/utils/untrusted-content.d.ts +5 -35
  425. package/dist/utils/untrusted-content.d.ts.map +1 -1
  426. package/dist/utils/untrusted-content.js +16 -75
  427. package/dist/utils/untrusted-content.js.map +1 -1
  428. package/dist/wiki/obsidian-writer.d.ts +4 -2
  429. package/dist/wiki/obsidian-writer.d.ts.map +1 -1
  430. package/dist/wiki/obsidian-writer.js +85 -4
  431. package/dist/wiki/obsidian-writer.js.map +1 -1
  432. package/dist/wiki/path-safety.d.ts +2 -0
  433. package/dist/wiki/path-safety.d.ts.map +1 -1
  434. package/dist/wiki/path-safety.js +11 -3
  435. package/dist/wiki/path-safety.js.map +1 -1
  436. package/dist/wiki/wiki-edits.d.ts +17 -0
  437. package/dist/wiki/wiki-edits.d.ts.map +1 -0
  438. package/dist/wiki/wiki-edits.js +75 -0
  439. package/dist/wiki/wiki-edits.js.map +1 -0
  440. package/dist/wiki/wiki-read.d.ts +20 -11
  441. package/dist/wiki/wiki-read.d.ts.map +1 -1
  442. package/dist/wiki/wiki-read.js +87 -89
  443. package/dist/wiki/wiki-read.js.map +1 -1
  444. package/dist/wiki-artifacts/types.d.ts +1 -1
  445. package/dist/wiki-artifacts/types.d.ts.map +1 -1
  446. package/dist/wiki-artifacts/wiki-publish-adapter.d.ts.map +1 -1
  447. package/dist/wiki-artifacts/wiki-publish-adapter.js +13 -9
  448. package/dist/wiki-artifacts/wiki-publish-adapter.js.map +1 -1
  449. package/package.json +11 -41
  450. package/public/viewer/js/modules/graph.js +111 -41
  451. package/public/viewer/js/modules/memory.js +4 -31
  452. package/public/viewer/js/modules/wiki.js +0 -37
  453. package/public/viewer/js/utils/api.js +4 -50
  454. package/public/viewer/log-viewer.html +46 -0
  455. package/public/viewer/operator/operator.css +1 -1
  456. package/public/viewer/operator/operator.js +10835 -8211
  457. package/public/viewer/src/modules/graph.ts +133 -41
  458. package/public/viewer/src/modules/memory.ts +4 -31
  459. package/public/viewer/src/modules/wiki.ts +0 -42
  460. package/public/viewer/src/types/global.d.ts +1 -1
  461. package/public/viewer/src/utils/api.ts +7 -83
  462. package/public/viewer/viewer.html +7 -96
  463. package/dist/agent/agent-loop.d.ts +0 -289
  464. package/dist/agent/agent-loop.d.ts.map +0 -1
  465. package/dist/agent/agent-loop.js +0 -2842
  466. package/dist/agent/agent-loop.js.map +0 -1
  467. package/dist/agent/attachment-text-extractor.d.ts +0 -2
  468. package/dist/agent/attachment-text-extractor.d.ts.map +0 -1
  469. package/dist/agent/attachment-text-extractor.js +0 -128
  470. package/dist/agent/attachment-text-extractor.js.map +0 -1
  471. package/dist/agent/backend-model-policy.d.ts +0 -58
  472. package/dist/agent/backend-model-policy.d.ts.map +0 -1
  473. package/dist/agent/backend-model-policy.js +0 -167
  474. package/dist/agent/backend-model-policy.js.map +0 -1
  475. package/dist/agent/backend-model-runner-factory.d.ts +0 -27
  476. package/dist/agent/backend-model-runner-factory.d.ts.map +0 -1
  477. package/dist/agent/backend-model-runner-factory.js +0 -88
  478. package/dist/agent/backend-model-runner-factory.js.map +0 -1
  479. package/dist/agent/claude-cli-wrapper.d.ts +0 -144
  480. package/dist/agent/claude-cli-wrapper.d.ts.map +0 -1
  481. package/dist/agent/claude-cli-wrapper.js +0 -382
  482. package/dist/agent/claude-cli-wrapper.js.map +0 -1
  483. package/dist/agent/cli-arg-redaction.d.ts +0 -2
  484. package/dist/agent/cli-arg-redaction.d.ts.map +0 -1
  485. package/dist/agent/cli-arg-redaction.js +0 -18
  486. package/dist/agent/cli-arg-redaction.js.map +0 -1
  487. package/dist/agent/cline-cli-adapter.d.ts +0 -126
  488. package/dist/agent/cline-cli-adapter.d.ts.map +0 -1
  489. package/dist/agent/cline-cli-adapter.js +0 -1042
  490. package/dist/agent/cline-cli-adapter.js.map +0 -1
  491. package/dist/agent/cline-native-tool-policy.d.ts +0 -9
  492. package/dist/agent/cline-native-tool-policy.d.ts.map +0 -1
  493. package/dist/agent/cline-native-tool-policy.js +0 -61
  494. package/dist/agent/cline-native-tool-policy.js.map +0 -1
  495. package/dist/agent/code-act/completed-terminal-result.d.ts +0 -5
  496. package/dist/agent/code-act/completed-terminal-result.d.ts.map +0 -1
  497. package/dist/agent/code-act/completed-terminal-result.js +0 -83
  498. package/dist/agent/code-act/completed-terminal-result.js.map +0 -1
  499. package/dist/agent/code-act/constants.d.ts +0 -11
  500. package/dist/agent/code-act/constants.d.ts.map +0 -1
  501. package/dist/agent/code-act/constants.js +0 -64
  502. package/dist/agent/code-act/constants.js.map +0 -1
  503. package/dist/agent/code-act/host-bridge.d.ts +0 -50
  504. package/dist/agent/code-act/host-bridge.d.ts.map +0 -1
  505. package/dist/agent/code-act/host-bridge.js +0 -1405
  506. package/dist/agent/code-act/host-bridge.js.map +0 -1
  507. package/dist/agent/code-act/index.d.ts +0 -10
  508. package/dist/agent/code-act/index.d.ts.map +0 -1
  509. package/dist/agent/code-act/index.js +0 -22
  510. package/dist/agent/code-act/index.js.map +0 -1
  511. package/dist/agent/code-act/run-context-registry.d.ts +0 -36
  512. package/dist/agent/code-act/run-context-registry.d.ts.map +0 -1
  513. package/dist/agent/code-act/run-context-registry.js +0 -143
  514. package/dist/agent/code-act/run-context-registry.js.map +0 -1
  515. package/dist/agent/code-act/sandbox.d.ts +0 -25
  516. package/dist/agent/code-act/sandbox.d.ts.map +0 -1
  517. package/dist/agent/code-act/sandbox.js +0 -494
  518. package/dist/agent/code-act/sandbox.js.map +0 -1
  519. package/dist/agent/code-act/tool-catalog.d.ts +0 -30
  520. package/dist/agent/code-act/tool-catalog.d.ts.map +0 -1
  521. package/dist/agent/code-act/tool-catalog.js +0 -185
  522. package/dist/agent/code-act/tool-catalog.js.map +0 -1
  523. package/dist/agent/code-act/tool-policy.d.ts +0 -51
  524. package/dist/agent/code-act/tool-policy.d.ts.map +0 -1
  525. package/dist/agent/code-act/tool-policy.js +0 -160
  526. package/dist/agent/code-act/tool-policy.js.map +0 -1
  527. package/dist/agent/code-act/type-definition-generator.d.ts +0 -19
  528. package/dist/agent/code-act/type-definition-generator.d.ts.map +0 -1
  529. package/dist/agent/code-act/type-definition-generator.js +0 -73
  530. package/dist/agent/code-act/type-definition-generator.js.map +0 -1
  531. package/dist/agent/code-act/types.d.ts +0 -57
  532. package/dist/agent/code-act/types.d.ts.map +0 -1
  533. package/dist/agent/code-act/types.js +0 -14
  534. package/dist/agent/code-act/types.js.map +0 -1
  535. package/dist/agent/codex-app-server-process.d.ts +0 -257
  536. package/dist/agent/codex-app-server-process.d.ts.map +0 -1
  537. package/dist/agent/codex-app-server-process.js +0 -2084
  538. package/dist/agent/codex-app-server-process.js.map +0 -1
  539. package/dist/agent/codex-auth.d.ts +0 -2
  540. package/dist/agent/codex-auth.d.ts.map +0 -1
  541. package/dist/agent/codex-auth.js +0 -17
  542. package/dist/agent/codex-auth.js.map +0 -1
  543. package/dist/agent/codex-auxiliary-tools.d.ts +0 -17
  544. package/dist/agent/codex-auxiliary-tools.d.ts.map +0 -1
  545. package/dist/agent/codex-auxiliary-tools.js +0 -267
  546. package/dist/agent/codex-auxiliary-tools.js.map +0 -1
  547. package/dist/agent/codex-home.d.ts +0 -13
  548. package/dist/agent/codex-home.d.ts.map +0 -1
  549. package/dist/agent/codex-home.js +0 -644
  550. package/dist/agent/codex-home.js.map +0 -1
  551. package/dist/agent/codex-thread-registry.d.ts +0 -63
  552. package/dist/agent/codex-thread-registry.d.ts.map +0 -1
  553. package/dist/agent/codex-thread-registry.js +0 -433
  554. package/dist/agent/codex-thread-registry.js.map +0 -1
  555. package/dist/agent/content-dedup.d.ts +0 -86
  556. package/dist/agent/content-dedup.d.ts.map +0 -1
  557. package/dist/agent/content-dedup.js +0 -114
  558. package/dist/agent/content-dedup.js.map +0 -1
  559. package/dist/agent/context-compile-contract.d.ts +0 -5
  560. package/dist/agent/context-compile-contract.d.ts.map +0 -1
  561. package/dist/agent/context-compile-contract.js +0 -8
  562. package/dist/agent/context-compile-contract.js.map +0 -1
  563. package/dist/agent/context-compile-service.d.ts +0 -60
  564. package/dist/agent/context-compile-service.d.ts.map +0 -1
  565. package/dist/agent/context-compile-service.js +0 -481
  566. package/dist/agent/context-compile-service.js.map +0 -1
  567. package/dist/agent/context-prompt-builder.d.ts +0 -24
  568. package/dist/agent/context-prompt-builder.d.ts.map +0 -1
  569. package/dist/agent/context-prompt-builder.js +0 -61
  570. package/dist/agent/context-prompt-builder.js.map +0 -1
  571. package/dist/agent/contract-extractor.d.ts +0 -124
  572. package/dist/agent/contract-extractor.d.ts.map +0 -1
  573. package/dist/agent/contract-extractor.js +0 -465
  574. package/dist/agent/contract-extractor.js.map +0 -1
  575. package/dist/agent/drive-tools.d.ts +0 -83
  576. package/dist/agent/drive-tools.d.ts.map +0 -1
  577. package/dist/agent/drive-tools.js +0 -338
  578. package/dist/agent/drive-tools.js.map +0 -1
  579. package/dist/agent/gateway-tool-catalog.d.ts +0 -14
  580. package/dist/agent/gateway-tool-catalog.d.ts.map +0 -1
  581. package/dist/agent/gateway-tool-catalog.js +0 -41
  582. package/dist/agent/gateway-tool-catalog.js.map +0 -1
  583. package/dist/agent/gateway-tool-executor.d.ts +0 -353
  584. package/dist/agent/gateway-tool-executor.d.ts.map +0 -1
  585. package/dist/agent/gateway-tool-executor.js +0 -5448
  586. package/dist/agent/gateway-tool-executor.js.map +0 -1
  587. package/dist/agent/gateway-tools.md +0 -166
  588. package/dist/agent/image-translation-tools.d.ts +0 -48
  589. package/dist/agent/image-translation-tools.d.ts.map +0 -1
  590. package/dist/agent/image-translation-tools.js +0 -274
  591. package/dist/agent/image-translation-tools.js.map +0 -1
  592. package/dist/agent/index.d.ts +0 -13
  593. package/dist/agent/index.d.ts.map +0 -1
  594. package/dist/agent/index.js +0 -18
  595. package/dist/agent/index.js.map +0 -1
  596. package/dist/agent/mama-tool-handlers.d.ts +0 -11
  597. package/dist/agent/mama-tool-handlers.d.ts.map +0 -1
  598. package/dist/agent/mama-tool-handlers.js +0 -220
  599. package/dist/agent/mama-tool-handlers.js.map +0 -1
  600. package/dist/agent/managed-agent-runtime-sync.d.ts +0 -36
  601. package/dist/agent/managed-agent-runtime-sync.d.ts.map +0 -1
  602. package/dist/agent/managed-agent-runtime-sync.js +0 -245
  603. package/dist/agent/managed-agent-runtime-sync.js.map +0 -1
  604. package/dist/agent/managed-agent-validation.d.ts +0 -4
  605. package/dist/agent/managed-agent-validation.d.ts.map +0 -1
  606. package/dist/agent/managed-agent-validation.js +0 -85
  607. package/dist/agent/managed-agent-validation.js.map +0 -1
  608. package/dist/agent/model-runner.d.ts +0 -180
  609. package/dist/agent/model-runner.d.ts.map +0 -1
  610. package/dist/agent/model-runner.js +0 -54
  611. package/dist/agent/model-runner.js.map +0 -1
  612. package/dist/agent/native-effect-observer.d.ts +0 -20
  613. package/dist/agent/native-effect-observer.d.ts.map +0 -1
  614. package/dist/agent/native-effect-observer.js +0 -86
  615. package/dist/agent/native-effect-observer.js.map +0 -1
  616. package/dist/agent/obsidian-cli-args.d.ts +0 -14
  617. package/dist/agent/obsidian-cli-args.d.ts.map +0 -1
  618. package/dist/agent/obsidian-cli-args.js +0 -57
  619. package/dist/agent/obsidian-cli-args.js.map +0 -1
  620. package/dist/agent/os-agent-capabilities.md +0 -367
  621. package/dist/agent/persistent-cli-adapter.d.ts +0 -173
  622. package/dist/agent/persistent-cli-adapter.d.ts.map +0 -1
  623. package/dist/agent/persistent-cli-adapter.js +0 -467
  624. package/dist/agent/persistent-cli-adapter.js.map +0 -1
  625. package/dist/agent/persistent-cli-process.d.ts +0 -392
  626. package/dist/agent/persistent-cli-process.d.ts.map +0 -1
  627. package/dist/agent/persistent-cli-process.js +0 -1568
  628. package/dist/agent/persistent-cli-process.js.map +0 -1
  629. package/dist/agent/post-tool-handler.d.ts +0 -27
  630. package/dist/agent/post-tool-handler.d.ts.map +0 -1
  631. package/dist/agent/post-tool-handler.js +0 -194
  632. package/dist/agent/post-tool-handler.js.map +0 -1
  633. package/dist/agent/pre-compact-handler.d.ts +0 -36
  634. package/dist/agent/pre-compact-handler.d.ts.map +0 -1
  635. package/dist/agent/pre-compact-handler.js +0 -162
  636. package/dist/agent/pre-compact-handler.js.map +0 -1
  637. package/dist/agent/prompt-enhancer.d.ts +0 -33
  638. package/dist/agent/prompt-enhancer.d.ts.map +0 -1
  639. package/dist/agent/prompt-enhancer.js +0 -811
  640. package/dist/agent/prompt-enhancer.js.map +0 -1
  641. package/dist/agent/prompt-size-monitor.d.ts +0 -104
  642. package/dist/agent/prompt-size-monitor.d.ts.map +0 -1
  643. package/dist/agent/prompt-size-monitor.js +0 -192
  644. package/dist/agent/prompt-size-monitor.js.map +0 -1
  645. package/dist/agent/role-manager.d.ts +0 -122
  646. package/dist/agent/role-manager.d.ts.map +0 -1
  647. package/dist/agent/role-manager.js +0 -300
  648. package/dist/agent/role-manager.js.map +0 -1
  649. package/dist/agent/session-pool.d.ts +0 -176
  650. package/dist/agent/session-pool.d.ts.map +0 -1
  651. package/dist/agent/session-pool.js +0 -368
  652. package/dist/agent/session-pool.js.map +0 -1
  653. package/dist/agent/skill-loader.d.ts +0 -87
  654. package/dist/agent/skill-loader.d.ts.map +0 -1
  655. package/dist/agent/skill-loader.js +0 -461
  656. package/dist/agent/skill-loader.js.map +0 -1
  657. package/dist/agent/stop-continuation-handler.d.ts +0 -106
  658. package/dist/agent/stop-continuation-handler.d.ts.map +0 -1
  659. package/dist/agent/stop-continuation-handler.js +0 -230
  660. package/dist/agent/stop-continuation-handler.js.map +0 -1
  661. package/dist/agent/subagent-run-reconcile.d.ts +0 -23
  662. package/dist/agent/subagent-run-reconcile.d.ts.map +0 -1
  663. package/dist/agent/subagent-run-reconcile.js +0 -56
  664. package/dist/agent/subagent-run-reconcile.js.map +0 -1
  665. package/dist/agent/temporal-code-act-breaker.d.ts +0 -26
  666. package/dist/agent/temporal-code-act-breaker.d.ts.map +0 -1
  667. package/dist/agent/temporal-code-act-breaker.js +0 -94
  668. package/dist/agent/temporal-code-act-breaker.js.map +0 -1
  669. package/dist/agent/token-estimator.d.ts +0 -25
  670. package/dist/agent/token-estimator.d.ts.map +0 -1
  671. package/dist/agent/token-estimator.js +0 -75
  672. package/dist/agent/token-estimator.js.map +0 -1
  673. package/dist/agent/tool-registry.d.ts +0 -81
  674. package/dist/agent/tool-registry.d.ts.map +0 -1
  675. package/dist/agent/tool-registry.js +0 -876
  676. package/dist/agent/tool-registry.js.map +0 -1
  677. package/dist/agent/types.d.ts +0 -1261
  678. package/dist/agent/types.d.ts.map +0 -1
  679. package/dist/agent/types.js +0 -60
  680. package/dist/agent/types.js.map +0 -1
  681. package/dist/agent/yaml-frontmatter.d.ts +0 -75
  682. package/dist/agent/yaml-frontmatter.d.ts.map +0 -1
  683. package/dist/agent/yaml-frontmatter.js +0 -166
  684. package/dist/agent/yaml-frontmatter.js.map +0 -1
  685. package/dist/api/agent-context-handler.d.ts +0 -10
  686. package/dist/api/agent-context-handler.d.ts.map +0 -1
  687. package/dist/api/agent-context-handler.js +0 -216
  688. package/dist/api/agent-context-handler.js.map +0 -1
  689. package/dist/api/agent-graph-handler.d.ts +0 -18
  690. package/dist/api/agent-graph-handler.d.ts.map +0 -1
  691. package/dist/api/agent-graph-handler.js +0 -569
  692. package/dist/api/agent-graph-handler.js.map +0 -1
  693. package/dist/api/agent-handler.d.ts +0 -36
  694. package/dist/api/agent-handler.d.ts.map +0 -1
  695. package/dist/api/agent-handler.js +0 -223
  696. package/dist/api/agent-handler.js.map +0 -1
  697. package/dist/api/agent-raw-handler.d.ts +0 -70
  698. package/dist/api/agent-raw-handler.d.ts.map +0 -1
  699. package/dist/api/agent-raw-handler.js +0 -262
  700. package/dist/api/agent-raw-handler.js.map +0 -1
  701. package/dist/api/agent-situation-handler.d.ts +0 -14
  702. package/dist/api/agent-situation-handler.d.ts.map +0 -1
  703. package/dist/api/agent-situation-handler.js +0 -383
  704. package/dist/api/agent-situation-handler.js.map +0 -1
  705. package/dist/api/connector-feed-handler.d.ts +0 -42
  706. package/dist/api/connector-feed-handler.d.ts.map +0 -1
  707. package/dist/api/connector-feed-handler.js +0 -180
  708. package/dist/api/connector-feed-handler.js.map +0 -1
  709. package/dist/api/cron-handler.d.ts +0 -44
  710. package/dist/api/cron-handler.d.ts.map +0 -1
  711. package/dist/api/cron-handler.js +0 -261
  712. package/dist/api/cron-handler.js.map +0 -1
  713. package/dist/api/entity-audit-handler.d.ts +0 -12
  714. package/dist/api/entity-audit-handler.d.ts.map +0 -1
  715. package/dist/api/entity-audit-handler.js +0 -119
  716. package/dist/api/entity-audit-handler.js.map +0 -1
  717. package/dist/api/entity-audit-queue.d.ts +0 -74
  718. package/dist/api/entity-audit-queue.d.ts.map +0 -1
  719. package/dist/api/entity-audit-queue.js +0 -123
  720. package/dist/api/entity-audit-queue.js.map +0 -1
  721. package/dist/api/entity-audit-runner.d.ts +0 -9
  722. package/dist/api/entity-audit-runner.d.ts.map +0 -1
  723. package/dist/api/entity-audit-runner.js +0 -240
  724. package/dist/api/entity-audit-runner.js.map +0 -1
  725. package/dist/api/entity-review-handler.d.ts +0 -18
  726. package/dist/api/entity-review-handler.d.ts.map +0 -1
  727. package/dist/api/entity-review-handler.js +0 -521
  728. package/dist/api/entity-review-handler.js.map +0 -1
  729. package/dist/api/error-handler.d.ts +0 -22
  730. package/dist/api/error-handler.d.ts.map +0 -1
  731. package/dist/api/error-handler.js +0 -104
  732. package/dist/api/error-handler.js.map +0 -1
  733. package/dist/api/graph-api-types.d.ts +0 -105
  734. package/dist/api/graph-api-types.d.ts.map +0 -1
  735. package/dist/api/graph-api-types.js +0 -6
  736. package/dist/api/graph-api-types.js.map +0 -1
  737. package/dist/api/graph-api.d.ts +0 -42
  738. package/dist/api/graph-api.d.ts.map +0 -1
  739. package/dist/api/graph-api.js +0 -3460
  740. package/dist/api/graph-api.js.map +0 -1
  741. package/dist/api/heartbeat-handler.d.ts +0 -49
  742. package/dist/api/heartbeat-handler.d.ts.map +0 -1
  743. package/dist/api/heartbeat-handler.js +0 -106
  744. package/dist/api/heartbeat-handler.js.map +0 -1
  745. package/dist/api/index.d.ts +0 -145
  746. package/dist/api/index.d.ts.map +0 -1
  747. package/dist/api/index.js +0 -448
  748. package/dist/api/index.js.map +0 -1
  749. package/dist/api/intelligence-handler.d.ts +0 -116
  750. package/dist/api/intelligence-handler.d.ts.map +0 -1
  751. package/dist/api/intelligence-handler.js +0 -280
  752. package/dist/api/intelligence-handler.js.map +0 -1
  753. package/dist/api/memory-provenance-handler.d.ts +0 -3
  754. package/dist/api/memory-provenance-handler.d.ts.map +0 -1
  755. package/dist/api/memory-provenance-handler.js +0 -120
  756. package/dist/api/memory-provenance-handler.js.map +0 -1
  757. package/dist/api/operator-handler.d.ts +0 -19
  758. package/dist/api/operator-handler.d.ts.map +0 -1
  759. package/dist/api/operator-handler.js +0 -106
  760. package/dist/api/operator-handler.js.map +0 -1
  761. package/dist/api/operator-summary.d.ts +0 -3
  762. package/dist/api/operator-summary.d.ts.map +0 -1
  763. package/dist/api/operator-summary.js +0 -72
  764. package/dist/api/operator-summary.js.map +0 -1
  765. package/dist/api/operator-tasks-handler.d.ts +0 -7
  766. package/dist/api/operator-tasks-handler.d.ts.map +0 -1
  767. package/dist/api/operator-tasks-handler.js +0 -192
  768. package/dist/api/operator-tasks-handler.js.map +0 -1
  769. package/dist/api/runtime-status-handler.d.ts +0 -42
  770. package/dist/api/runtime-status-handler.d.ts.map +0 -1
  771. package/dist/api/runtime-status-handler.js +0 -56
  772. package/dist/api/runtime-status-handler.js.map +0 -1
  773. package/dist/api/skills-handler.d.ts +0 -12
  774. package/dist/api/skills-handler.d.ts.map +0 -1
  775. package/dist/api/skills-handler.js +0 -156
  776. package/dist/api/skills-handler.js.map +0 -1
  777. package/dist/api/token-handler.d.ts +0 -33
  778. package/dist/api/token-handler.d.ts.map +0 -1
  779. package/dist/api/token-handler.js +0 -118
  780. package/dist/api/token-handler.js.map +0 -1
  781. package/dist/api/types.d.ts +0 -155
  782. package/dist/api/types.d.ts.map +0 -1
  783. package/dist/api/types.js +0 -49
  784. package/dist/api/types.js.map +0 -1
  785. package/dist/api/ui-command-handler.d.ts +0 -48
  786. package/dist/api/ui-command-handler.d.ts.map +0 -1
  787. package/dist/api/ui-command-handler.js +0 -160
  788. package/dist/api/ui-command-handler.js.map +0 -1
  789. package/dist/api/upload-handler.d.ts +0 -12
  790. package/dist/api/upload-handler.d.ts.map +0 -1
  791. package/dist/api/upload-handler.js +0 -321
  792. package/dist/api/upload-handler.js.map +0 -1
  793. package/dist/api/wiki-handler.d.ts +0 -19
  794. package/dist/api/wiki-handler.d.ts.map +0 -1
  795. package/dist/api/wiki-handler.js +0 -136
  796. package/dist/api/wiki-handler.js.map +0 -1
  797. package/dist/api/worker-envelope.d.ts +0 -26
  798. package/dist/api/worker-envelope.d.ts.map +0 -1
  799. package/dist/api/worker-envelope.js +0 -176
  800. package/dist/api/worker-envelope.js.map +0 -1
  801. package/dist/auth/claude-client.d.ts +0 -12
  802. package/dist/auth/claude-client.d.ts.map +0 -1
  803. package/dist/auth/claude-client.js +0 -36
  804. package/dist/auth/claude-client.js.map +0 -1
  805. package/dist/auth/claude-code-auth.d.ts +0 -12
  806. package/dist/auth/claude-code-auth.d.ts.map +0 -1
  807. package/dist/auth/claude-code-auth.js +0 -85
  808. package/dist/auth/claude-code-auth.js.map +0 -1
  809. package/dist/auth/index.d.ts +0 -9
  810. package/dist/auth/index.d.ts.map +0 -1
  811. package/dist/auth/index.js +0 -13
  812. package/dist/auth/index.js.map +0 -1
  813. package/dist/auth/oauth-manager.d.ts +0 -59
  814. package/dist/auth/oauth-manager.d.ts.map +0 -1
  815. package/dist/auth/oauth-manager.js +0 -252
  816. package/dist/auth/oauth-manager.js.map +0 -1
  817. package/dist/auth/types.d.ts +0 -92
  818. package/dist/auth/types.d.ts.map +0 -1
  819. package/dist/auth/types.js +0 -23
  820. package/dist/auth/types.js.map +0 -1
  821. package/dist/cli/commands/connector.d.ts +0 -14
  822. package/dist/cli/commands/connector.d.ts.map +0 -1
  823. package/dist/cli/commands/connector.js +0 -174
  824. package/dist/cli/commands/connector.js.map +0 -1
  825. package/dist/cli/commands/gateway.d.ts +0 -18
  826. package/dist/cli/commands/gateway.d.ts.map +0 -1
  827. package/dist/cli/commands/gateway.js +0 -144
  828. package/dist/cli/commands/gateway.js.map +0 -1
  829. package/dist/cli/commands/report.d.ts +0 -14
  830. package/dist/cli/commands/report.d.ts.map +0 -1
  831. package/dist/cli/commands/report.js +0 -102
  832. package/dist/cli/commands/report.js.map +0 -1
  833. package/dist/cli/commands/run.d.ts +0 -19
  834. package/dist/cli/commands/run.d.ts.map +0 -1
  835. package/dist/cli/commands/run.js +0 -123
  836. package/dist/cli/commands/run.js.map +0 -1
  837. package/dist/cli/commands/setup.d.ts +0 -3
  838. package/dist/cli/commands/setup.d.ts.map +0 -1
  839. package/dist/cli/commands/setup.js +0 -9
  840. package/dist/cli/commands/setup.js.map +0 -1
  841. package/dist/cli/commands/start.d.ts +0 -263
  842. package/dist/cli/commands/start.d.ts.map +0 -1
  843. package/dist/cli/commands/start.js +0 -2230
  844. package/dist/cli/commands/start.js.map +0 -1
  845. package/dist/cli/commands/status.d.ts +0 -18
  846. package/dist/cli/commands/status.d.ts.map +0 -1
  847. package/dist/cli/commands/status.js +0 -326
  848. package/dist/cli/commands/status.js.map +0 -1
  849. package/dist/cli/commands/stop.d.ts +0 -28
  850. package/dist/cli/commands/stop.d.ts.map +0 -1
  851. package/dist/cli/commands/stop.js +0 -597
  852. package/dist/cli/commands/stop.js.map +0 -1
  853. package/dist/cli/config/config-manager.d.ts +0 -84
  854. package/dist/cli/config/config-manager.d.ts.map +0 -1
  855. package/dist/cli/config/config-manager.js +0 -886
  856. package/dist/cli/config/config-manager.js.map +0 -1
  857. package/dist/cli/config/types.d.ts +0 -633
  858. package/dist/cli/config/types.d.ts.map +0 -1
  859. package/dist/cli/config/types.js +0 -247
  860. package/dist/cli/config/types.js.map +0 -1
  861. package/dist/cli/runtime/agent-loop-init.d.ts +0 -53
  862. package/dist/cli/runtime/agent-loop-init.d.ts.map +0 -1
  863. package/dist/cli/runtime/agent-loop-init.js +0 -368
  864. package/dist/cli/runtime/agent-loop-init.js.map +0 -1
  865. package/dist/cli/runtime/api-routes-init.d.ts +0 -84
  866. package/dist/cli/runtime/api-routes-init.d.ts.map +0 -1
  867. package/dist/cli/runtime/api-routes-init.js +0 -1542
  868. package/dist/cli/runtime/api-routes-init.js.map +0 -1
  869. package/dist/cli/runtime/api-server-init.d.ts +0 -59
  870. package/dist/cli/runtime/api-server-init.d.ts.map +0 -1
  871. package/dist/cli/runtime/api-server-init.js +0 -159
  872. package/dist/cli/runtime/api-server-init.js.map +0 -1
  873. package/dist/cli/runtime/code-act-executor.d.ts +0 -14
  874. package/dist/cli/runtime/code-act-executor.d.ts.map +0 -1
  875. package/dist/cli/runtime/code-act-executor.js +0 -108
  876. package/dist/cli/runtime/code-act-executor.js.map +0 -1
  877. package/dist/cli/runtime/connector-bootstrap.d.ts +0 -8
  878. package/dist/cli/runtime/connector-bootstrap.d.ts.map +0 -1
  879. package/dist/cli/runtime/connector-bootstrap.js +0 -14
  880. package/dist/cli/runtime/connector-bootstrap.js.map +0 -1
  881. package/dist/cli/runtime/connector-init.d.ts +0 -64
  882. package/dist/cli/runtime/connector-init.d.ts.map +0 -1
  883. package/dist/cli/runtime/connector-init.js +0 -237
  884. package/dist/cli/runtime/connector-init.js.map +0 -1
  885. package/dist/cli/runtime/daemon.d.ts +0 -38
  886. package/dist/cli/runtime/daemon.d.ts.map +0 -1
  887. package/dist/cli/runtime/daemon.js +0 -263
  888. package/dist/cli/runtime/daemon.js.map +0 -1
  889. package/dist/cli/runtime/envelope-bootstrap.d.ts +0 -17
  890. package/dist/cli/runtime/envelope-bootstrap.d.ts.map +0 -1
  891. package/dist/cli/runtime/envelope-bootstrap.js +0 -56
  892. package/dist/cli/runtime/envelope-bootstrap.js.map +0 -1
  893. package/dist/cli/runtime/gateway-init.d.ts +0 -55
  894. package/dist/cli/runtime/gateway-init.d.ts.map +0 -1
  895. package/dist/cli/runtime/gateway-init.js +0 -196
  896. package/dist/cli/runtime/gateway-init.js.map +0 -1
  897. package/dist/cli/runtime/gateway-wiring.d.ts +0 -51
  898. package/dist/cli/runtime/gateway-wiring.d.ts.map +0 -1
  899. package/dist/cli/runtime/gateway-wiring.js +0 -215
  900. package/dist/cli/runtime/gateway-wiring.js.map +0 -1
  901. package/dist/cli/runtime/mama-core-init.d.ts +0 -42
  902. package/dist/cli/runtime/mama-core-init.d.ts.map +0 -1
  903. package/dist/cli/runtime/mama-core-init.js +0 -211
  904. package/dist/cli/runtime/mama-core-init.js.map +0 -1
  905. package/dist/cli/runtime/message-router-config.d.ts +0 -4
  906. package/dist/cli/runtime/message-router-config.d.ts.map +0 -1
  907. package/dist/cli/runtime/message-router-config.js +0 -11
  908. package/dist/cli/runtime/message-router-config.js.map +0 -1
  909. package/dist/cli/runtime/metrics-init.d.ts +0 -28
  910. package/dist/cli/runtime/metrics-init.d.ts.map +0 -1
  911. package/dist/cli/runtime/metrics-init.js +0 -131
  912. package/dist/cli/runtime/metrics-init.js.map +0 -1
  913. package/dist/cli/runtime/owner-backfill.d.ts +0 -24
  914. package/dist/cli/runtime/owner-backfill.d.ts.map +0 -1
  915. package/dist/cli/runtime/owner-backfill.js +0 -24
  916. package/dist/cli/runtime/owner-backfill.js.map +0 -1
  917. package/dist/cli/runtime/scheduler-init.d.ts +0 -60
  918. package/dist/cli/runtime/scheduler-init.d.ts.map +0 -1
  919. package/dist/cli/runtime/scheduler-init.js +0 -173
  920. package/dist/cli/runtime/scheduler-init.js.map +0 -1
  921. package/dist/cli/runtime/server-start.d.ts +0 -23
  922. package/dist/cli/runtime/server-start.d.ts.map +0 -1
  923. package/dist/cli/runtime/server-start.js +0 -174
  924. package/dist/cli/runtime/server-start.js.map +0 -1
  925. package/dist/cli/runtime/shutdown.d.ts +0 -46
  926. package/dist/cli/runtime/shutdown.d.ts.map +0 -1
  927. package/dist/cli/runtime/shutdown.js +0 -240
  928. package/dist/cli/runtime/shutdown.js.map +0 -1
  929. package/dist/cli/runtime/temporal-init.d.ts +0 -26
  930. package/dist/cli/runtime/temporal-init.d.ts.map +0 -1
  931. package/dist/cli/runtime/temporal-init.js +0 -57
  932. package/dist/cli/runtime/temporal-init.js.map +0 -1
  933. package/dist/cli/runtime/types.d.ts +0 -127
  934. package/dist/cli/runtime/types.d.ts.map +0 -1
  935. package/dist/cli/runtime/types.js +0 -12
  936. package/dist/cli/runtime/types.js.map +0 -1
  937. package/dist/cli/runtime/utilities.d.ts +0 -72
  938. package/dist/cli/runtime/utilities.d.ts.map +0 -1
  939. package/dist/cli/runtime/utilities.js +0 -472
  940. package/dist/cli/runtime/utilities.js.map +0 -1
  941. package/dist/cli/shutdown-utils.d.ts +0 -6
  942. package/dist/cli/shutdown-utils.d.ts.map +0 -1
  943. package/dist/cli/shutdown-utils.js +0 -11
  944. package/dist/cli/shutdown-utils.js.map +0 -1
  945. package/dist/cli/utils/pid-manager.d.ts +0 -56
  946. package/dist/cli/utils/pid-manager.d.ts.map +0 -1
  947. package/dist/cli/utils/pid-manager.js +0 -141
  948. package/dist/cli/utils/pid-manager.js.map +0 -1
  949. package/dist/concurrency/index.d.ts +0 -13
  950. package/dist/concurrency/index.d.ts.map +0 -1
  951. package/dist/concurrency/index.js +0 -22
  952. package/dist/concurrency/index.js.map +0 -1
  953. package/dist/concurrency/lane-manager.d.ts +0 -113
  954. package/dist/concurrency/lane-manager.d.ts.map +0 -1
  955. package/dist/concurrency/lane-manager.js +0 -248
  956. package/dist/concurrency/lane-manager.js.map +0 -1
  957. package/dist/concurrency/session-key.d.ts +0 -41
  958. package/dist/concurrency/session-key.d.ts.map +0 -1
  959. package/dist/concurrency/session-key.js +0 -61
  960. package/dist/concurrency/session-key.js.map +0 -1
  961. package/dist/concurrency/types.d.ts +0 -73
  962. package/dist/concurrency/types.d.ts.map +0 -1
  963. package/dist/concurrency/types.js +0 -16
  964. package/dist/concurrency/types.js.map +0 -1
  965. package/dist/connectors/framework/raw-store.d.ts +0 -63
  966. package/dist/connectors/framework/raw-store.d.ts.map +0 -1
  967. package/dist/connectors/framework/raw-store.js +0 -356
  968. package/dist/connectors/framework/raw-store.js.map +0 -1
  969. package/dist/connectors/kagemusha/query-tools.d.ts +0 -146
  970. package/dist/connectors/kagemusha/query-tools.d.ts.map +0 -1
  971. package/dist/connectors/kagemusha/query-tools.js +0 -467
  972. package/dist/connectors/kagemusha/query-tools.js.map +0 -1
  973. package/dist/connectors/private-connector-policy.d.ts +0 -174
  974. package/dist/connectors/private-connector-policy.d.ts.map +0 -1
  975. package/dist/connectors/private-connector-policy.js +0 -299
  976. package/dist/connectors/private-connector-policy.js.map +0 -1
  977. package/dist/connectors/private-prompt-overlay.d.ts +0 -17
  978. package/dist/connectors/private-prompt-overlay.d.ts.map +0 -1
  979. package/dist/connectors/private-prompt-overlay.js +0 -156
  980. package/dist/connectors/private-prompt-overlay.js.map +0 -1
  981. package/dist/connectors/trello/query-tools.d.ts +0 -243
  982. package/dist/connectors/trello/query-tools.d.ts.map +0 -1
  983. package/dist/connectors/trello/query-tools.js +0 -661
  984. package/dist/connectors/trello/query-tools.js.map +0 -1
  985. package/dist/db/agent-store.d.ts +0 -145
  986. package/dist/db/agent-store.d.ts.map +0 -1
  987. package/dist/db/agent-store.js +0 -279
  988. package/dist/db/agent-store.js.map +0 -1
  989. package/dist/db/migrations/agent-activity-envelope-hash.d.ts +0 -3
  990. package/dist/db/migrations/agent-activity-envelope-hash.d.ts.map +0 -1
  991. package/dist/db/migrations/agent-activity-envelope-hash.js +0 -29
  992. package/dist/db/migrations/agent-activity-envelope-hash.js.map +0 -1
  993. package/dist/db/migrations/agent-activity-gateway-call-id.d.ts +0 -3
  994. package/dist/db/migrations/agent-activity-gateway-call-id.d.ts.map +0 -1
  995. package/dist/db/migrations/agent-activity-gateway-call-id.js +0 -17
  996. package/dist/db/migrations/agent-activity-gateway-call-id.js.map +0 -1
  997. package/dist/db/migrations/agent-activity-tool-name.d.ts +0 -8
  998. package/dist/db/migrations/agent-activity-tool-name.d.ts.map +0 -1
  999. package/dist/db/migrations/agent-activity-tool-name.js +0 -24
  1000. package/dist/db/migrations/agent-activity-tool-name.js.map +0 -1
  1001. package/dist/db/migrations/agent-activity-validation-columns.d.ts +0 -3
  1002. package/dist/db/migrations/agent-activity-validation-columns.d.ts.map +0 -1
  1003. package/dist/db/migrations/agent-activity-validation-columns.js +0 -22
  1004. package/dist/db/migrations/agent-activity-validation-columns.js.map +0 -1
  1005. package/dist/db/migrations/agent-metrics-response-avg.d.ts +0 -3
  1006. package/dist/db/migrations/agent-metrics-response-avg.d.ts.map +0 -1
  1007. package/dist/db/migrations/agent-metrics-response-avg.js +0 -19
  1008. package/dist/db/migrations/agent-metrics-response-avg.js.map +0 -1
  1009. package/dist/db/migrations/agent-store-tables.d.ts +0 -3
  1010. package/dist/db/migrations/agent-store-tables.d.ts.map +0 -1
  1011. package/dist/db/migrations/agent-store-tables.js +0 -64
  1012. package/dist/db/migrations/agent-store-tables.js.map +0 -1
  1013. package/dist/db/migrations/envelope-tables.d.ts +0 -3
  1014. package/dist/db/migrations/envelope-tables.d.ts.map +0 -1
  1015. package/dist/db/migrations/envelope-tables.js +0 -38
  1016. package/dist/db/migrations/envelope-tables.js.map +0 -1
  1017. package/dist/db/migrations/operator-owner-action-candidates.d.ts +0 -19
  1018. package/dist/db/migrations/operator-owner-action-candidates.d.ts.map +0 -1
  1019. package/dist/db/migrations/operator-owner-action-candidates.js +0 -254
  1020. package/dist/db/migrations/operator-owner-action-candidates.js.map +0 -1
  1021. package/dist/db/migrations/operator-procedures.d.ts +0 -4
  1022. package/dist/db/migrations/operator-procedures.d.ts.map +0 -1
  1023. package/dist/db/migrations/operator-procedures.js +0 -63
  1024. package/dist/db/migrations/operator-procedures.js.map +0 -1
  1025. package/dist/db/migrations/operator-task-classification.d.ts +0 -15
  1026. package/dist/db/migrations/operator-task-classification.d.ts.map +0 -1
  1027. package/dist/db/migrations/operator-task-classification.js +0 -25
  1028. package/dist/db/migrations/operator-task-classification.js.map +0 -1
  1029. package/dist/db/migrations/operator-task-external-lifecycle.d.ts +0 -17
  1030. package/dist/db/migrations/operator-task-external-lifecycle.d.ts.map +0 -1
  1031. package/dist/db/migrations/operator-task-external-lifecycle.js +0 -199
  1032. package/dist/db/migrations/operator-task-external-lifecycle.js.map +0 -1
  1033. package/dist/db/migrations/operator-task-review-lifecycle.d.ts +0 -4
  1034. package/dist/db/migrations/operator-task-review-lifecycle.d.ts.map +0 -1
  1035. package/dist/db/migrations/operator-task-review-lifecycle.js +0 -17
  1036. package/dist/db/migrations/operator-task-review-lifecycle.js.map +0 -1
  1037. package/dist/db/migrations/operator-task-temporal.d.ts +0 -8
  1038. package/dist/db/migrations/operator-task-temporal.d.ts.map +0 -1
  1039. package/dist/db/migrations/operator-task-temporal.js +0 -214
  1040. package/dist/db/migrations/operator-task-temporal.js.map +0 -1
  1041. package/dist/db/migrations/owner-action-effects.d.ts +0 -18
  1042. package/dist/db/migrations/owner-action-effects.d.ts.map +0 -1
  1043. package/dist/db/migrations/owner-action-effects.js +0 -111
  1044. package/dist/db/migrations/owner-action-effects.js.map +0 -1
  1045. package/dist/db/migrations/raw-item-revisions.d.ts +0 -4
  1046. package/dist/db/migrations/raw-item-revisions.d.ts.map +0 -1
  1047. package/dist/db/migrations/raw-item-revisions.js +0 -29
  1048. package/dist/db/migrations/raw-item-revisions.js.map +0 -1
  1049. package/dist/db/migrations/token-usage-agent-version.d.ts +0 -3
  1050. package/dist/db/migrations/token-usage-agent-version.d.ts.map +0 -1
  1051. package/dist/db/migrations/token-usage-agent-version.js +0 -16
  1052. package/dist/db/migrations/token-usage-agent-version.js.map +0 -1
  1053. package/dist/db/migrations/validation-session-tables.d.ts +0 -3
  1054. package/dist/db/migrations/validation-session-tables.d.ts.map +0 -1
  1055. package/dist/db/migrations/validation-session-tables.js +0 -59
  1056. package/dist/db/migrations/validation-session-tables.js.map +0 -1
  1057. package/dist/envelope/authority.d.ts +0 -15
  1058. package/dist/envelope/authority.d.ts.map +0 -1
  1059. package/dist/envelope/authority.js +0 -95
  1060. package/dist/envelope/authority.js.map +0 -1
  1061. package/dist/envelope/canonical.d.ts +0 -14
  1062. package/dist/envelope/canonical.d.ts.map +0 -1
  1063. package/dist/envelope/canonical.js +0 -68
  1064. package/dist/envelope/canonical.js.map +0 -1
  1065. package/dist/envelope/enforcer.d.ts +0 -30
  1066. package/dist/envelope/enforcer.d.ts.map +0 -1
  1067. package/dist/envelope/enforcer.js +0 -286
  1068. package/dist/envelope/enforcer.js.map +0 -1
  1069. package/dist/envelope/expiry.d.ts +0 -2
  1070. package/dist/envelope/expiry.d.ts.map +0 -1
  1071. package/dist/envelope/expiry.js +0 -15
  1072. package/dist/envelope/expiry.js.map +0 -1
  1073. package/dist/envelope/index.d.ts +0 -9
  1074. package/dist/envelope/index.d.ts.map +0 -1
  1075. package/dist/envelope/index.js +0 -25
  1076. package/dist/envelope/index.js.map +0 -1
  1077. package/dist/envelope/key-provider.d.ts +0 -7
  1078. package/dist/envelope/key-provider.d.ts.map +0 -1
  1079. package/dist/envelope/key-provider.js +0 -137
  1080. package/dist/envelope/key-provider.js.map +0 -1
  1081. package/dist/envelope/reactive-config.d.ts +0 -24
  1082. package/dist/envelope/reactive-config.d.ts.map +0 -1
  1083. package/dist/envelope/reactive-config.js +0 -198
  1084. package/dist/envelope/reactive-config.js.map +0 -1
  1085. package/dist/envelope/run-guard.d.ts +0 -10
  1086. package/dist/envelope/run-guard.d.ts.map +0 -1
  1087. package/dist/envelope/run-guard.js +0 -19
  1088. package/dist/envelope/run-guard.js.map +0 -1
  1089. package/dist/envelope/signature.d.ts +0 -15
  1090. package/dist/envelope/signature.d.ts.map +0 -1
  1091. package/dist/envelope/signature.js +0 -75
  1092. package/dist/envelope/signature.js.map +0 -1
  1093. package/dist/envelope/store.d.ts +0 -16
  1094. package/dist/envelope/store.d.ts.map +0 -1
  1095. package/dist/envelope/store.js +0 -118
  1096. package/dist/envelope/store.js.map +0 -1
  1097. package/dist/envelope/tool-connector-scope.d.ts +0 -35
  1098. package/dist/envelope/tool-connector-scope.d.ts.map +0 -1
  1099. package/dist/envelope/tool-connector-scope.js +0 -61
  1100. package/dist/envelope/tool-connector-scope.js.map +0 -1
  1101. package/dist/envelope/types.d.ts +0 -60
  1102. package/dist/envelope/types.d.ts.map +0 -1
  1103. package/dist/envelope/types.js +0 -9
  1104. package/dist/envelope/types.js.map +0 -1
  1105. package/dist/evidence/effects.d.ts +0 -125
  1106. package/dist/evidence/effects.d.ts.map +0 -1
  1107. package/dist/evidence/effects.js +0 -409
  1108. package/dist/evidence/effects.js.map +0 -1
  1109. package/dist/evidence/read.d.ts +0 -130
  1110. package/dist/evidence/read.d.ts.map +0 -1
  1111. package/dist/evidence/read.js +0 -167
  1112. package/dist/evidence/read.js.map +0 -1
  1113. package/dist/gateways/attachment-utils.d.ts +0 -28
  1114. package/dist/gateways/attachment-utils.d.ts.map +0 -1
  1115. package/dist/gateways/attachment-utils.js +0 -489
  1116. package/dist/gateways/attachment-utils.js.map +0 -1
  1117. package/dist/gateways/channel-history.d.ts +0 -148
  1118. package/dist/gateways/channel-history.d.ts.map +0 -1
  1119. package/dist/gateways/channel-history.js +0 -385
  1120. package/dist/gateways/channel-history.js.map +0 -1
  1121. package/dist/gateways/context-injector.d.ts +0 -255
  1122. package/dist/gateways/context-injector.d.ts.map +0 -1
  1123. package/dist/gateways/context-injector.js +0 -285
  1124. package/dist/gateways/context-injector.js.map +0 -1
  1125. package/dist/gateways/image-analyzer.d.ts +0 -28
  1126. package/dist/gateways/image-analyzer.d.ts.map +0 -1
  1127. package/dist/gateways/image-analyzer.js +0 -154
  1128. package/dist/gateways/image-analyzer.js.map +0 -1
  1129. package/dist/gateways/index.d.ts +0 -35
  1130. package/dist/gateways/index.d.ts.map +0 -1
  1131. package/dist/gateways/index.js +0 -55
  1132. package/dist/gateways/index.js.map +0 -1
  1133. package/dist/gateways/member-candidate-store.d.ts +0 -26
  1134. package/dist/gateways/member-candidate-store.d.ts.map +0 -1
  1135. package/dist/gateways/member-candidate-store.js +0 -90
  1136. package/dist/gateways/member-candidate-store.js.map +0 -1
  1137. package/dist/gateways/member-effective-scope.d.ts +0 -25
  1138. package/dist/gateways/member-effective-scope.d.ts.map +0 -1
  1139. package/dist/gateways/member-effective-scope.js +0 -323
  1140. package/dist/gateways/member-effective-scope.js.map +0 -1
  1141. package/dist/gateways/message-router.d.ts +0 -239
  1142. package/dist/gateways/message-router.d.ts.map +0 -1
  1143. package/dist/gateways/message-router.js +0 -1714
  1144. package/dist/gateways/message-router.js.map +0 -1
  1145. package/dist/gateways/plugin-loader.d.ts +0 -80
  1146. package/dist/gateways/plugin-loader.d.ts.map +0 -1
  1147. package/dist/gateways/plugin-loader.js +0 -299
  1148. package/dist/gateways/plugin-loader.js.map +0 -1
  1149. package/dist/gateways/principal.d.ts +0 -37
  1150. package/dist/gateways/principal.d.ts.map +0 -1
  1151. package/dist/gateways/principal.js +0 -95
  1152. package/dist/gateways/principal.js.map +0 -1
  1153. package/dist/gateways/report-projection-v1.d.ts +0 -41
  1154. package/dist/gateways/report-projection-v1.d.ts.map +0 -1
  1155. package/dist/gateways/report-projection-v1.js +0 -160
  1156. package/dist/gateways/report-projection-v1.js.map +0 -1
  1157. package/dist/gateways/telegram-media.d.ts +0 -41
  1158. package/dist/gateways/telegram-media.d.ts.map +0 -1
  1159. package/dist/gateways/telegram-media.js +0 -242
  1160. package/dist/gateways/telegram-media.js.map +0 -1
  1161. package/dist/gateways/telegram-report-context-store.d.ts +0 -131
  1162. package/dist/gateways/telegram-report-context-store.d.ts.map +0 -1
  1163. package/dist/gateways/telegram-report-context-store.js +0 -388
  1164. package/dist/gateways/telegram-report-context-store.js.map +0 -1
  1165. package/dist/gateways/tool-status-tracker.d.ts +0 -87
  1166. package/dist/gateways/tool-status-tracker.d.ts.map +0 -1
  1167. package/dist/gateways/tool-status-tracker.js +0 -284
  1168. package/dist/gateways/tool-status-tracker.js.map +0 -1
  1169. package/dist/mcp/code-act-api-client.d.ts +0 -32
  1170. package/dist/mcp/code-act-api-client.d.ts.map +0 -1
  1171. package/dist/mcp/code-act-api-client.js +0 -80
  1172. package/dist/mcp/code-act-api-client.js.map +0 -1
  1173. package/dist/mcp/code-act-mcp-config.d.ts +0 -49
  1174. package/dist/mcp/code-act-mcp-config.d.ts.map +0 -1
  1175. package/dist/mcp/code-act-mcp-config.js +0 -124
  1176. package/dist/mcp/code-act-mcp-config.js.map +0 -1
  1177. package/dist/mcp/code-act-server.d.ts +0 -14
  1178. package/dist/mcp/code-act-server.d.ts.map +0 -1
  1179. package/dist/mcp/code-act-server.js +0 -204
  1180. package/dist/mcp/code-act-server.js.map +0 -1
  1181. package/dist/mcp/code-act-terminal-transport.d.ts +0 -64
  1182. package/dist/mcp/code-act-terminal-transport.d.ts.map +0 -1
  1183. package/dist/mcp/code-act-terminal-transport.js +0 -176
  1184. package/dist/mcp/code-act-terminal-transport.js.map +0 -1
  1185. package/dist/memory/agent-notice-queue.d.ts +0 -24
  1186. package/dist/memory/agent-notice-queue.d.ts.map +0 -1
  1187. package/dist/memory/agent-notice-queue.js +0 -40
  1188. package/dist/memory/agent-notice-queue.js.map +0 -1
  1189. package/dist/memory/audit-task-queue.d.ts +0 -28
  1190. package/dist/memory/audit-task-queue.d.ts.map +0 -1
  1191. package/dist/memory/audit-task-queue.js +0 -29
  1192. package/dist/memory/audit-task-queue.js.map +0 -1
  1193. package/dist/memory/bootstrap-context.d.ts +0 -12
  1194. package/dist/memory/bootstrap-context.d.ts.map +0 -1
  1195. package/dist/memory/bootstrap-context.js +0 -68
  1196. package/dist/memory/bootstrap-context.js.map +0 -1
  1197. package/dist/memory/history-extractor.d.ts +0 -69
  1198. package/dist/memory/history-extractor.d.ts.map +0 -1
  1199. package/dist/memory/history-extractor.js +0 -210
  1200. package/dist/memory/history-extractor.js.map +0 -1
  1201. package/dist/memory/memory-agent-ack.d.ts +0 -4
  1202. package/dist/memory/memory-agent-ack.d.ts.map +0 -1
  1203. package/dist/memory/memory-agent-ack.js +0 -54
  1204. package/dist/memory/memory-agent-ack.js.map +0 -1
  1205. package/dist/memory/memory-agent-dashboard.d.ts +0 -35
  1206. package/dist/memory/memory-agent-dashboard.d.ts.map +0 -1
  1207. package/dist/memory/memory-agent-dashboard.js +0 -116
  1208. package/dist/memory/memory-agent-dashboard.js.map +0 -1
  1209. package/dist/memory/memory-logger.d.ts +0 -47
  1210. package/dist/memory/memory-logger.d.ts.map +0 -1
  1211. package/dist/memory/memory-logger.js +0 -126
  1212. package/dist/memory/memory-logger.js.map +0 -1
  1213. package/dist/memory/provenance-live.d.ts +0 -111
  1214. package/dist/memory/provenance-live.d.ts.map +0 -1
  1215. package/dist/memory/provenance-live.js +0 -381
  1216. package/dist/memory/provenance-live.js.map +0 -1
  1217. package/dist/memory/provenance-resolver.d.ts +0 -184
  1218. package/dist/memory/provenance-resolver.d.ts.map +0 -1
  1219. package/dist/memory/provenance-resolver.js +0 -152
  1220. package/dist/memory/provenance-resolver.js.map +0 -1
  1221. package/dist/memory/raw-backed-memory-ingest.d.ts +0 -26
  1222. package/dist/memory/raw-backed-memory-ingest.d.ts.map +0 -1
  1223. package/dist/memory/raw-backed-memory-ingest.js +0 -214
  1224. package/dist/memory/raw-backed-memory-ingest.js.map +0 -1
  1225. package/dist/memory/recall-bundle-formatter.d.ts +0 -26
  1226. package/dist/memory/recall-bundle-formatter.d.ts.map +0 -1
  1227. package/dist/memory/recall-bundle-formatter.js +0 -53
  1228. package/dist/memory/recall-bundle-formatter.js.map +0 -1
  1229. package/dist/memory/save-candidate-extractor.d.ts +0 -16
  1230. package/dist/memory/save-candidate-extractor.d.ts.map +0 -1
  1231. package/dist/memory/save-candidate-extractor.js +0 -127
  1232. package/dist/memory/save-candidate-extractor.js.map +0 -1
  1233. package/dist/memory/save-candidate-types.d.ts +0 -16
  1234. package/dist/memory/save-candidate-types.d.ts.map +0 -1
  1235. package/dist/memory/save-candidate-types.js +0 -3
  1236. package/dist/memory/save-candidate-types.js.map +0 -1
  1237. package/dist/memory/scope-context.d.ts +0 -12
  1238. package/dist/memory/scope-context.d.ts.map +0 -1
  1239. package/dist/memory/scope-context.js +0 -18
  1240. package/dist/memory/scope-context.js.map +0 -1
  1241. package/dist/memory/secret-filter.d.ts +0 -23
  1242. package/dist/memory/secret-filter.d.ts.map +0 -1
  1243. package/dist/memory/secret-filter.js +0 -90
  1244. package/dist/memory/secret-filter.js.map +0 -1
  1245. package/dist/multi-agent/agent-event-bus.d.ts +0 -50
  1246. package/dist/multi-agent/agent-event-bus.d.ts.map +0 -1
  1247. package/dist/multi-agent/agent-event-bus.js +0 -101
  1248. package/dist/multi-agent/agent-event-bus.js.map +0 -1
  1249. package/dist/multi-agent/agent-process-manager.d.ts +0 -205
  1250. package/dist/multi-agent/agent-process-manager.d.ts.map +0 -1
  1251. package/dist/multi-agent/agent-process-manager.js +0 -1191
  1252. package/dist/multi-agent/agent-process-manager.js.map +0 -1
  1253. package/dist/multi-agent/bmad-templates.d.ts +0 -49
  1254. package/dist/multi-agent/bmad-templates.d.ts.map +0 -1
  1255. package/dist/multi-agent/bmad-templates.js +0 -121
  1256. package/dist/multi-agent/bmad-templates.js.map +0 -1
  1257. package/dist/multi-agent/runtime-process.d.ts +0 -74
  1258. package/dist/multi-agent/runtime-process.d.ts.map +0 -1
  1259. package/dist/multi-agent/runtime-process.js +0 -160
  1260. package/dist/multi-agent/runtime-process.js.map +0 -1
  1261. package/dist/multi-agent/tool-permission-manager.d.ts +0 -70
  1262. package/dist/multi-agent/tool-permission-manager.d.ts.map +0 -1
  1263. package/dist/multi-agent/tool-permission-manager.js +0 -195
  1264. package/dist/multi-agent/tool-permission-manager.js.map +0 -1
  1265. package/dist/multi-agent/types.d.ts +0 -438
  1266. package/dist/multi-agent/types.d.ts.map +0 -1
  1267. package/dist/multi-agent/types.js +0 -27
  1268. package/dist/multi-agent/types.js.map +0 -1
  1269. package/dist/multi-agent/wiki-agent-persona.d.ts +0 -16
  1270. package/dist/multi-agent/wiki-agent-persona.d.ts.map +0 -1
  1271. package/dist/multi-agent/wiki-agent-persona.js +0 -23
  1272. package/dist/multi-agent/wiki-agent-persona.js.map +0 -1
  1273. package/dist/multi-agent/workflow-types.d.ts +0 -186
  1274. package/dist/multi-agent/workflow-types.d.ts.map +0 -1
  1275. package/dist/multi-agent/workflow-types.js +0 -9
  1276. package/dist/multi-agent/workflow-types.js.map +0 -1
  1277. package/dist/observability/code-audit.d.ts +0 -87
  1278. package/dist/observability/code-audit.d.ts.map +0 -1
  1279. package/dist/observability/code-audit.js +0 -414
  1280. package/dist/observability/code-audit.js.map +0 -1
  1281. package/dist/observability/health-check.d.ts +0 -102
  1282. package/dist/observability/health-check.d.ts.map +0 -1
  1283. package/dist/observability/health-check.js +0 -422
  1284. package/dist/observability/health-check.js.map +0 -1
  1285. package/dist/observability/health-score.d.ts +0 -29
  1286. package/dist/observability/health-score.d.ts.map +0 -1
  1287. package/dist/observability/health-score.js +0 -83
  1288. package/dist/observability/health-score.js.map +0 -1
  1289. package/dist/observability/metrics-cleanup.d.ts +0 -24
  1290. package/dist/observability/metrics-cleanup.d.ts.map +0 -1
  1291. package/dist/observability/metrics-cleanup.js +0 -51
  1292. package/dist/observability/metrics-cleanup.js.map +0 -1
  1293. package/dist/observability/metrics-store.d.ts +0 -52
  1294. package/dist/observability/metrics-store.d.ts.map +0 -1
  1295. package/dist/observability/metrics-store.js +0 -186
  1296. package/dist/observability/metrics-store.js.map +0 -1
  1297. package/dist/observability/operational-issues.d.ts +0 -55
  1298. package/dist/observability/operational-issues.d.ts.map +0 -1
  1299. package/dist/observability/operational-issues.js +0 -170
  1300. package/dist/observability/operational-issues.js.map +0 -1
  1301. package/dist/onboarding/agent-contract.d.ts +0 -42
  1302. package/dist/onboarding/agent-contract.d.ts.map +0 -1
  1303. package/dist/onboarding/agent-contract.js +0 -129
  1304. package/dist/onboarding/agent-contract.js.map +0 -1
  1305. package/dist/onboarding/assess-live.d.ts +0 -22
  1306. package/dist/onboarding/assess-live.d.ts.map +0 -1
  1307. package/dist/onboarding/assess-live.js +0 -200
  1308. package/dist/onboarding/assess-live.js.map +0 -1
  1309. package/dist/onboarding/bootstrap-template.d.ts +0 -5
  1310. package/dist/onboarding/bootstrap-template.d.ts.map +0 -1
  1311. package/dist/onboarding/bootstrap-template.js +0 -34
  1312. package/dist/onboarding/bootstrap-template.js.map +0 -1
  1313. package/dist/operator/action-verifier.d.ts +0 -75
  1314. package/dist/operator/action-verifier.d.ts.map +0 -1
  1315. package/dist/operator/action-verifier.js +0 -149
  1316. package/dist/operator/action-verifier.js.map +0 -1
  1317. package/dist/operator/board-delta-gate.d.ts +0 -131
  1318. package/dist/operator/board-delta-gate.d.ts.map +0 -1
  1319. package/dist/operator/board-delta-gate.js +0 -181
  1320. package/dist/operator/board-delta-gate.js.map +0 -1
  1321. package/dist/operator/board-pipeline-render.d.ts +0 -16
  1322. package/dist/operator/board-pipeline-render.d.ts.map +0 -1
  1323. package/dist/operator/board-pipeline-render.js +0 -69
  1324. package/dist/operator/board-pipeline-render.js.map +0 -1
  1325. package/dist/operator/board-reconcile.d.ts +0 -61
  1326. package/dist/operator/board-reconcile.d.ts.map +0 -1
  1327. package/dist/operator/board-reconcile.js +0 -157
  1328. package/dist/operator/board-reconcile.js.map +0 -1
  1329. package/dist/operator/board-refresh-gate.d.ts +0 -39
  1330. package/dist/operator/board-refresh-gate.d.ts.map +0 -1
  1331. package/dist/operator/board-refresh-gate.js +0 -83
  1332. package/dist/operator/board-refresh-gate.js.map +0 -1
  1333. package/dist/operator/changes-projection.d.ts +0 -72
  1334. package/dist/operator/changes-projection.d.ts.map +0 -1
  1335. package/dist/operator/changes-projection.js +0 -110
  1336. package/dist/operator/changes-projection.js.map +0 -1
  1337. package/dist/operator/connector-delta-repo.d.ts +0 -33
  1338. package/dist/operator/connector-delta-repo.d.ts.map +0 -1
  1339. package/dist/operator/connector-delta-repo.js +0 -0
  1340. package/dist/operator/connector-delta-repo.js.map +0 -1
  1341. package/dist/operator/console-brief.d.ts +0 -40
  1342. package/dist/operator/console-brief.d.ts.map +0 -1
  1343. package/dist/operator/console-brief.js +0 -246
  1344. package/dist/operator/console-brief.js.map +0 -1
  1345. package/dist/operator/experience-evidence.d.ts +0 -18
  1346. package/dist/operator/experience-evidence.d.ts.map +0 -1
  1347. package/dist/operator/experience-evidence.js +0 -82
  1348. package/dist/operator/experience-evidence.js.map +0 -1
  1349. package/dist/operator/experience-hints.d.ts +0 -44
  1350. package/dist/operator/experience-hints.d.ts.map +0 -1
  1351. package/dist/operator/experience-hints.js +0 -98
  1352. package/dist/operator/experience-hints.js.map +0 -1
  1353. package/dist/operator/external-correlation.d.ts +0 -94
  1354. package/dist/operator/external-correlation.d.ts.map +0 -1
  1355. package/dist/operator/external-correlation.js +0 -177
  1356. package/dist/operator/external-correlation.js.map +0 -1
  1357. package/dist/operator/external-lifecycle-candidates.d.ts +0 -70
  1358. package/dist/operator/external-lifecycle-candidates.d.ts.map +0 -1
  1359. package/dist/operator/external-lifecycle-candidates.js +0 -579
  1360. package/dist/operator/external-lifecycle-candidates.js.map +0 -1
  1361. package/dist/operator/external-lifecycle-discovery.d.ts +0 -61
  1362. package/dist/operator/external-lifecycle-discovery.d.ts.map +0 -1
  1363. package/dist/operator/external-lifecycle-discovery.js +0 -103
  1364. package/dist/operator/external-lifecycle-discovery.js.map +0 -1
  1365. package/dist/operator/external-lifecycle.d.ts +0 -105
  1366. package/dist/operator/external-lifecycle.d.ts.map +0 -1
  1367. package/dist/operator/external-lifecycle.js +0 -27
  1368. package/dist/operator/external-lifecycle.js.map +0 -1
  1369. package/dist/operator/file-coordination.d.ts +0 -7
  1370. package/dist/operator/file-coordination.d.ts.map +0 -1
  1371. package/dist/operator/file-coordination.js +0 -84
  1372. package/dist/operator/file-coordination.js.map +0 -1
  1373. package/dist/operator/file-export.d.ts +0 -22
  1374. package/dist/operator/file-export.d.ts.map +0 -1
  1375. package/dist/operator/file-export.js +0 -115
  1376. package/dist/operator/file-export.js.map +0 -1
  1377. package/dist/operator/leg-cadence.d.ts +0 -72
  1378. package/dist/operator/leg-cadence.d.ts.map +0 -1
  1379. package/dist/operator/leg-cadence.js +0 -122
  1380. package/dist/operator/leg-cadence.js.map +0 -1
  1381. package/dist/operator/mama-memory-port.d.ts +0 -13
  1382. package/dist/operator/mama-memory-port.d.ts.map +0 -1
  1383. package/dist/operator/mama-memory-port.js +0 -33
  1384. package/dist/operator/mama-memory-port.js.map +0 -1
  1385. package/dist/operator/operator-interfaces.d.ts +0 -136
  1386. package/dist/operator/operator-interfaces.d.ts.map +0 -1
  1387. package/dist/operator/operator-interfaces.js +0 -15
  1388. package/dist/operator/operator-interfaces.js.map +0 -1
  1389. package/dist/operator/operator-trigger-loop.d.ts +0 -203
  1390. package/dist/operator/operator-trigger-loop.d.ts.map +0 -1
  1391. package/dist/operator/operator-trigger-loop.js +0 -827
  1392. package/dist/operator/operator-trigger-loop.js.map +0 -1
  1393. package/dist/operator/owner-action-effects.d.ts +0 -112
  1394. package/dist/operator/owner-action-effects.d.ts.map +0 -1
  1395. package/dist/operator/owner-action-effects.js +0 -375
  1396. package/dist/operator/owner-action-effects.js.map +0 -1
  1397. package/dist/operator/owner-event-effects.d.ts +0 -65
  1398. package/dist/operator/owner-event-effects.d.ts.map +0 -1
  1399. package/dist/operator/owner-event-effects.js +0 -249
  1400. package/dist/operator/owner-event-effects.js.map +0 -1
  1401. package/dist/operator/owner-event-inbox.d.ts +0 -124
  1402. package/dist/operator/owner-event-inbox.d.ts.map +0 -1
  1403. package/dist/operator/owner-event-inbox.js +0 -440
  1404. package/dist/operator/owner-event-inbox.js.map +0 -1
  1405. package/dist/operator/owner-event-loop.d.ts +0 -99
  1406. package/dist/operator/owner-event-loop.d.ts.map +0 -1
  1407. package/dist/operator/owner-event-loop.js +0 -253
  1408. package/dist/operator/owner-event-loop.js.map +0 -1
  1409. package/dist/operator/owner-event-outcome.d.ts +0 -36
  1410. package/dist/operator/owner-event-outcome.d.ts.map +0 -1
  1411. package/dist/operator/owner-event-outcome.js +0 -174
  1412. package/dist/operator/owner-event-outcome.js.map +0 -1
  1413. package/dist/operator/owner-event-policy.d.ts +0 -40
  1414. package/dist/operator/owner-event-policy.d.ts.map +0 -1
  1415. package/dist/operator/owner-event-policy.js +0 -75
  1416. package/dist/operator/owner-event-policy.js.map +0 -1
  1417. package/dist/operator/owner-event-prompt.d.ts +0 -21
  1418. package/dist/operator/owner-event-prompt.d.ts.map +0 -1
  1419. package/dist/operator/owner-event-prompt.js +0 -69
  1420. package/dist/operator/owner-event-prompt.js.map +0 -1
  1421. package/dist/operator/owner-runtime-journal.d.ts +0 -21
  1422. package/dist/operator/owner-runtime-journal.d.ts.map +0 -1
  1423. package/dist/operator/owner-runtime-journal.js +0 -135
  1424. package/dist/operator/owner-runtime-journal.js.map +0 -1
  1425. package/dist/operator/owner-runtime.d.ts +0 -48
  1426. package/dist/operator/owner-runtime.d.ts.map +0 -1
  1427. package/dist/operator/owner-runtime.js +0 -99
  1428. package/dist/operator/owner-runtime.js.map +0 -1
  1429. package/dist/operator/pending-report-store.d.ts +0 -99
  1430. package/dist/operator/pending-report-store.d.ts.map +0 -1
  1431. package/dist/operator/pending-report-store.js +0 -554
  1432. package/dist/operator/pending-report-store.js.map +0 -1
  1433. package/dist/operator/procedure-activation.d.ts +0 -7
  1434. package/dist/operator/procedure-activation.d.ts.map +0 -1
  1435. package/dist/operator/procedure-activation.js +0 -132
  1436. package/dist/operator/procedure-activation.js.map +0 -1
  1437. package/dist/operator/procedure-projection.d.ts +0 -25
  1438. package/dist/operator/procedure-projection.d.ts.map +0 -1
  1439. package/dist/operator/procedure-projection.js +0 -80
  1440. package/dist/operator/procedure-projection.js.map +0 -1
  1441. package/dist/operator/procedure-runtime.d.ts +0 -45
  1442. package/dist/operator/procedure-runtime.d.ts.map +0 -1
  1443. package/dist/operator/procedure-runtime.js +0 -496
  1444. package/dist/operator/procedure-runtime.js.map +0 -1
  1445. package/dist/operator/procedure-store.d.ts +0 -97
  1446. package/dist/operator/procedure-store.d.ts.map +0 -1
  1447. package/dist/operator/procedure-store.js +0 -368
  1448. package/dist/operator/procedure-store.js.map +0 -1
  1449. package/dist/operator/provenance-lookup.d.ts +0 -18
  1450. package/dist/operator/provenance-lookup.d.ts.map +0 -1
  1451. package/dist/operator/provenance-lookup.js +0 -54
  1452. package/dist/operator/provenance-lookup.js.map +0 -1
  1453. package/dist/operator/repair-request.d.ts +0 -29
  1454. package/dist/operator/repair-request.d.ts.map +0 -1
  1455. package/dist/operator/repair-request.js +0 -115
  1456. package/dist/operator/repair-request.js.map +0 -1
  1457. package/dist/operator/report-carry-delivery.d.ts +0 -35
  1458. package/dist/operator/report-carry-delivery.d.ts.map +0 -1
  1459. package/dist/operator/report-carry-delivery.js +0 -55
  1460. package/dist/operator/report-carry-delivery.js.map +0 -1
  1461. package/dist/operator/report-carry.d.ts +0 -66
  1462. package/dist/operator/report-carry.d.ts.map +0 -1
  1463. package/dist/operator/report-carry.js +0 -352
  1464. package/dist/operator/report-carry.js.map +0 -1
  1465. package/dist/operator/report-delivery-coordinator.d.ts +0 -84
  1466. package/dist/operator/report-delivery-coordinator.d.ts.map +0 -1
  1467. package/dist/operator/report-delivery-coordinator.js +0 -146
  1468. package/dist/operator/report-delivery-coordinator.js.map +0 -1
  1469. package/dist/operator/report-run.d.ts +0 -52
  1470. package/dist/operator/report-run.d.ts.map +0 -1
  1471. package/dist/operator/report-run.js +0 -32
  1472. package/dist/operator/report-run.js.map +0 -1
  1473. package/dist/operator/report-scheduler.d.ts +0 -66
  1474. package/dist/operator/report-scheduler.d.ts.map +0 -1
  1475. package/dist/operator/report-scheduler.js +0 -135
  1476. package/dist/operator/report-scheduler.js.map +0 -1
  1477. package/dist/operator/runtime-config.d.ts +0 -10
  1478. package/dist/operator/runtime-config.d.ts.map +0 -1
  1479. package/dist/operator/runtime-config.js +0 -21
  1480. package/dist/operator/runtime-config.js.map +0 -1
  1481. package/dist/operator/situation-report.d.ts +0 -197
  1482. package/dist/operator/situation-report.d.ts.map +0 -1
  1483. package/dist/operator/situation-report.js +0 -462
  1484. package/dist/operator/situation-report.js.map +0 -1
  1485. package/dist/operator/subagent-stimulus.d.ts +0 -34
  1486. package/dist/operator/subagent-stimulus.d.ts.map +0 -1
  1487. package/dist/operator/subagent-stimulus.js +0 -145
  1488. package/dist/operator/subagent-stimulus.js.map +0 -1
  1489. package/dist/operator/task-ledger.d.ts +0 -879
  1490. package/dist/operator/task-ledger.d.ts.map +0 -1
  1491. package/dist/operator/task-ledger.js +0 -3601
  1492. package/dist/operator/task-ledger.js.map +0 -1
  1493. package/dist/operator/task-list-views.d.ts +0 -91
  1494. package/dist/operator/task-list-views.d.ts.map +0 -1
  1495. package/dist/operator/task-list-views.js +0 -532
  1496. package/dist/operator/task-list-views.js.map +0 -1
  1497. package/dist/operator/task-temporal.d.ts +0 -24
  1498. package/dist/operator/task-temporal.d.ts.map +0 -1
  1499. package/dist/operator/task-temporal.js +0 -123
  1500. package/dist/operator/task-temporal.js.map +0 -1
  1501. package/dist/operator/temporal-effect.d.ts +0 -65
  1502. package/dist/operator/temporal-effect.d.ts.map +0 -1
  1503. package/dist/operator/temporal-effect.js +0 -71
  1504. package/dist/operator/temporal-effect.js.map +0 -1
  1505. package/dist/operator/temporal-reconcile.d.ts +0 -49
  1506. package/dist/operator/temporal-reconcile.d.ts.map +0 -1
  1507. package/dist/operator/temporal-reconcile.js +0 -231
  1508. package/dist/operator/temporal-reconcile.js.map +0 -1
  1509. package/dist/operator/temporal-runtime.d.ts +0 -51
  1510. package/dist/operator/temporal-runtime.d.ts.map +0 -1
  1511. package/dist/operator/temporal-runtime.js +0 -104
  1512. package/dist/operator/temporal-runtime.js.map +0 -1
  1513. package/dist/operator/temporal-worker.d.ts +0 -18
  1514. package/dist/operator/temporal-worker.d.ts.map +0 -1
  1515. package/dist/operator/temporal-worker.js +0 -82
  1516. package/dist/operator/temporal-worker.js.map +0 -1
  1517. package/dist/operator/thread-brief-memory.d.ts +0 -29
  1518. package/dist/operator/thread-brief-memory.d.ts.map +0 -1
  1519. package/dist/operator/thread-brief-memory.js +0 -61
  1520. package/dist/operator/thread-brief-memory.js.map +0 -1
  1521. package/dist/operator/trigger-author.d.ts +0 -63
  1522. package/dist/operator/trigger-author.d.ts.map +0 -1
  1523. package/dist/operator/trigger-author.js +0 -384
  1524. package/dist/operator/trigger-author.js.map +0 -1
  1525. package/dist/operator/trigger-evolve.d.ts +0 -31
  1526. package/dist/operator/trigger-evolve.d.ts.map +0 -1
  1527. package/dist/operator/trigger-evolve.js +0 -51
  1528. package/dist/operator/trigger-evolve.js.map +0 -1
  1529. package/dist/operator/trigger-fire.d.ts +0 -29
  1530. package/dist/operator/trigger-fire.d.ts.map +0 -1
  1531. package/dist/operator/trigger-fire.js +0 -41
  1532. package/dist/operator/trigger-fire.js.map +0 -1
  1533. package/dist/operator/trigger-matcher.d.ts +0 -19
  1534. package/dist/operator/trigger-matcher.d.ts.map +0 -1
  1535. package/dist/operator/trigger-matcher.js +0 -65
  1536. package/dist/operator/trigger-matcher.js.map +0 -1
  1537. package/dist/operator/trigger-registry.d.ts +0 -58
  1538. package/dist/operator/trigger-registry.d.ts.map +0 -1
  1539. package/dist/operator/trigger-registry.js +0 -349
  1540. package/dist/operator/trigger-registry.js.map +0 -1
  1541. package/dist/operator/trigger-review.d.ts +0 -23
  1542. package/dist/operator/trigger-review.d.ts.map +0 -1
  1543. package/dist/operator/trigger-review.js +0 -193
  1544. package/dist/operator/trigger-review.js.map +0 -1
  1545. package/dist/operator/trigger-types.d.ts +0 -95
  1546. package/dist/operator/trigger-types.d.ts.map +0 -1
  1547. package/dist/operator/trigger-types.js +0 -14
  1548. package/dist/operator/trigger-types.js.map +0 -1
  1549. package/dist/operator/wiki-continuity.d.ts +0 -153
  1550. package/dist/operator/wiki-continuity.d.ts.map +0 -1
  1551. package/dist/operator/wiki-continuity.js +0 -221
  1552. package/dist/operator/wiki-continuity.js.map +0 -1
  1553. package/dist/operator/worker-run.d.ts +0 -109
  1554. package/dist/operator/worker-run.d.ts.map +0 -1
  1555. package/dist/operator/worker-run.js +0 -131
  1556. package/dist/operator/worker-run.js.map +0 -1
  1557. package/dist/operator/workorder-consumer.d.ts +0 -294
  1558. package/dist/operator/workorder-consumer.d.ts.map +0 -1
  1559. package/dist/operator/workorder-consumer.js +0 -1108
  1560. package/dist/operator/workorder-consumer.js.map +0 -1
  1561. package/dist/operator/workorder-hooks.d.ts +0 -162
  1562. package/dist/operator/workorder-hooks.d.ts.map +0 -1
  1563. package/dist/operator/workorder-hooks.js +0 -342
  1564. package/dist/operator/workorder-hooks.js.map +0 -1
  1565. package/dist/operator/workorder-publishers.d.ts +0 -117
  1566. package/dist/operator/workorder-publishers.d.ts.map +0 -1
  1567. package/dist/operator/workorder-publishers.js +0 -544
  1568. package/dist/operator/workorder-publishers.js.map +0 -1
  1569. package/dist/runners/cli-runner.d.ts +0 -59
  1570. package/dist/runners/cli-runner.d.ts.map +0 -1
  1571. package/dist/runners/cli-runner.js +0 -191
  1572. package/dist/runners/cli-runner.js.map +0 -1
  1573. package/dist/runners/index.d.ts +0 -11
  1574. package/dist/runners/index.d.ts.map +0 -1
  1575. package/dist/runners/index.js +0 -15
  1576. package/dist/runners/index.js.map +0 -1
  1577. package/dist/runners/types.d.ts +0 -81
  1578. package/dist/runners/types.d.ts.map +0 -1
  1579. package/dist/runners/types.js +0 -31
  1580. package/dist/runners/types.js.map +0 -1
  1581. package/dist/scheduler/cron-result-router.d.ts +0 -24
  1582. package/dist/scheduler/cron-result-router.d.ts.map +0 -1
  1583. package/dist/scheduler/cron-result-router.js +0 -63
  1584. package/dist/scheduler/cron-result-router.js.map +0 -1
  1585. package/dist/scheduler/cron-scheduler.d.ts +0 -115
  1586. package/dist/scheduler/cron-scheduler.d.ts.map +0 -1
  1587. package/dist/scheduler/cron-scheduler.js +0 -336
  1588. package/dist/scheduler/cron-scheduler.js.map +0 -1
  1589. package/dist/scheduler/cron-worker.d.ts +0 -39
  1590. package/dist/scheduler/cron-worker.d.ts.map +0 -1
  1591. package/dist/scheduler/cron-worker.js +0 -94
  1592. package/dist/scheduler/cron-worker.js.map +0 -1
  1593. package/dist/scheduler/heartbeat.d.ts +0 -64
  1594. package/dist/scheduler/heartbeat.d.ts.map +0 -1
  1595. package/dist/scheduler/heartbeat.js +0 -197
  1596. package/dist/scheduler/heartbeat.js.map +0 -1
  1597. package/dist/scheduler/index.d.ts +0 -26
  1598. package/dist/scheduler/index.d.ts.map +0 -1
  1599. package/dist/scheduler/index.js +0 -37
  1600. package/dist/scheduler/index.js.map +0 -1
  1601. package/dist/scheduler/job-lock.d.ts +0 -85
  1602. package/dist/scheduler/job-lock.d.ts.map +0 -1
  1603. package/dist/scheduler/job-lock.js +0 -137
  1604. package/dist/scheduler/job-lock.js.map +0 -1
  1605. package/dist/scheduler/recovery.d.ts +0 -78
  1606. package/dist/scheduler/recovery.d.ts.map +0 -1
  1607. package/dist/scheduler/recovery.js +0 -124
  1608. package/dist/scheduler/recovery.js.map +0 -1
  1609. package/dist/scheduler/schedule-store.d.ts +0 -112
  1610. package/dist/scheduler/schedule-store.d.ts.map +0 -1
  1611. package/dist/scheduler/schedule-store.js +0 -259
  1612. package/dist/scheduler/schedule-store.js.map +0 -1
  1613. package/dist/scheduler/token-keep-alive.d.ts +0 -49
  1614. package/dist/scheduler/token-keep-alive.d.ts.map +0 -1
  1615. package/dist/scheduler/token-keep-alive.js +0 -102
  1616. package/dist/scheduler/token-keep-alive.js.map +0 -1
  1617. package/dist/scheduler/types.d.ts +0 -98
  1618. package/dist/scheduler/types.d.ts.map +0 -1
  1619. package/dist/scheduler/types.js +0 -21
  1620. package/dist/scheduler/types.js.map +0 -1
  1621. package/dist/security/security-monitor.d.ts +0 -56
  1622. package/dist/security/security-monitor.d.ts.map +0 -1
  1623. package/dist/security/security-monitor.js +0 -779
  1624. package/dist/security/security-monitor.js.map +0 -1
  1625. package/dist/security/trusted-proxy.d.ts +0 -9
  1626. package/dist/security/trusted-proxy.d.ts.map +0 -1
  1627. package/dist/security/trusted-proxy.js +0 -36
  1628. package/dist/security/trusted-proxy.js.map +0 -1
  1629. package/dist/skills/index.d.ts +0 -10
  1630. package/dist/skills/index.d.ts.map +0 -1
  1631. package/dist/skills/index.js +0 -26
  1632. package/dist/skills/index.js.map +0 -1
  1633. package/dist/skills/skill-executor.d.ts +0 -48
  1634. package/dist/skills/skill-executor.d.ts.map +0 -1
  1635. package/dist/skills/skill-executor.js +0 -483
  1636. package/dist/skills/skill-executor.js.map +0 -1
  1637. package/dist/skills/skill-loader.d.ts +0 -40
  1638. package/dist/skills/skill-loader.d.ts.map +0 -1
  1639. package/dist/skills/skill-loader.js +0 -233
  1640. package/dist/skills/skill-loader.js.map +0 -1
  1641. package/dist/skills/skill-matcher.d.ts +0 -33
  1642. package/dist/skills/skill-matcher.d.ts.map +0 -1
  1643. package/dist/skills/skill-matcher.js +0 -190
  1644. package/dist/skills/skill-matcher.js.map +0 -1
  1645. package/dist/skills/skill-registry.d.ts +0 -117
  1646. package/dist/skills/skill-registry.d.ts.map +0 -1
  1647. package/dist/skills/skill-registry.js +0 -627
  1648. package/dist/skills/skill-registry.js.map +0 -1
  1649. package/dist/skills/types.d.ts +0 -131
  1650. package/dist/skills/types.d.ts.map +0 -1
  1651. package/dist/skills/types.js +0 -12
  1652. package/dist/skills/types.js.map +0 -1
  1653. package/dist/utils/log-sanitizer.d.ts +0 -79
  1654. package/dist/utils/log-sanitizer.d.ts.map +0 -1
  1655. package/dist/utils/log-sanitizer.js +0 -215
  1656. package/dist/utils/log-sanitizer.js.map +0 -1
  1657. package/dist/validation/session-service.d.ts +0 -72
  1658. package/dist/validation/session-service.d.ts.map +0 -1
  1659. package/dist/validation/session-service.js +0 -298
  1660. package/dist/validation/session-service.js.map +0 -1
  1661. package/dist/validation/store.d.ts +0 -25
  1662. package/dist/validation/store.d.ts.map +0 -1
  1663. package/dist/validation/store.js +0 -200
  1664. package/dist/validation/store.js.map +0 -1
  1665. package/dist/validation/types.d.ts +0 -119
  1666. package/dist/validation/types.d.ts.map +0 -1
  1667. package/dist/validation/types.js +0 -57
  1668. package/dist/validation/types.js.map +0 -1
  1669. package/dist/wiki/wiki-turn-contract.d.ts +0 -19
  1670. package/dist/wiki/wiki-turn-contract.d.ts.map +0 -1
  1671. package/dist/wiki/wiki-turn-contract.js +0 -60
  1672. package/dist/wiki/wiki-turn-contract.js.map +0 -1
  1673. package/public/viewer/js/utils/ui-commands.js +0 -88
  1674. package/public/viewer/src/utils/ui-commands.ts +0 -114
  1675. package/scripts/attachment/extract-office-text.js +0 -179
  1676. package/scripts/attachment/extract-pdf-text.swift +0 -36
  1677. package/scripts/backfill-channel-keys.ts +0 -509
  1678. package/scripts/crack-failure-digests.ts +0 -55
  1679. package/scripts/generate-gateway-tools.ts +0 -131
  1680. package/scripts/image/fb-overlay.py +0 -128
  1681. package/scripts/image/ocr-image.py +0 -38
  1682. package/scripts/postinstall.js +0 -161
  1683. package/scripts/setup-ocr.js +0 -120
  1684. package/templates/AGENTS.claude.md +0 -23
  1685. package/templates/AGENTS.codex.md +0 -11
  1686. package/templates/bmad/LICENSE +0 -28
  1687. package/templates/bmad/architecture.md +0 -343
  1688. package/templates/bmad/bmm-workflow-status.template.yaml +0 -66
  1689. package/templates/bmad/prd.md +0 -198
  1690. package/templates/bmad/product-brief.md +0 -149
  1691. package/templates/bmad/sprint-status.template.yaml +0 -35
  1692. package/templates/bmad/tech-spec.md +0 -151
  1693. package/templates/entity-audit-fixtures/cross-language-aliases.json +0 -28
  1694. package/templates/entity-audit-fixtures/gold-canonical-identities.json +0 -46
  1695. package/templates/skills/danggeun-monitor.md +0 -88
  1696. package/templates/skills/document-analyze.md +0 -63
  1697. package/templates/skills/frontend-design.md +0 -71
  1698. package/templates/skills/image-translate.md +0 -62
  1699. package/templates/skills/multi-agent-collab.md +0 -145
  1700. package/templates/skills/scheduling.md +0 -107
  1701. package/templates/workspace/skill-forge/DESIGN.md +0 -115
  1702. package/templates/workspace/skill-forge/agents/architect.ts +0 -295
  1703. package/templates/workspace/skill-forge/agents/developer.ts +0 -364
  1704. package/templates/workspace/skill-forge/agents/qa.ts +0 -313
  1705. package/templates/workspace/skill-forge/claude-api.ts +0 -353
  1706. package/templates/workspace/skill-forge/discord-ui.ts +0 -580
  1707. package/templates/workspace/skill-forge/error-handler.ts +0 -354
  1708. package/templates/workspace/skill-forge/mama-integration.ts +0 -357
  1709. package/templates/workspace/skill-forge/orchestrator.ts +0 -495
  1710. package/templates/workspace/skill-forge/output/generated-skills/skills/hello-world/README.md +0 -24
  1711. package/templates/workspace/skill-forge/output/generated-skills/skills/hello-world/index.ts +0 -79
  1712. package/templates/workspace/skill-forge/output/generated-skills/skills/hello-world/types.ts +0 -17
  1713. package/templates/workspace/skill-forge/package.json +0 -21
  1714. package/templates/workspace/skill-forge/state/session.json +0 -132
  1715. package/templates/workspace/skill-forge/test-e2e.ts +0 -139
  1716. package/templates/workspace/skill-forge/tsconfig.json +0 -20
  1717. package/templates/workspace/skill-forge/types.ts +0 -159
@@ -1,1056 +1,543 @@
1
1
  "use strict";
2
- /**
3
- * Telegram Gateway for MAMA Standalone
4
- *
5
- * Production-hardened Telegram bot integration using grammY:
6
- * - Telegram message_id dedup without dropping repeated short replies
7
- * - Photo/document/caption ingestion through MAMA content blocks
8
- * - Group chat filtering (mention/command/reply-to-bot only)
9
- * - Sticker receive/send with emotion mapping
10
- * - Single-message streaming presenter (placeholder → final answer)
11
- * - Typing indicator, error handling
12
- */
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || (function () {
30
- var ownKeys = function(o) {
31
- ownKeys = Object.getOwnPropertyNames || function (o) {
32
- var ar = [];
33
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
- return ar;
35
- };
36
- return ownKeys(o);
37
- };
38
- return function (mod) {
39
- if (mod && mod.__esModule) return mod;
40
- var result = {};
41
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
- __setModuleDefault(result, mod);
43
- return result;
44
- };
45
- })();
46
2
  Object.defineProperty(exports, "__esModule", { value: true });
47
3
  exports.TelegramGateway = void 0;
48
- const promises_1 = require("node:fs/promises");
4
+ const node_async_hooks_1 = require("node:async_hooks");
49
5
  const node_crypto_1 = require("node:crypto");
50
- const node_os_1 = require("node:os");
6
+ const node_fs_1 = require("node:fs");
51
7
  const node_path_1 = require("node:path");
52
- const node_async_hooks_1 = require("node:async_hooks");
53
8
  const grammy_1 = require("grammy");
54
9
  const base_gateway_js_1 = require("./base-gateway.js");
55
- const memory_logger_js_1 = require("../memory/memory-logger.js");
56
- const untrusted_content_js_1 = require("../utils/untrusted-content.js");
57
- const attachment_utils_js_1 = require("./attachment-utils.js");
58
10
  const telegram_text_entities_js_1 = require("./telegram-text-entities.js");
59
- const telegram_media_js_1 = require("./telegram-media.js");
60
- const telegram_response_presenter_js_1 = require("./telegram-response-presenter.js");
61
11
  const telegram_format_js_1 = require("./telegram-format.js");
62
12
  const telegram_message_ledger_js_1 = require("./telegram-message-ledger.js");
63
- const member_candidate_store_js_1 = require("./member-candidate-store.js");
64
- const principal_js_1 = require("./principal.js");
65
- const security_monitor_js_1 = require("../security/security-monitor.js");
66
- const debugLogger = __importStar(require("@jungjaehoon/mama-core/debug-logger"));
67
- const { DebugLogger } = debugLogger;
68
- const telegramLogger = new DebugLogger('telegram');
13
+ const telegram_response_presenter_js_1 = require("./telegram-response-presenter.js");
14
+ const file_delivery_js_1 = require("../api/file-delivery.js");
15
+ const telegram_errors_js_1 = require("./telegram-errors.js");
16
+ const telegram_attachments_js_1 = require("./telegram-attachments.js");
69
17
  const TELEGRAM_MAX_LENGTH = 4096;
70
18
  const MESSAGE_DEDUP_TTL_MS = 60_000;
71
- const REJECTED_CHAT_WARN_INTERVAL_MS = 60_000;
72
- const TYPING_INTERVAL_MS = 4_000;
73
- function parseOutboundChunkProgress(value) {
74
- const parsed = JSON.parse(value);
75
- if (!parsed || typeof parsed !== 'object')
76
- throw new Error('Invalid Telegram outbound progress');
77
- const record = parsed;
78
- if (record.version !== 1 ||
79
- !Number.isSafeInteger(record.nextIndex) ||
80
- record.nextIndex < 0 ||
81
- typeof record.uncertain !== 'boolean') {
82
- throw new Error('Invalid Telegram outbound progress');
83
- }
84
- return { nextIndex: record.nextIndex, uncertain: record.uncertain };
85
- }
86
- function isDefiniteTelegramApiRejection(error) {
87
- if (!error || typeof error !== 'object')
88
- return false;
89
- const record = error;
90
- if (Number.isSafeInteger(record.error_code))
91
- return true;
92
- const response = record.response;
93
- return (Boolean(response) &&
94
- typeof response === 'object' &&
95
- Number.isSafeInteger(response.error_code));
96
- }
97
- /**
98
- * Report-delivery terminal classifier (design Decision 3): ONLY a definite
99
- * Telegram non-acceptance may park a report as `prepared_definite_rejection`.
100
- * 429 and 5xx (and anything carrying `retry_after`) remain retryable - a
101
- * routine rate limit must never permanently silence owner reporting. This is
102
- * deliberately narrower than isDefiniteTelegramApiRejection, which answers a
103
- * different question (was the chunk send outcome unambiguous?).
104
- */
105
- function isTerminalTelegramRejection(error) {
106
- if (!isDefiniteTelegramApiRejection(error))
107
- return false;
108
- const record = error;
109
- const errorCode = Number.isSafeInteger(record.error_code)
110
- ? record.error_code
111
- : Number.isSafeInteger(record.response?.error_code)
112
- ? record.response.error_code
113
- : null;
114
- if (errorCode === null)
115
- return false;
116
- const parameters = record.parameters;
117
- if (parameters && Number.isSafeInteger(parameters.retry_after))
118
- return false;
119
- if (errorCode === 429 || errorCode >= 500)
120
- return false;
121
- return errorCode >= 400;
19
+ const INTERRUPTED_RESPONSE = 'The previous processing attempt was interrupted. It was not rerun because its external ' +
20
+ 'side effects could not be proven safe to repeat. Please send a new message if you want to ' +
21
+ 'retry it.';
22
+ function entityOptions(entities) {
23
+ return { entities };
122
24
  }
123
- function telegramRejectionReason(error) {
124
- if (error && typeof error === 'object') {
125
- const record = error;
126
- if (typeof record.description === 'string' && record.description.length > 0) {
127
- return record.description;
128
- }
129
- const response = record.response;
130
- if (response && typeof response === 'object') {
131
- const description = response.description;
132
- if (typeof description === 'string' && description.length > 0)
133
- return description;
134
- }
135
- }
25
+ function telegramErrorMessage(error) {
136
26
  return error instanceof Error ? error.message : String(error);
137
27
  }
138
- /**
139
- * Telegram's own MessageEntity union is narrower than the structural entity the
140
- * formatter produces; the wire shape is identical.
141
- */
142
- function entityOptions(entities) {
143
- return { entities };
28
+ function sendErrorIsEntityOnly(error) {
29
+ return (0, telegram_format_js_1.isTelegramEntityRejection)(telegramErrorMessage(error));
144
30
  }
145
- /**
146
- * Send one formatted chunk. If Telegram rejects the entity list, resend the
147
- * same text unstyled: losing the styling is acceptable, losing the answer is
148
- * not. Any other failure stays a failure so the delivery ledger sees it.
149
- * Unstyled text is sent exactly as before, without an options argument.
150
- */
151
31
  async function sendFormattedMessage(api, chatId, message) {
152
- if (!message.entities.length) {
153
- return await api.sendMessage(chatId, message.text);
154
- }
32
+ if (message.entities.length === 0)
33
+ return api.sendMessage(chatId, message.text);
155
34
  try {
156
35
  return await api.sendMessage(chatId, message.text, entityOptions(message.entities));
157
36
  }
158
37
  catch (error) {
159
- if (!(0, telegram_format_js_1.isTelegramEntityRejection)(telegramRejectionReason(error)))
38
+ if (!sendErrorIsEntityOnly(error))
160
39
  throw error;
161
- return await api.sendMessage(chatId, message.text);
40
+ return api.sendMessage(chatId, message.text);
162
41
  }
163
42
  }
164
- /** Edit one formatted chunk, with the same styling-only fallback. */
165
43
  async function editFormattedMessage(api, chatId, messageId, message) {
166
- if (!message.entities.length) {
44
+ if (message.entities.length === 0) {
167
45
  await api.editMessageText(chatId, messageId, message.text);
168
46
  return;
169
47
  }
170
48
  try {
171
49
  await api.editMessageText(chatId, messageId, message.text, entityOptions(message.entities));
172
- return;
173
50
  }
174
51
  catch (error) {
175
- if (!(0, telegram_format_js_1.isTelegramEntityRejection)(telegramRejectionReason(error)))
52
+ if (!sendErrorIsEntityOnly(error))
176
53
  throw error;
54
+ await api.editMessageText(chatId, messageId, message.text);
177
55
  }
178
- await api.editMessageText(chatId, messageId, message.text);
179
56
  }
180
- const EMOTION_EMOJI = {
181
- happy: ['😊', '😀', '😄', '🙂'],
182
- laugh: ['😂', '🤣', '😆'],
183
- love: ['❤️', '😍', '🥰', '💕'],
184
- sad: ['😢', '😞', '😔'],
185
- cry: ['😭', '😿'],
186
- angry: ['😠', '😡', '🤬'],
187
- surprised: ['😮', '😲', '😯', '🤯'],
188
- ok: ['👌', '👍', '✅'],
189
- thanks: ['🙏', '🤗'],
190
- sorry: ['🙇', '😓', '💦'],
191
- hello: ['👋', '🙋', '✋'],
192
- bye: ['👋', '🫡'],
193
- thinking: ['🤔', '💭'],
194
- excited: ['🎉', '🥳', '✨'],
195
- tired: ['😫', '😩', '😴'],
196
- };
197
- const DEFAULT_STICKER_SET = 'HotCherry';
198
- /**
199
- * Telegram Gateway class
200
- */
57
+ function sourceMessageRef(chatId, messageId) {
58
+ return `telegram:${chatId}:${messageId}`;
59
+ }
60
+ function chatIdFromSourceMessageRef(value) {
61
+ const prefix = 'telegram:';
62
+ if (!value.startsWith(prefix))
63
+ throw new Error('Telegram source message reference is invalid');
64
+ const rest = value.slice(prefix.length);
65
+ const separator = rest.lastIndexOf(':');
66
+ if (separator <= 0 || !/^\d+$/.test(rest.slice(separator + 1))) {
67
+ throw new Error('Telegram source message reference is invalid');
68
+ }
69
+ return rest.slice(0, separator);
70
+ }
71
+ function outboundLedgerKey(idempotencyKey) {
72
+ return `outbound:${(0, node_crypto_1.createHash)('sha256').update(`text\0${idempotencyKey}`).digest('hex')}`;
73
+ }
74
+ /** Telegram owner ingress and its durable response transport. */
201
75
  class TelegramGateway extends base_gateway_js_1.BaseGateway {
202
76
  source = 'telegram';
203
- principalResolver;
204
77
  token;
205
78
  config;
206
- bot = null;
207
- botId = 0;
208
- botUsername = '';
209
- lastError = null;
210
- lastMessageAt;
211
- mediaRoot;
212
- fetchImpl;
79
+ filesRoot;
80
+ downloadsDir;
81
+ log;
82
+ onFatalError;
213
83
  messageLedger;
214
84
  chatTails = new Map();
215
- inboundTails = new Map();
216
- activeInboundMessages = new Set();
217
- activeChat = new node_async_hooks_1.AsyncLocalStorage();
218
- // Telegram update dedup
85
+ activePresenters = new Map();
219
86
  recentMessageIds = new Map();
220
- rejectedChatWarnAt = new Map();
221
- // Dedup cleanup timer
222
- dedupCleanupTimer = null;
223
- // Sticker cache
224
- stickerCache = new Map();
225
- stickerSetLoaded = false;
87
+ activeChat = new node_async_hooks_1.AsyncLocalStorage();
88
+ bot = null;
89
+ lastError = null;
90
+ lastMessageAt;
226
91
  get mentionPattern() {
227
- return null; // Group filtering handled explicitly in handleMessage
92
+ return null;
228
93
  }
229
94
  constructor(options) {
230
- // The seam lives on the shared surface role, not on this gateway.
231
- super({ turnProcessor: options.turnProcessor });
95
+ super({ intake: options.intake });
232
96
  this.token = options.token;
233
- this.principalResolver = options.principalResolver;
234
97
  this.config = {
235
- enabled: true,
236
- token: options.token,
237
- allowedChats: options.config?.allowedChats || [],
238
- ownerUserIds: options.config?.ownerUserIds,
98
+ enabled: options.config?.enabled ?? true,
99
+ allowedChats: options.config?.allowedChats ?? [],
100
+ ...(options.config?.ownerUserIds === undefined
101
+ ? {}
102
+ : { ownerUserIds: options.config.ownerUserIds }),
103
+ ...(options.config?.ownerChatId === undefined
104
+ ? {}
105
+ : { ownerChatId: options.config.ownerChatId }),
106
+ ...(options.config?.polling === undefined ? {} : { polling: options.config.polling }),
239
107
  };
240
- this.mediaRoot =
241
- options.mediaRoot ??
242
- (0, node_path_1.join)(process.env.MAMA_WORKSPACE || (0, node_path_1.join)((0, node_os_1.homedir)(), '.mama', 'workspace'), 'media', 'inbound', 'telegram');
243
- this.fetchImpl = options.fetchImpl;
244
- this.messageLedger = new telegram_message_ledger_js_1.TelegramMessageLedger(options.messageLedgerPath ??
245
- process.env.MAMA_TELEGRAM_MESSAGE_LEDGER_PATH ??
246
- `${this.mediaRoot}.processed-message-ids.json`, { log: (line) => console.error(line) });
108
+ this.filesRoot = options.filesRoot;
109
+ this.downloadsDir = options.downloadsDir;
110
+ this.onFatalError =
111
+ options.onFatalError ??
112
+ ((error) => {
113
+ queueMicrotask(() => {
114
+ throw error;
115
+ });
116
+ });
117
+ this.log = options.log ?? ((line) => console.log(line));
118
+ const ledgerPath = options.messageLedgerPath ?? process.env.MAMA_TELEGRAM_MESSAGE_LEDGER_PATH;
119
+ if (!options.messageLedger && !ledgerPath?.trim()) {
120
+ throw new Error('Telegram message ledger path is required');
121
+ }
122
+ this.messageLedger =
123
+ options.messageLedger ?? new telegram_message_ledger_js_1.TelegramMessageLedger(ledgerPath, { log: this.log });
247
124
  }
248
125
  async start() {
249
- if (this.connected) {
250
- console.log('Telegram gateway already connected');
126
+ if (this.connected)
251
127
  return;
252
- }
253
128
  if (!this.config.allowedChats?.some((chatId) => chatId.trim().length > 0)) {
254
129
  throw new Error('telegram gateway disabled: allowed_chats is not set. Run: mama status');
255
130
  }
131
+ if (!this.token.trim())
132
+ throw new Error('telegram gateway requires a token');
256
133
  try {
257
134
  this.bot = new grammy_1.Bot(this.token);
258
135
  this.bot.on('message', async (ctx) => {
259
- try {
260
- if (ctx.message) {
261
- await this.handleMessage(ctx.message);
262
- }
263
- }
264
- catch (error) {
265
- console.error('[Telegram] Error handling message:', error);
266
- this.emitEvent({
267
- type: 'error',
268
- source: 'telegram',
269
- timestamp: new Date(),
270
- data: { error: error instanceof Error ? error.message : String(error) },
271
- });
272
- // Let grammY treat the update as failed. The durable message ledger
273
- // prevents unsafe turn re-execution and replays a ready outbox response.
274
- throw error;
275
- }
136
+ if (ctx.message)
137
+ await this.handleMessage(ctx.message);
276
138
  });
277
- this.bot.catch((err) => {
278
- this.lastError = err.message ?? String(err);
279
- console.error(`[Telegram] error: ${this.lastError}`);
139
+ this.bot.catch((error) => {
140
+ this.lastError = telegramErrorMessage(error);
141
+ console.error(`telegram handler failed error=${this.lastError}`);
280
142
  });
281
143
  await this.bot.init();
282
- this.botId = this.bot.botInfo.id;
283
- this.botUsername = this.bot.botInfo.username || '';
284
- console.log(`Telegram bot logged in as @${this.botUsername}`);
285
- await this.recoverPendingInboundDeliveries();
286
- console.log(`[Telegram] Inbound allowlist active: ${this.config.allowedChats.length} chat(s)`);
287
144
  this.connected = true;
288
145
  this.lastError = null;
289
- await (0, telegram_media_js_1.pruneTelegramMediaRoot)(this.mediaRoot);
290
- // Periodic dedup cleanup
291
- this.dedupCleanupTimer = setInterval(() => {
292
- const now = Date.now();
293
- for (const [key, ts] of this.recentMessageIds) {
294
- if (now - ts > MESSAGE_DEDUP_TTL_MS)
295
- this.recentMessageIds.delete(key);
296
- }
297
- for (const [key, ts] of this.rejectedChatWarnAt) {
298
- if (now - ts > REJECTED_CHAT_WARN_INTERVAL_MS) {
299
- this.rejectedChatWarnAt.delete(key);
300
- }
301
- }
302
- void (0, telegram_media_js_1.pruneTelegramMediaRoot)(this.mediaRoot).catch((error) => {
303
- console.error(`[Telegram] media retention cleanup failed: ${error instanceof Error ? error.message : String(error)}`);
146
+ this.emitEvent({ type: 'connected', source: 'telegram', timestamp: new Date() });
147
+ await this.recoverPendingResponses();
148
+ if (this.config.polling !== false) {
149
+ // Polling runs for the life of the process; a failure here means no owner message
150
+ // is ever received, so it is logged, not swallowed.
151
+ this.bot.start().catch((error) => {
152
+ this.lastError = telegramErrorMessage(error);
153
+ this.connected = false;
154
+ console.error(`telegram polling stopped error=${this.lastError}`);
155
+ this.onFatalError(error);
304
156
  });
305
- void this.recoverPendingInboundDeliveries().catch((error) => {
306
- console.error(`[Telegram] pending response recovery failed: ${error instanceof Error ? error.message : String(error)}`);
307
- });
308
- }, 60_000);
309
- this.emitEvent({
310
- type: 'connected',
311
- source: 'telegram',
312
- timestamp: new Date(),
313
- data: { username: this.botUsername },
314
- });
315
- // Start long polling (non-blocking)
316
- this.bot.start();
157
+ console.log(`telegram polling started polling=${this.config.polling ?? 'default'}`);
158
+ }
159
+ else {
160
+ console.log('telegram polling disabled by config');
161
+ }
317
162
  }
318
163
  catch (error) {
319
- if (this.bot) {
320
- try {
321
- await this.bot.stop();
322
- }
323
- catch {
324
- /* ignore */
325
- }
326
- this.bot = null;
327
- }
328
- this.lastError = error instanceof Error ? error.message : String(error);
329
- console.error('Telegram connection failed:', error);
164
+ this.lastError = telegramErrorMessage(error);
165
+ if (this.bot)
166
+ await this.bot.stop().catch(() => { });
167
+ this.bot = null;
168
+ this.connected = false;
330
169
  throw error;
331
170
  }
332
171
  }
333
172
  async stop() {
334
- if (this.dedupCleanupTimer) {
335
- clearInterval(this.dedupCleanupTimer);
336
- this.dedupCleanupTimer = null;
337
- }
338
- if (this.bot) {
339
- try {
340
- await this.bot.stop();
341
- }
342
- catch {
343
- /* ignore */
344
- }
345
- this.bot = null;
346
- this.stickerCache.clear();
347
- this.stickerSetLoaded = false;
348
- }
349
- this.rejectedChatWarnAt.clear();
173
+ if (this.bot)
174
+ await this.bot.stop().catch(() => { });
175
+ this.bot = null;
350
176
  this.connected = false;
351
- this.emitEvent({
352
- type: 'disconnected',
353
- source: 'telegram',
354
- timestamp: new Date(),
355
- });
356
- }
357
- async handleMessage(msg) {
358
- if (!msg.from || !msg.chat)
177
+ this.recentMessageIds.clear();
178
+ this.emitEvent({ type: 'disconnected', source: 'telegram', timestamp: new Date() });
179
+ }
180
+ /** Delivered inbound identities; message and answer text stay in the durable runtime journal. */
181
+ recentDeliveredMessageRefs() {
182
+ return this.messageLedger.recentDeliveredMessageRefs();
183
+ }
184
+ /** Final response callback used by the owner runtime after a native turn settles. */
185
+ async deliverResponse(sourceRef, response) {
186
+ const chatId = chatIdFromSourceMessageRef(sourceRef);
187
+ this.requireAllowedChat(chatId);
188
+ const existing = this.messageLedger.get(sourceRef);
189
+ if (!existing)
190
+ throw new Error(`Telegram response has no accepted message ${sourceRef}`);
191
+ if (existing.deliveryTarget && existing.deliveryTarget !== `telegram:${chatId}`) {
192
+ throw new Error('Telegram response destination conflicts with its accepted message');
193
+ }
194
+ if (existing.state === 'delivered')
359
195
  return;
360
- const now = Date.now();
361
- const messageKey = `${msg.chat.id}:${msg.message_id}`;
362
- if (this.messageLedger.get(messageKey)?.state === 'delivered')
196
+ if (existing.state === 'ready' && existing.response !== response) {
197
+ throw new Error('Telegram response conflicts with its durable ledger entry');
198
+ }
199
+ if (existing.state === 'processing')
200
+ this.messageLedger.markReady(sourceRef, response, 'html-v1');
201
+ if (!this.bot || !this.connected)
363
202
  return;
364
- if (this.recentMessageIds.has(messageKey))
203
+ await this.deliverReadyEntry(sourceRef);
204
+ }
205
+ async sendMessage(chatId, text, idempotencyKey) {
206
+ if (!this.bot || !this.connected)
207
+ throw new Error('Telegram gateway not connected');
208
+ this.requireAllowedChat(chatId);
209
+ const trimmed = text.trim();
210
+ if (!trimmed)
365
211
  return;
366
- this.recentMessageIds.set(messageKey, now);
367
- for (const [key, ts] of this.recentMessageIds) {
368
- if (now - ts > MESSAGE_DEDUP_TTL_MS)
369
- this.recentMessageIds.delete(key);
370
- }
371
- const chatId = String(msg.chat.id);
372
- if (this.config.allowedChats && this.config.allowedChats.length > 0) {
373
- if (!this.config.allowedChats.includes(chatId)) {
374
- const lastWarn = this.rejectedChatWarnAt.get(chatId) ?? 0;
375
- if (now - lastWarn > REJECTED_CHAT_WARN_INTERVAL_MS) {
376
- this.rejectedChatWarnAt.set(chatId, now);
377
- console.warn(`[Telegram] Dropped message from non-allowlisted chat ${msg.chat.id} (user ${msg.from.id})`);
378
- }
379
- return;
380
- }
381
- }
382
- let principal = (0, principal_js_1.resolveTelegramPrincipal)({
383
- userId: String(msg.from.id),
384
- chatId,
385
- chatType: msg.chat.type,
386
- allowedChats: new Set(this.config.allowedChats ?? []),
387
- ownerUserIds: this.config.ownerUserIds === undefined ? undefined : new Set(this.config.ownerUserIds),
388
- });
389
- if (this.principalResolver) {
390
- principal = (0, principal_js_1.overlayMemberPrincipal)(principal, this.principalResolver('telegram', 'global', String(msg.from.id)));
391
- }
392
- if (principal.class === 'owner' &&
393
- principal.consoleEligible &&
394
- msg.forward_origin?.type === 'user' &&
395
- Boolean(msg.forward_origin.sender_user)) {
396
- (0, member_candidate_store_js_1.getMemberCandidateStore)().upsert({
397
- connector: 'telegram',
398
- namespace: 'global',
399
- externalId: String(msg.forward_origin.sender_user.id),
400
- displayName: msg.forward_origin.sender_user.first_name,
401
- firstSeen: now,
402
- expiresAt: now + member_candidate_store_js_1.MEMBER_CANDIDATE_TTL_MS,
403
- });
404
- }
405
- if (principal.lane === 'divert') {
406
- (0, security_monitor_js_1.logSecurityEventOnly)({
407
- type: 'telegram_principal_diverted',
408
- severity: 'warn',
409
- message: 'Telegram ingress diverted before processing',
410
- details: { source: 'telegram', chatType: msg.chat.type },
212
+ await this.runInChatQueue(chatId, () => this.sendMessageNow(chatId, trimmed, idempotencyKey));
213
+ }
214
+ async sendToOwner(text, idempotencyKey) {
215
+ const ownerChatId = this.config.ownerChatId?.trim();
216
+ if (!ownerChatId)
217
+ throw new Error('telegram.owner_chat_id is required for delta delivery');
218
+ await this.sendMessage(ownerChatId, text, idempotencyKey);
219
+ }
220
+ async sendFile(path, caption, operationId) {
221
+ if (!this.bot || !this.connected)
222
+ throw new Error('Telegram gateway not connected');
223
+ if (operationId.trim() === '')
224
+ throw new Error('Telegram file operation id is required');
225
+ const ownerChatId = this.config.ownerChatId?.trim();
226
+ if (!ownerChatId)
227
+ throw new Error('telegram.owner_chat_id is required for file delivery');
228
+ this.requireAllowedChat(ownerChatId);
229
+ if (!this.filesRoot)
230
+ throw new Error('Telegram workspace files root is not configured');
231
+ const validated = (0, file_delivery_js_1.openWorkspaceFile)(this.filesRoot, path);
232
+ try {
233
+ const payloadIdentity = (0, file_delivery_js_1.workspaceFileIdentity)(validated.fd, caption);
234
+ const claim = this.messageLedger.claim(`file:${operationId}`, {
235
+ deliveryTarget: `telegram:${ownerChatId}`,
236
+ payloadIdentity,
411
237
  });
412
- return;
413
- }
414
- const laneKey = (0, principal_js_1.laneChannelId)(chatId, principal.lane);
415
- await this.runInQueue(this.inboundTails, laneKey, async () => {
416
- this.activeInboundMessages.add(messageKey);
417
- try {
418
- await this.processMessage(msg, messageKey, principal);
419
- }
420
- finally {
421
- this.activeInboundMessages.delete(messageKey);
238
+ if (!claim.claimed) {
239
+ if (claim.entry.state === 'delivered') {
240
+ return {
241
+ sentAs: validated.sentAs,
242
+ size: validated.size,
243
+ idempotent: true,
244
+ };
245
+ }
246
+ throw new Error('Telegram file delivery operation is already in progress or uncertain');
422
247
  }
423
- });
424
- }
425
- async runInChatQueue(chatKey, work, allowReentrant = false) {
426
- const active = this.activeChat.getStore();
427
- if (allowReentrant && active?.active && active.key === chatKey)
428
- return work();
429
- return this.runInQueue(this.chatTails, chatKey, async () => {
430
- const lease = { key: chatKey, active: true };
248
+ const upload = new grammy_1.InputFile((0, file_delivery_js_1.readWorkspaceFile)(validated.fd), (0, node_path_1.basename)(validated.path));
431
249
  try {
432
- return await this.activeChat.run(lease, work);
250
+ const sent = validated.sentAs === 'photo'
251
+ ? await this.bot.api.sendPhoto(ownerChatId, upload, caption === undefined ? undefined : { caption })
252
+ : await this.bot.api.sendDocument(ownerChatId, upload, caption === undefined ? undefined : { caption });
253
+ this.messageLedger.markDelivered(`file:${operationId}`);
254
+ return {
255
+ messageId: sent.message_id,
256
+ sentAs: validated.sentAs,
257
+ size: validated.size,
258
+ };
433
259
  }
434
- finally {
435
- // Async work inherited from a completed send cannot bypass a later batch.
436
- lease.active = false;
260
+ catch (error) {
261
+ this.messageLedger.markFailed(`file:${operationId}`);
262
+ throw error;
437
263
  }
438
- });
439
- }
440
- /** Inbound ordering and outbound atomic batches have separate lifetimes. */
441
- async runInQueue(tails, key, work) {
442
- const previous = tails.get(key);
443
- let release;
444
- const gate = new Promise((resolve) => {
445
- release = resolve;
446
- });
447
- const currentTail = (previous ?? Promise.resolve()).catch(() => { }).then(() => gate);
448
- tails.set(key, currentTail);
449
- try {
450
- if (previous)
451
- await previous.catch(() => { });
452
- return await work();
453
264
  }
454
265
  finally {
455
- release();
456
- if (tails.get(key) === currentTail)
457
- tails.delete(key);
266
+ (0, node_fs_1.closeSync)(validated.fd);
267
+ }
268
+ }
269
+ getLastError() {
270
+ return this.lastError;
271
+ }
272
+ getLastMessageAt() {
273
+ return this.lastMessageAt;
274
+ }
275
+ ownerAllowed(chatId, userId) {
276
+ if (!this.config.allowedChats?.includes(chatId))
277
+ return false;
278
+ if (this.config.ownerUserIds !== undefined)
279
+ return this.config.ownerUserIds.includes(userId);
280
+ return this.config.allowedChats.length === 1 && this.config.allowedChats[0] === userId;
281
+ }
282
+ requireAllowedChat(chatId) {
283
+ if (!this.config.allowedChats?.includes(chatId)) {
284
+ throw new Error('Telegram destination is not allowlisted');
458
285
  }
459
286
  }
460
- async processMessage(msg, messageKey, principal) {
461
- if (!msg.from || !msg.chat)
287
+ async handleMessage(message) {
288
+ if (!message.chat || !message.from)
462
289
  return;
463
- const now = Date.now();
464
- const hasMedia = Boolean((msg.photo && msg.photo.length > 0) || msg.document);
465
- if (hasMedia && (!this.config.allowedChats || this.config.allowedChats.length === 0)) {
466
- const lastWarn = this.rejectedChatWarnAt.get(String(msg.chat.id)) ?? 0;
467
- if (now - lastWarn > REJECTED_CHAT_WARN_INTERVAL_MS) {
468
- this.rejectedChatWarnAt.set(String(msg.chat.id), now);
469
- console.warn('[Telegram] Dropped media because telegram.allowed_chats is not configured');
470
- }
290
+ const chatId = String(message.chat.id);
291
+ const userId = String(message.from.id);
292
+ if (message.from.is_bot || !this.ownerAllowed(chatId, userId)) {
293
+ const chatHash = (0, node_crypto_1.createHash)('sha256').update(`chat\0${chatId}`).digest('hex');
294
+ const senderHash = (0, node_crypto_1.createHash)('sha256').update(`sender\0${userId}`).digest('hex');
295
+ console.warn(`telegram message dropped reason=non_owner chat_hash=${chatHash} sender_hash=${senderHash}`);
471
296
  return;
472
297
  }
473
- // Task G: text pairs with `entities`, caption with `caption_entities`. The
474
- // selected field is the ORIGINAL reference frame for every entity offset
475
- // (UTF-16 code units); later host adjustments never rewrite it.
476
- const { field: selectedField, text: selectedText, entities: selectedEntities, } = (0, telegram_text_entities_js_1.selectTelegramTextEntities)(msg);
477
- const telegramFormatting = msg.sticker
478
- ? undefined
479
- : (0, telegram_text_entities_js_1.captureTelegramTextFormatting)(selectedField, selectedText, selectedEntities);
480
- // Group chat filtering
481
- const isGroup = msg.chat.type === 'group' || msg.chat.type === 'supergroup';
482
- if (isGroup) {
483
- const isMention = this.botUsername &&
484
- selectedEntities?.some((e) => e.type === 'mention' &&
485
- selectedText.slice(e.offset, e.offset + e.length).toLowerCase() ===
486
- `@${this.botUsername.toLowerCase()}`);
487
- const isBotCommand = selectedEntities?.some((e) => e.type === 'bot_command');
488
- const isReplyToBot = msg.reply_to_message?.from?.id === this.botId;
489
- if (!isMention && !isBotCommand && !isReplyToBot)
490
- return;
491
- }
492
- let text = selectedText;
493
- if (msg.sticker) {
494
- text = `[sticker: ${msg.sticker.emoji || '😊'}]`;
495
- }
496
- if (isGroup && this.botUsername) {
497
- const escaped = this.botUsername.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
498
- text = text.replace(new RegExp(`@${escaped}\\b`, 'gi'), '').trim();
499
- }
500
- // Provenance labeling: a FORWARDED message is third-party content the
501
- // owner relayed, not the owner speaking. Selection and mention removal
502
- // happen first so caption provenance follows the same trust boundary.
503
- const isForwarded = Boolean(msg.forward_origin);
504
- const durableEntry = this.messageLedger.get(messageKey);
505
- const numChatId = msg.chat.id;
506
- const api = this.bot.api;
507
- let initialResponseMessageId = null;
508
- const presenter = this.createResponsePresenter(numChatId, messageKey, durableEntry?.nextChunkIndex ?? 0, (messageId) => {
509
- initialResponseMessageId = messageId;
510
- });
511
- if (durableEntry?.state !== 'ready')
512
- await presenter.start();
513
- if (durableEntry?.state === 'ready' && durableEntry.response !== undefined) {
514
- try {
515
- await presenter.finalize(durableEntry.response);
516
- this.messageLedger.markDelivered(messageKey);
517
- }
518
- catch (error) {
519
- this.recentMessageIds.delete(messageKey);
520
- throw error;
521
- }
298
+ const ref = sourceMessageRef(chatId, message.message_id);
299
+ const now = Date.now();
300
+ const previous = this.recentMessageIds.get(ref);
301
+ if (previous !== undefined && now - previous <= MESSAGE_DEDUP_TTL_MS)
522
302
  return;
303
+ this.recentMessageIds.set(ref, now);
304
+ for (const [key, timestamp] of this.recentMessageIds) {
305
+ if (now - timestamp > MESSAGE_DEDUP_TTL_MS)
306
+ this.recentMessageIds.delete(key);
523
307
  }
524
- if (durableEntry?.state === 'processing') {
525
- const interruptedNotice = 'The previous processing attempt was interrupted. It was not rerun because its external ' +
526
- 'side effects could not be proven safe to repeat. Please send a new message if you want ' +
527
- 'to retry it.';
528
- this.messageLedger.markReady(messageKey, interruptedNotice, 'html-v1');
529
- try {
530
- await presenter.finalize(interruptedNotice);
531
- this.messageLedger.markDelivered(messageKey);
532
- }
533
- catch (error) {
534
- this.recentMessageIds.delete(messageKey);
535
- throw error;
536
- }
308
+ const durable = this.messageLedger.get(ref);
309
+ if (durable?.state === 'delivered')
537
310
  return;
538
- }
539
- const attachments = [];
540
- const contentBlocks = [];
541
- let transientMediaPath;
542
- // The public lane is conversation-only: a non-owner's attachment is never
543
- // downloaded with the bot's credentials and never becomes a model-visible
544
- // content block. Text/caption still flows.
545
- const mediaAllowed = principal.lane === 'owner';
546
- try {
547
- if (mediaAllowed && msg.photo && msg.photo.length > 0) {
548
- const photo = msg.photo[msg.photo.length - 1];
549
- const downloaded = await (0, telegram_media_js_1.downloadTelegramMedia)({
550
- botToken: this.token,
551
- fileId: photo.file_id,
552
- fileUniqueId: photo.file_unique_id,
553
- declaredSize: photo.file_size,
554
- kind: 'photo',
555
- mediaRoot: this.mediaRoot,
556
- getFile: (fileId) => api.getFile(fileId),
557
- fetchImpl: this.fetchImpl,
558
- });
559
- transientMediaPath = downloaded.localPath;
560
- const detectedType = (0, attachment_utils_js_1.detectImageType)(await (0, promises_1.readFile)(downloaded.localPath));
561
- if (!detectedType) {
562
- await presenter.fail('This image format is not supported.');
563
- return;
564
- }
565
- const attachment = {
566
- type: 'image',
567
- sourceRef: downloaded.sourceRef,
568
- localPath: downloaded.localPath,
569
- filename: downloaded.filename,
570
- contentType: detectedType,
571
- size: downloaded.size,
572
- };
573
- attachments.push(attachment);
574
- const builtBlocks = await (0, attachment_utils_js_1.buildContentBlocks)([attachment]);
575
- const imageBlocks = builtBlocks.filter((block) => block.type === 'image');
576
- if (imageBlocks.length === 0) {
577
- await presenter.fail('This image format is not supported.');
578
- return;
579
- }
580
- for (const block of imageBlocks) {
581
- contentBlocks.push({ type: 'image', source: block.source });
582
- }
583
- // Keep the private local path for bounded OCR/overlay follow-ups. The
584
- // media retention sweeper removes it after the configured TTL/quota.
585
- transientMediaPath = undefined;
586
- if (!text.trim()) {
587
- text = '[Image]';
588
- }
589
- }
590
- else if (mediaAllowed && msg.document) {
591
- const downloaded = await (0, telegram_media_js_1.downloadTelegramMedia)({
592
- botToken: this.token,
593
- fileId: msg.document.file_id,
594
- fileUniqueId: msg.document.file_unique_id,
595
- filename: msg.document.file_name,
596
- mimeType: msg.document.mime_type,
597
- declaredSize: msg.document.file_size,
598
- kind: 'document',
599
- mediaRoot: this.mediaRoot,
600
- getFile: (fileId) => api.getFile(fileId),
601
- fetchImpl: this.fetchImpl,
602
- });
603
- transientMediaPath = downloaded.localPath;
604
- const detectedType = (0, attachment_utils_js_1.detectImageType)(await (0, promises_1.readFile)(downloaded.localPath));
605
- if (downloaded.mimeType.startsWith('image/') && !detectedType) {
606
- await presenter.fail('This image format is not supported.');
607
- return;
608
- }
609
- const attachment = {
610
- type: detectedType ? 'image' : 'file',
611
- sourceRef: downloaded.sourceRef,
612
- localPath: downloaded.localPath,
613
- filename: downloaded.filename,
614
- contentType: detectedType ?? downloaded.mimeType,
615
- size: downloaded.size,
616
- };
617
- attachments.push(attachment);
618
- if (detectedType) {
619
- const builtBlocks = await (0, attachment_utils_js_1.buildContentBlocks)([attachment]);
620
- const imageBlocks = builtBlocks.filter((block) => block.type === 'image');
621
- if (imageBlocks.length === 0) {
622
- await presenter.fail('This image format is not supported.');
623
- return;
624
- }
625
- for (const block of imageBlocks) {
626
- contentBlocks.push({ type: 'image', source: block.source });
627
- }
628
- if (!text.trim()) {
629
- text = `[Image: ${downloaded.filename}]`;
630
- }
631
- transientMediaPath = undefined;
632
- }
633
- else {
634
- contentBlocks.push({
635
- type: 'text',
636
- text: `[File: ${downloaded.filename}, type: ${downloaded.mimeType}]`,
637
- });
638
- if (!text.trim()) {
639
- text = `[File: ${downloaded.filename}]`;
640
- }
641
- // Documents remain in the private inbound workspace so the routed
642
- // turn and a bounded follow-up can read the actual attachment.
643
- transientMediaPath = undefined;
644
- }
645
- }
646
- }
647
- catch {
648
- await presenter.fail(msg.document ? 'The file could not be downloaded.' : 'The image could not be downloaded.');
311
+ if (durable?.state === 'ready') {
312
+ await this.deliverReadyEntry(ref);
649
313
  return;
650
314
  }
651
- finally {
652
- if (transientMediaPath) {
653
- await (0, promises_1.unlink)(transientMediaPath).catch(() => { });
654
- }
315
+ if (durable?.state === 'processing' && this.activePresenters.has(ref))
316
+ return;
317
+ if (durable?.state === 'processing' && this.intake.isPending?.(ref))
318
+ return;
319
+ if (durable?.state === 'processing') {
320
+ this.messageLedger.markReady(ref, INTERRUPTED_RESPONSE, 'html-v1');
321
+ await this.deliverReadyEntry(ref);
322
+ return;
655
323
  }
656
- if (!text.trim()) {
657
- await presenter.fail('This Telegram message type is not supported.');
324
+ const selected = (0, telegram_text_entities_js_1.selectTelegramTextEntities)(message);
325
+ const files = (0, telegram_attachments_js_1.telegramFiles)(message);
326
+ if (!selected.text.trim() && files.length === 0)
658
327
  return;
328
+ const formatting = (0, telegram_text_entities_js_1.captureTelegramTextFormatting)(selected.field, selected.text, selected.entities);
329
+ const inputIdentity = (0, node_crypto_1.createHash)('sha256')
330
+ .update(`${selected.text}\0${files.map(({ file }) => file.file_unique_id).join(',')}`)
331
+ .digest('hex');
332
+ const ledgerEntry = this.messageLedger.claim(ref, {
333
+ deliveryTarget: `telegram:${chatId}`,
334
+ payloadIdentity: inputIdentity,
335
+ }).entry;
336
+ const presenter = this.createResponsePresenter(ref, Number(message.chat.id));
337
+ this.activePresenters.set(ref, presenter);
338
+ try {
339
+ if (ledgerEntry.state !== 'ready')
340
+ await presenter.start();
341
+ const attachments = await (0, telegram_attachments_js_1.downloadTelegramFiles)(files, {
342
+ api: this.bot.api,
343
+ token: this.token,
344
+ downloadsDir: this.downloadsDir,
345
+ messageId: message.message_id,
346
+ });
347
+ const input = {
348
+ id: ref,
349
+ channelKey: chatId,
350
+ occurredAt: message.date * 1000,
351
+ text: selected.text.trim()
352
+ ? selected.text
353
+ : attachments.map(({ name }) => `[file: ${name}]`).join('\n'),
354
+ ...(formatting === undefined && attachments.length === 0
355
+ ? {}
356
+ : {
357
+ payload: {
358
+ ...(formatting === undefined ? {} : { telegramFormatting: formatting }),
359
+ ...(attachments.length === 0 ? {} : { attachments }),
360
+ },
361
+ }),
362
+ };
363
+ this.intake.acceptOwnerMessage(input);
364
+ this.emitEvent({
365
+ type: 'message_received',
366
+ source: 'telegram',
367
+ timestamp: new Date(),
368
+ data: { sourceMessageRef: ref },
369
+ });
659
370
  }
660
- if (isForwarded) {
661
- text = (0, untrusted_content_js_1.wrapUntrustedContent)('telegram-forward', text);
371
+ catch (error) {
372
+ this.activePresenters.delete(ref);
373
+ throw error;
662
374
  }
663
- const sender = msg.from.username || String(msg.from.id);
664
- console.log(`[Telegram] Message from ${sender} (${text.length} chars)`);
665
- const memoryLogger = (0, memory_logger_js_1.getMemoryLogger)();
666
- memoryLogger.logMessage('Telegram', sender, text, false);
667
- this.emitEvent({
668
- type: 'message_received',
669
- source: 'telegram',
670
- timestamp: new Date(),
671
- data: { chatId: String(msg.chat.id), userId: String(msg.from.id) },
672
- });
673
- const normalizedMessage = {
674
- source: 'telegram',
675
- channelId: String(msg.chat.id),
676
- userId: String(msg.from.id),
677
- text,
678
- principal,
679
- contentBlocks: contentBlocks.length > 0 ? contentBlocks : undefined,
680
- metadata: {
681
- username: msg.from.username,
682
- messageId: String(msg.message_id),
683
- chatType: msg.chat.type,
684
- attachments: attachments.length > 0 ? attachments : undefined,
685
- // Trusted provenance flag: downstream strips untrusted blocks ONLY
686
- // when the GATEWAY wrapped them - sender-typed markers are not a
687
- // security boundary (forgeable in-band data).
688
- untrustedWrapped: isForwarded,
689
- // Sender styling as data. Offsets stay bound to originalText, so the
690
- // mention removal / placeholder / wrapper applied to `text` above
691
- // cannot shift them. A forwarded body's formatting is fenced by the
692
- // router under the same untrustedWrapped flag.
693
- ...(telegramFormatting ? { telegramFormatting } : {}),
375
+ }
376
+ createResponsePresenter(sourceRef, chatId) {
377
+ if (!this.bot)
378
+ throw new Error('Telegram gateway not connected');
379
+ return new telegram_response_presenter_js_1.TelegramResponsePresenter({
380
+ send: (content) => sendFormattedMessage(this.bot.api, chatId, content).then((sent) => String(sent.message_id)),
381
+ edit: (handle, content) => editFormattedMessage(this.bot.api, chatId, Number(handle), content),
382
+ delete: async (handle) => {
383
+ await this.bot.api.deleteMessage(chatId, Number(handle));
694
384
  },
695
- };
696
- // Typing indicator
697
- const chatId = String(msg.chat.id);
698
- const sendTyping = () => this.bot?.api.sendChatAction(numChatId, 'typing').catch(() => { });
699
- sendTyping();
700
- const typingInterval = setInterval(sendTyping, TYPING_INTERVAL_MS);
701
- try {
702
- // Process through message router
703
- let result;
704
- this.messageLedger.claim(messageKey);
705
- try {
706
- result = await this.turnProcessor.processTurn(normalizedMessage, {
707
- onStream: presenter.callbacks(),
708
- onQueued: () => presenter.markQueued(),
709
- });
710
- }
711
- catch (error) {
712
- const failureNotice = 'An error occurred while processing the message.';
713
- this.messageLedger.markReady(messageKey, failureNotice, 'html-v1');
714
- try {
715
- await presenter.fail(failureNotice);
716
- this.messageLedger.markDelivered(messageKey);
717
- }
718
- catch {
719
- this.recentMessageIds.delete(messageKey);
720
- }
721
- throw error;
722
- }
723
- if (result.outcome === 'external_divert') {
724
- if (initialResponseMessageId !== null) {
725
- await api.deleteMessage(numChatId, initialResponseMessageId).catch(() => { });
385
+ }, {
386
+ resumeFromChunk: this.messageLedger.get(sourceRef)?.nextChunkIndex ?? 0,
387
+ chunkFormat: this.messageLedger.get(sourceRef)?.chunkFormat ?? 'html-v1',
388
+ withDelivery: (send) => this.runInChatQueue(String(chatId), send, true),
389
+ onChunkProgress: (nextIndex, uncertain) => {
390
+ const entry = this.messageLedger.get(sourceRef);
391
+ if (entry?.state === 'ready') {
392
+ this.messageLedger.markDeliveryProgress(sourceRef, nextIndex, uncertain);
726
393
  }
727
- this.messageLedger.markReady(messageKey, '', 'html-v1');
728
- this.messageLedger.markDelivered(messageKey);
729
- telegramLogger.info('[Telegram] Turn externally diverted; no response sent');
394
+ },
395
+ });
396
+ }
397
+ async deliverReadyEntry(sourceRef) {
398
+ const entry = this.messageLedger.get(sourceRef);
399
+ if (!entry || entry.state === 'delivered')
400
+ return;
401
+ if (entry.response === undefined)
402
+ throw new Error('Telegram ready entry has no response');
403
+ const chatId = Number(chatIdFromSourceMessageRef(sourceRef));
404
+ await this.runInChatQueue(String(chatId), async () => {
405
+ const current = this.messageLedger.get(sourceRef);
406
+ if (!current || current.state === 'delivered')
730
407
  return;
731
- }
732
- this.messageLedger.markReady(messageKey, result.response, 'html-v1');
408
+ if (current.deliveryUncertain)
409
+ throw new Error('Telegram response delivery is uncertain');
410
+ const presenter = this.activePresenters.get(sourceRef) ?? this.createResponsePresenter(sourceRef, chatId);
733
411
  try {
734
- await presenter.finalize(result.response);
735
- this.messageLedger.markDelivered(messageKey);
412
+ await presenter.finalize(current.response);
736
413
  }
737
- catch (error) {
738
- this.recentMessageIds.delete(messageKey);
739
- throw error;
414
+ finally {
415
+ this.activePresenters.delete(sourceRef);
740
416
  }
417
+ this.messageLedger.markDelivered(sourceRef);
741
418
  this.lastMessageAt = Date.now();
742
- memoryLogger.logMessage('Telegram', 'MAMA', result.response, true);
743
419
  this.emitEvent({
744
420
  type: 'message_sent',
745
421
  source: 'telegram',
746
422
  timestamp: new Date(),
747
- data: {
748
- chatId,
749
- responseLength: result.response.length,
750
- duration: result.duration,
751
- },
423
+ data: { sourceMessageRef: sourceRef },
752
424
  });
753
- }
754
- finally {
755
- clearInterval(typingInterval);
756
- }
757
- }
758
- async sendMessage(chatId, text, idempotencyKey) {
759
- if (!this.bot)
760
- throw new Error('Telegram gateway not connected');
761
- if (!text.trim())
762
- return;
763
- await this.runInChatQueue(chatId, () => this.sendMessageNow(chatId, text, idempotencyKey));
764
- }
765
- /** Detached system work must wait behind the normal per-chat delivery queue. */
766
- async sendSystemMessage(chatId, text, deliveryId) {
767
- await this.sendMessage(chatId, text, deliveryId);
425
+ });
768
426
  }
769
- /**
770
- * TG-05/TG-06: narrow owner-report delivery surface for the report
771
- * coordinator. Pins the delivery-ID-bound ledger entry before the first
772
- * send so a confirmed-send proof cannot be pruned while the report-context
773
- * SQLite row remains nonterminal, and classifies send failures with the
774
- * gateway's own definite-rejection test.
775
- */
776
- createReportDeliveryControl() {
777
- const pinnedTargets = new Map();
778
- const ledgerKey = (deliveryId) => this.outboundLedgerKey(deliveryId, 'text');
779
- return {
780
- claimAndPin: async (binding) => {
781
- const key = ledgerKey(binding.deliveryId);
782
- this.messageLedger.claim(key, {
783
- deliveryTarget: `telegram:${binding.target.channelId}`,
784
- payloadIdentity: (0, node_crypto_1.createHash)('sha256').update(binding.text).digest('hex'),
785
- });
786
- this.messageLedger.pin(key);
787
- pinnedTargets.set(binding.deliveryId, {
788
- chatId: binding.target.channelId,
789
- text: binding.text,
790
- });
791
- return { deliveryId: binding.deliveryId };
792
- },
793
- sendPinned: async (lease) => {
794
- const pinned = pinnedTargets.get(lease.deliveryId);
795
- if (!pinned) {
796
- throw new Error(`Owner report delivery ${lease.deliveryId} was not pinned by this control`);
797
- }
798
- try {
799
- await this.sendMessage(pinned.chatId, pinned.text, lease.deliveryId);
800
- return { kind: 'confirmed' };
427
+ async recoverPendingResponses() {
428
+ for (const entry of this.messageLedger.listUndelivered()) {
429
+ try {
430
+ if (entry.deliveryUncertain) {
431
+ this.log(`telegram delivery requires reconciliation key=${entry.key} state=${entry.state} next_chunk_index=${entry.nextChunkIndex ?? 0}`);
432
+ continue;
801
433
  }
802
- catch (error) {
803
- if (isTerminalTelegramRejection(error)) {
804
- return { kind: 'definite_rejection', reason: telegramRejectionReason(error) };
434
+ if (entry.key.startsWith('outbound:') && entry.state === 'ready') {
435
+ const chatId = entry.deliveryTarget?.slice('telegram:'.length);
436
+ if (!entry.deliveryTarget?.startsWith('telegram:') || !chatId) {
437
+ throw new Error('Telegram outbound entry has no valid destination');
805
438
  }
806
- return {
807
- kind: 'retryable',
808
- detail: error instanceof Error ? error.message : String(error),
809
- };
439
+ if (!this.config.allowedChats?.includes(chatId))
440
+ continue;
441
+ await this.runInChatQueue(chatId, () => this.deliverOutboundEntry(entry.key, chatId));
442
+ continue;
810
443
  }
811
- },
812
- releasePin: async (deliveryId) => {
813
- this.messageLedger.unpin(ledgerKey(deliveryId));
814
- pinnedTargets.delete(deliveryId);
815
- },
816
- reconcilePins: async (nonterminalIds, terminalIds) => {
817
- for (const deliveryId of nonterminalIds) {
818
- const key = ledgerKey(deliveryId);
819
- if (this.messageLedger.get(key))
820
- this.messageLedger.pin(key);
444
+ if (!entry.key.startsWith('telegram:'))
445
+ continue;
446
+ const chatId = chatIdFromSourceMessageRef(entry.key);
447
+ if (!this.config.allowedChats?.includes(chatId))
448
+ continue;
449
+ if (entry.state === 'ready' && entry.response !== undefined) {
450
+ await this.deliverReadyEntry(entry.key);
451
+ continue;
821
452
  }
822
- for (const deliveryId of terminalIds) {
823
- this.messageLedger.unpin(ledgerKey(deliveryId));
453
+ if (entry.state === 'processing' && !this.intake.isPending?.(entry.key)) {
454
+ this.messageLedger.markReady(entry.key, INTERRUPTED_RESPONSE, 'html-v1');
455
+ await this.deliverReadyEntry(entry.key);
824
456
  }
825
- },
826
- };
827
- }
828
- async sendMessageFromActiveTurn(chatId, text, idempotencyKey) {
829
- if (!this.bot)
830
- throw new Error('Telegram gateway not connected');
831
- if (!text.trim())
832
- return;
833
- await this.runInChatQueue(chatId, () => this.sendMessageNow(chatId, text, idempotencyKey), true);
457
+ }
458
+ catch (error) {
459
+ // Delivery already recorded its progress; one entry must not keep polling from starting.
460
+ this.log(`telegram recovery failed key=${entry.key} error=${telegramErrorMessage(error)}`);
461
+ }
462
+ }
834
463
  }
835
464
  async sendMessageNow(chatId, text, idempotencyKey) {
836
- const bot = this.bot;
837
- if (!bot)
465
+ if (!this.bot)
838
466
  throw new Error('Telegram gateway not connected');
839
- const ledgerKey = idempotencyKey ? this.outboundLedgerKey(idempotencyKey, 'text') : undefined;
840
- const pending = ledgerKey ? this.messageLedger.get(ledgerKey) : null;
841
- const chunkFormat = pending?.state === 'ready' ? (pending.chunkFormat ?? 'plain-v1') : 'html-v1';
842
- const chunks = (0, telegram_format_js_1.formatTelegramMessage)(text, TELEGRAM_MAX_LENGTH, chunkFormat);
843
- // Zero chunks means zero API calls. Claiming the ledger and marking it
844
- // delivered would record a send that never happened and suppress every
845
- // retry of it, so refuse before touching the ledger at all.
846
- if (chunks.length === 0)
847
- throw new Error('Refusing to record an empty Telegram delivery');
848
- const numChatId = Number(chatId);
849
- if (!ledgerKey) {
467
+ const chunks = (0, telegram_format_js_1.formatTelegramMessage)(text, TELEGRAM_MAX_LENGTH, 'html-v1');
468
+ if (!idempotencyKey) {
850
469
  for (const chunk of chunks)
851
- await sendFormattedMessage(bot.api, numChatId, chunk);
470
+ await sendFormattedMessage(this.bot.api, Number(chatId), chunk);
852
471
  return;
853
472
  }
473
+ const key = outboundLedgerKey(idempotencyKey);
854
474
  const binding = {
855
475
  deliveryTarget: `telegram:${chatId}`,
856
476
  payloadIdentity: (0, node_crypto_1.createHash)('sha256').update(text).digest('hex'),
477
+ idempotencyKey,
478
+ keepDeliveredOnPayloadChange: true,
857
479
  };
858
- const { entry: existing } = this.messageLedger.claim(ledgerKey, binding);
859
- if (existing?.state === 'delivered')
480
+ const existing = this.messageLedger.claim(key, binding).entry;
481
+ if (existing.state === 'delivered')
860
482
  return;
861
- let nextIndex = 0;
862
- if (existing?.state === 'ready' && existing.response) {
863
- const progress = parseOutboundChunkProgress(existing.response);
864
- nextIndex = progress.nextIndex;
865
- if (progress.uncertain) {
866
- console.warn(`[Telegram] Retrying delivery ${ledgerKey} from chunk ${nextIndex} after an ` +
867
- 'ambiguous prior acceptance; at-least-once delivery may duplicate that chunk');
868
- }
869
- }
870
- for (let index = nextIndex; index < chunks.length; index += 1) {
871
- this.messageLedger.markReady(ledgerKey, JSON.stringify({ version: 1, nextIndex: index, uncertain: true }), chunkFormat);
483
+ if (existing.state !== 'ready')
484
+ this.messageLedger.markReady(key, text, 'html-v1');
485
+ await this.deliverOutboundEntry(key, chatId);
486
+ }
487
+ async deliverOutboundEntry(key, chatId) {
488
+ const entry = this.messageLedger.get(key);
489
+ if (!entry)
490
+ throw new Error(`Telegram outbound entry is missing: ${key}`);
491
+ if (entry.state === 'delivered')
492
+ return;
493
+ if (entry.deliveryUncertain)
494
+ throw new Error('Telegram outbound delivery is uncertain');
495
+ if (!this.bot)
496
+ throw new Error('Telegram gateway not connected');
497
+ if (entry.response === undefined)
498
+ throw new Error('Telegram outbound entry has no response');
499
+ // markReady persists both fields; inventing them could resend chunks or change their formatting.
500
+ if (entry.chunkFormat === undefined || entry.nextChunkIndex === undefined) {
501
+ throw new Error('Telegram outbound entry has incomplete delivery metadata');
502
+ }
503
+ const chunks = (0, telegram_format_js_1.formatTelegramMessage)(entry.response, TELEGRAM_MAX_LENGTH, entry.chunkFormat);
504
+ const start = entry.nextChunkIndex;
505
+ for (let index = start; index < chunks.length; index += 1) {
506
+ this.messageLedger.markDeliveryProgress(key, index, true);
872
507
  try {
873
- await sendFormattedMessage(bot.api, numChatId, chunks[index]);
508
+ const sent = await sendFormattedMessage(this.bot.api, Number(chatId), chunks[index]);
509
+ this.messageLedger.markDeliveryProgress(key, index + 1, false, sent.message_id);
874
510
  }
875
511
  catch (error) {
876
- if (isDefiniteTelegramApiRejection(error)) {
877
- this.messageLedger.markReady(ledgerKey, JSON.stringify({ version: 1, nextIndex: index, uncertain: false }), chunkFormat);
512
+ if ((0, telegram_errors_js_1.isDefinitiveTelegramRejection)(error)) {
513
+ this.messageLedger.markDeliveryProgress(key, index, false);
878
514
  }
879
515
  throw error;
880
516
  }
881
- this.messageLedger.markReady(ledgerKey, JSON.stringify({ version: 1, nextIndex: index + 1, uncertain: false }), chunkFormat);
882
- }
883
- this.messageLedger.markDelivered(ledgerKey);
884
- }
885
- async sendFile(chatId, filePath, caption, idempotencyKey) {
886
- if (!this.bot)
887
- throw new Error('Telegram gateway not connected');
888
- const { InputFile } = await import('grammy');
889
- await this.runInChatQueue(chatId, () => this.sendOutboundOnce(idempotencyKey, 'file', chatId, `${filePath}\0${caption ?? ''}`, () => this.bot.api.sendDocument(Number(chatId), new InputFile(filePath), { caption }).then(() => { })));
890
- }
891
- async sendFileFromActiveTurn(chatId, filePath, caption, idempotencyKey) {
892
- if (!this.bot)
893
- throw new Error('Telegram gateway not connected');
894
- const { InputFile } = await import('grammy');
895
- await this.runInChatQueue(chatId, () => this.sendOutboundOnce(idempotencyKey, 'file', chatId, `${filePath}\0${caption ?? ''}`, () => this.bot.api.sendDocument(Number(chatId), new InputFile(filePath), { caption }).then(() => { })), true);
896
- }
897
- async sendImage(chatId, imagePath, caption, idempotencyKey) {
898
- if (!this.bot)
899
- throw new Error('Telegram gateway not connected');
900
- const { InputFile } = await import('grammy');
901
- await this.runInChatQueue(chatId, () => this.sendOutboundOnce(idempotencyKey, 'image', chatId, `${imagePath}\0${caption ?? ''}`, () => this.bot.api.sendPhoto(Number(chatId), new InputFile(imagePath), { caption }).then(() => { })));
902
- }
903
- async sendImageFromActiveTurn(chatId, imagePath, caption, idempotencyKey) {
904
- if (!this.bot)
905
- throw new Error('Telegram gateway not connected');
906
- const { InputFile } = await import('grammy');
907
- await this.runInChatQueue(chatId, () => this.sendOutboundOnce(idempotencyKey, 'image', chatId, `${imagePath}\0${caption ?? ''}`, () => this.bot.api.sendPhoto(Number(chatId), new InputFile(imagePath), { caption }).then(() => { })), true);
908
- }
909
- async sendOutboundOnce(idempotencyKey, kind, chatId, payload, send) {
910
- if (!idempotencyKey) {
911
- await send();
912
- return;
913
517
  }
914
- const ledgerKey = this.outboundLedgerKey(idempotencyKey, kind);
915
- const { entry: existing } = this.messageLedger.claim(ledgerKey, {
916
- deliveryTarget: `telegram:${chatId}`,
917
- payloadIdentity: (0, node_crypto_1.createHash)('sha256').update(payload).digest('hex'),
918
- });
919
- if (existing.state === 'delivered')
920
- return;
921
- await send();
922
- this.messageLedger.markDelivered(ledgerKey);
518
+ this.messageLedger.markDelivered(key);
519
+ this.log(`telegram outbound delivered idempotency_key=${JSON.stringify(entry.idempotencyKey)} message_ids=${JSON.stringify(this.messageLedger.get(key).messageIds ?? [])}`);
923
520
  }
924
- async recoverPendingInboundDeliveries() {
925
- for (const snapshot of this.messageLedger.listUndelivered()) {
926
- if (snapshot.key.startsWith('outbound:'))
927
- continue;
928
- const separator = snapshot.key.lastIndexOf(':');
929
- if (separator <= 0)
930
- continue;
931
- const chatId = snapshot.key.slice(0, separator);
932
- await this.runInChatQueue(chatId, async () => {
933
- const entry = this.messageLedger.get(snapshot.key);
934
- // The live presenter owns ready as well as processing until it settles.
935
- // Recovery must not jump ahead while that presenter drains a streaming edit.
936
- if (this.activeInboundMessages.has(snapshot.key))
937
- return;
938
- if (!entry || entry.state === 'delivered')
939
- return;
940
- if (entry.state === 'processing' && this.messageLedger.isOwnedByCurrentProcess(entry)) {
941
- return;
942
- }
943
- const response = entry.state === 'ready' && entry.response !== undefined
944
- ? entry.response
945
- : 'The previous processing attempt was interrupted. It was not rerun because its ' +
946
- 'external side effects could not be proven safe to repeat. Please send a new message ' +
947
- 'if you want to retry it.';
948
- if (entry.state !== 'ready')
949
- this.messageLedger.markReady(entry.key, response, 'html-v1');
950
- if (entry.deliveryUncertain) {
951
- console.warn(`[Telegram] Resuming inbound delivery ${entry.key} from uncertain chunk ` +
952
- `${entry.nextChunkIndex ?? 0}; that chunk may appear twice`);
953
- }
954
- const presenter = this.createResponsePresenter(Number(chatId), entry.key, entry.nextChunkIndex ?? 0);
955
- await presenter.finalize(response);
956
- this.messageLedger.markDelivered(entry.key);
957
- });
958
- }
959
- }
960
- createResponsePresenter(chatId, messageKey, resumeFromChunk = 0, onInitialSend) {
961
- const api = this.bot.api;
962
- return new telegram_response_presenter_js_1.TelegramResponsePresenter({
963
- send: async (content) => {
964
- const sent = await this.runInChatQueue(String(chatId), () => sendFormattedMessage(api, chatId, content), true);
965
- onInitialSend?.(sent.message_id);
966
- return String(sent.message_id);
967
- },
968
- edit: async (handle, content) => {
969
- await this.runInChatQueue(String(chatId), () => editFormattedMessage(api, chatId, Number(handle), content), true);
970
- },
971
- delete: async (handle) => {
972
- await this.runInChatQueue(String(chatId), () => api.deleteMessage(chatId, Number(handle)), true);
973
- },
974
- }, {
975
- resumeFromChunk,
976
- chunkFormat: this.messageLedger.get(messageKey)?.state === 'ready'
977
- ? (this.messageLedger.get(messageKey)?.chunkFormat ?? 'plain-v1')
978
- : 'html-v1',
979
- withDelivery: (send) => this.runInChatQueue(String(chatId), send, true),
980
- onChunkProgress: (nextIndex, uncertain) => {
981
- if (this.messageLedger.get(messageKey)?.state === 'ready') {
982
- this.messageLedger.markDeliveryProgress(messageKey, nextIndex, uncertain);
983
- }
984
- },
521
+ async runInChatQueue(chatId, work, allowReentrant = false) {
522
+ const active = this.activeChat.getStore();
523
+ if (allowReentrant && active?.active && active.chatId === chatId)
524
+ return work();
525
+ const previous = this.chatTails.get(chatId);
526
+ let release;
527
+ const gate = new Promise((resolve) => {
528
+ release = resolve;
985
529
  });
986
- }
987
- outboundLedgerKey(idempotencyKey, kind) {
988
- const digest = (0, node_crypto_1.createHash)('sha256').update(`${kind}\0${idempotencyKey}`).digest('hex');
989
- return `outbound:${digest}`;
990
- }
991
- /** Read the existing durable proof for one exact outbound delivery occurrence. */
992
- readOutboundDeliveryReceipt(deliveryId, variant) {
993
- const entry = this.messageLedger.get(this.outboundLedgerKey(deliveryId, variant));
994
- if (entry?.state !== 'delivered' ||
995
- typeof entry.payloadIdentity !== 'string' ||
996
- !/^[a-f0-9]{64}$/.test(entry.payloadIdentity)) {
997
- return null;
998
- }
999
- return {
1000
- deliveryId,
1001
- variant,
1002
- state: 'delivered',
1003
- payloadIdentity: entry.payloadIdentity,
1004
- confirmedAt: entry.updatedAt,
1005
- };
1006
- }
1007
- async sendSticker(chatId, emotion, idempotencyKey) {
1008
- if (!this.bot)
1009
- throw new Error('Telegram gateway not connected');
1010
- return this.runInChatQueue(String(chatId), () => this.sendStickerNow(chatId, emotion, idempotencyKey));
1011
- }
1012
- async sendStickerFromActiveTurn(chatId, emotion, idempotencyKey) {
1013
- if (!this.bot)
1014
- throw new Error('Telegram gateway not connected');
1015
- return this.runInChatQueue(String(chatId), () => this.sendStickerNow(chatId, emotion, idempotencyKey), true);
1016
- }
1017
- async sendStickerNow(chatId, emotion, idempotencyKey) {
1018
- const bot = this.bot;
1019
- if (!bot)
1020
- throw new Error('Telegram gateway not connected');
1021
- await this.loadStickerSet();
1022
- const candidates = EMOTION_EMOJI[emotion] ?? EMOTION_EMOJI.happy;
1023
- const numChatId = typeof chatId === 'string' ? Number(chatId) : chatId;
1024
- for (const emoji of candidates) {
1025
- const fileId = this.stickerCache.get(emoji);
1026
- if (fileId) {
1027
- await this.sendOutboundOnce(idempotencyKey, 'sticker', String(chatId), `${emotion}\0${fileId}`, () => bot.api.sendSticker(numChatId, fileId).then(() => { }));
1028
- return true;
1029
- }
1030
- }
1031
- await this.sendOutboundOnce(idempotencyKey, 'sticker', String(chatId), `${emotion}\0${candidates[0]}`, () => bot.api.sendMessage(numChatId, candidates[0]).then(() => { }));
1032
- return false;
1033
- }
1034
- getLastError() {
1035
- return this.lastError;
1036
- }
1037
- getLastMessageAt() {
1038
- return this.lastMessageAt;
1039
- }
1040
- async loadStickerSet() {
1041
- if (this.stickerSetLoaded || !this.bot)
1042
- return;
530
+ const current = (previous ?? Promise.resolve()).catch(() => { }).then(() => gate);
531
+ this.chatTails.set(chatId, current);
1043
532
  try {
1044
- const set = await this.bot.api.getStickerSet(DEFAULT_STICKER_SET);
1045
- for (const sticker of set.stickers) {
1046
- if (sticker.emoji && !this.stickerCache.has(sticker.emoji)) {
1047
- this.stickerCache.set(sticker.emoji, sticker.file_id);
1048
- }
1049
- }
1050
- this.stickerSetLoaded = true;
533
+ if (previous)
534
+ await previous.catch(() => { });
535
+ return await this.activeChat.run({ chatId, active: true }, work);
1051
536
  }
1052
- catch {
1053
- this.stickerSetLoaded = true;
537
+ finally {
538
+ release();
539
+ if (this.chatTails.get(chatId) === current)
540
+ this.chatTails.delete(chatId);
1054
541
  }
1055
542
  }
1056
543
  }