@0xmaxma/claude-gateway 1.8.14 → 2.0.1

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 (586) hide show
  1. package/README.md +28 -1613
  2. package/config.template.json +7 -1
  3. package/dist/agent/runner.d.ts +419 -0
  4. package/dist/agent/runner.d.ts.map +1 -1
  5. package/dist/agent/runner.js +736 -24
  6. package/dist/agent/runner.js.map +1 -1
  7. package/dist/agent/skill-learning/index.d.ts +6 -4
  8. package/dist/agent/skill-learning/index.d.ts.map +1 -1
  9. package/dist/agent/skill-learning/index.js +3 -3
  10. package/dist/agent/skill-learning/index.js.map +1 -1
  11. package/dist/agent/skill-learning/notifier.d.ts +3 -4
  12. package/dist/agent/skill-learning/notifier.d.ts.map +1 -1
  13. package/dist/agent/skill-learning/notifier.js +15 -13
  14. package/dist/agent/skill-learning/notifier.js.map +1 -1
  15. package/dist/agent/skill-learning/reviewer.d.ts.map +1 -1
  16. package/dist/agent/skill-learning/reviewer.js +3 -1
  17. package/dist/agent/skill-learning/reviewer.js.map +1 -1
  18. package/dist/api/connectors-router.d.ts.map +1 -1
  19. package/dist/api/connectors-router.js +110 -4
  20. package/dist/api/connectors-router.js.map +1 -1
  21. package/dist/api/gateway-router.d.ts +1 -0
  22. package/dist/api/gateway-router.d.ts.map +1 -1
  23. package/dist/api/gateway-router.js +13 -1
  24. package/dist/api/gateway-router.js.map +1 -1
  25. package/dist/api/line-webhook-router.d.ts +2 -2
  26. package/dist/api/line-webhook-router.d.ts.map +1 -1
  27. package/dist/api/line-webhook-router.js +264 -230
  28. package/dist/api/line-webhook-router.js.map +1 -1
  29. package/dist/api/router.d.ts.map +1 -1
  30. package/dist/api/router.js +162 -10
  31. package/dist/api/router.js.map +1 -1
  32. package/dist/api/share-router.d.ts.map +1 -1
  33. package/dist/api/share-router.js +29 -10
  34. package/dist/api/share-router.js.map +1 -1
  35. package/dist/api/slack-client.d.ts +2 -0
  36. package/dist/api/slack-client.d.ts.map +1 -1
  37. package/dist/api/slack-client.js +6 -2
  38. package/dist/api/slack-client.js.map +1 -1
  39. package/dist/api/slack-webhook-router.d.ts +3 -0
  40. package/dist/api/slack-webhook-router.d.ts.map +1 -1
  41. package/dist/api/slack-webhook-router.js +226 -131
  42. package/dist/api/slack-webhook-router.js.map +1 -1
  43. package/dist/api/voice-router.d.ts +21 -0
  44. package/dist/api/voice-router.d.ts.map +1 -0
  45. package/dist/api/voice-router.js +372 -0
  46. package/dist/api/voice-router.js.map +1 -0
  47. package/dist/api/voice-settings-router.d.ts +5 -0
  48. package/dist/api/voice-settings-router.d.ts.map +1 -0
  49. package/dist/api/voice-settings-router.js +318 -0
  50. package/dist/api/voice-settings-router.js.map +1 -0
  51. package/dist/apps/agent-container-migration.d.ts +11 -0
  52. package/dist/apps/agent-container-migration.d.ts.map +1 -0
  53. package/dist/apps/agent-container-migration.js +85 -0
  54. package/dist/apps/agent-container-migration.js.map +1 -0
  55. package/dist/apps/installer.d.ts +1 -1
  56. package/dist/apps/installer.d.ts.map +1 -1
  57. package/dist/apps/installer.js +2 -1
  58. package/dist/apps/installer.js.map +1 -1
  59. package/dist/cli/commands/tasks.d.ts +5 -0
  60. package/dist/cli/commands/tasks.d.ts.map +1 -0
  61. package/dist/cli/commands/tasks.js +92 -0
  62. package/dist/cli/commands/tasks.js.map +1 -0
  63. package/dist/cli/http-client.d.ts +2 -0
  64. package/dist/cli/http-client.d.ts.map +1 -1
  65. package/dist/cli/http-client.js +8 -3
  66. package/dist/cli/http-client.js.map +1 -1
  67. package/dist/cli/index.d.ts.map +1 -1
  68. package/dist/cli/index.js +5 -1
  69. package/dist/cli/index.js.map +1 -1
  70. package/dist/config/config-write-lock.d.ts +2 -0
  71. package/dist/config/config-write-lock.d.ts.map +1 -1
  72. package/dist/config/config-write-lock.js +5 -0
  73. package/dist/config/config-write-lock.js.map +1 -1
  74. package/dist/config/loader.d.ts.map +1 -1
  75. package/dist/config/loader.js +87 -2
  76. package/dist/config/loader.js.map +1 -1
  77. package/dist/config/migrator.d.ts.map +1 -1
  78. package/dist/config/migrator.js +12 -1
  79. package/dist/config/migrator.js.map +1 -1
  80. package/dist/config/watcher.d.ts.map +1 -1
  81. package/dist/config/watcher.js +6 -0
  82. package/dist/config/watcher.js.map +1 -1
  83. package/dist/connectors/resolve.d.ts.map +1 -1
  84. package/dist/connectors/resolve.js +3 -1
  85. package/dist/connectors/resolve.js.map +1 -1
  86. package/dist/connectors/types.d.ts +8 -0
  87. package/dist/connectors/types.d.ts.map +1 -1
  88. package/dist/cron/manager.d.ts.map +1 -1
  89. package/dist/cron/manager.js +21 -2
  90. package/dist/cron/manager.js.map +1 -1
  91. package/dist/discord/receiver.d.ts +2 -1
  92. package/dist/discord/receiver.d.ts.map +1 -1
  93. package/dist/discord/receiver.js +5 -1
  94. package/dist/discord/receiver.js.map +1 -1
  95. package/dist/history/db.d.ts +3 -0
  96. package/dist/history/db.d.ts.map +1 -1
  97. package/dist/history/db.js +21 -1
  98. package/dist/history/db.js.map +1 -1
  99. package/dist/history/types.d.ts +2 -0
  100. package/dist/history/types.d.ts.map +1 -1
  101. package/dist/index.js +48 -9
  102. package/dist/index.js.map +1 -1
  103. package/dist/orchestration/bounded-queue.d.ts +15 -0
  104. package/dist/orchestration/bounded-queue.d.ts.map +1 -0
  105. package/dist/orchestration/bounded-queue.js +58 -0
  106. package/dist/orchestration/bounded-queue.js.map +1 -0
  107. package/dist/orchestration/bridge.d.ts +55 -0
  108. package/dist/orchestration/bridge.d.ts.map +1 -0
  109. package/dist/orchestration/bridge.js +234 -0
  110. package/dist/orchestration/bridge.js.map +1 -0
  111. package/dist/orchestration/browser-routing.d.ts +7 -0
  112. package/dist/orchestration/browser-routing.d.ts.map +1 -0
  113. package/dist/orchestration/browser-routing.js +22 -0
  114. package/dist/orchestration/browser-routing.js.map +1 -0
  115. package/dist/orchestration/capabilities.d.ts +49 -0
  116. package/dist/orchestration/capabilities.d.ts.map +1 -0
  117. package/dist/orchestration/capabilities.js +417 -0
  118. package/dist/orchestration/capabilities.js.map +1 -0
  119. package/dist/orchestration/capacity.d.ts +14 -0
  120. package/dist/orchestration/capacity.d.ts.map +1 -0
  121. package/dist/orchestration/capacity.js +52 -0
  122. package/dist/orchestration/capacity.js.map +1 -0
  123. package/dist/orchestration/channel-activity.d.ts +21 -0
  124. package/dist/orchestration/channel-activity.d.ts.map +1 -0
  125. package/dist/orchestration/channel-activity.js +72 -0
  126. package/dist/orchestration/channel-activity.js.map +1 -0
  127. package/dist/orchestration/channel-controls.d.ts +32 -0
  128. package/dist/orchestration/channel-controls.d.ts.map +1 -0
  129. package/dist/orchestration/channel-controls.js +105 -0
  130. package/dist/orchestration/channel-controls.js.map +1 -0
  131. package/dist/orchestration/channel-input-media.d.ts +11 -0
  132. package/dist/orchestration/channel-input-media.d.ts.map +1 -0
  133. package/dist/orchestration/channel-input-media.js +54 -0
  134. package/dist/orchestration/channel-input-media.js.map +1 -0
  135. package/dist/orchestration/channel-media.d.ts +4 -0
  136. package/dist/orchestration/channel-media.d.ts.map +1 -0
  137. package/dist/orchestration/channel-media.js +70 -0
  138. package/dist/orchestration/channel-media.js.map +1 -0
  139. package/dist/orchestration/channel-speech.d.ts +7 -0
  140. package/dist/orchestration/channel-speech.d.ts.map +1 -0
  141. package/dist/orchestration/channel-speech.js +65 -0
  142. package/dist/orchestration/channel-speech.js.map +1 -0
  143. package/dist/orchestration/cli-skills.d.ts +12 -0
  144. package/dist/orchestration/cli-skills.d.ts.map +1 -0
  145. package/dist/orchestration/cli-skills.js +132 -0
  146. package/dist/orchestration/cli-skills.js.map +1 -0
  147. package/dist/orchestration/config.d.ts +260 -0
  148. package/dist/orchestration/config.d.ts.map +1 -0
  149. package/dist/orchestration/config.js +110 -0
  150. package/dist/orchestration/config.js.map +1 -0
  151. package/dist/orchestration/container.d.ts +21 -0
  152. package/dist/orchestration/container.d.ts.map +1 -0
  153. package/dist/orchestration/container.js +195 -0
  154. package/dist/orchestration/container.js.map +1 -0
  155. package/dist/orchestration/control-delivery.d.ts +5 -0
  156. package/dist/orchestration/control-delivery.d.ts.map +1 -0
  157. package/dist/orchestration/control-delivery.js +50 -0
  158. package/dist/orchestration/control-delivery.js.map +1 -0
  159. package/dist/orchestration/conversation-intake.d.ts +32 -0
  160. package/dist/orchestration/conversation-intake.d.ts.map +1 -0
  161. package/dist/orchestration/conversation-intake.js +92 -0
  162. package/dist/orchestration/conversation-intake.js.map +1 -0
  163. package/dist/orchestration/decisions.d.ts +27 -0
  164. package/dist/orchestration/decisions.d.ts.map +1 -0
  165. package/dist/orchestration/decisions.js +151 -0
  166. package/dist/orchestration/decisions.js.map +1 -0
  167. package/dist/orchestration/delivery.d.ts +34 -0
  168. package/dist/orchestration/delivery.d.ts.map +1 -0
  169. package/dist/orchestration/delivery.js +235 -0
  170. package/dist/orchestration/delivery.js.map +1 -0
  171. package/dist/orchestration/display-stream.d.ts +4 -0
  172. package/dist/orchestration/display-stream.d.ts.map +1 -0
  173. package/dist/orchestration/display-stream.js +77 -0
  174. package/dist/orchestration/display-stream.js.map +1 -0
  175. package/dist/orchestration/events.d.ts +30 -0
  176. package/dist/orchestration/events.d.ts.map +1 -0
  177. package/dist/orchestration/events.js +65 -0
  178. package/dist/orchestration/events.js.map +1 -0
  179. package/dist/orchestration/execution-observation.d.ts +38 -0
  180. package/dist/orchestration/execution-observation.d.ts.map +1 -0
  181. package/dist/orchestration/execution-observation.js +25 -0
  182. package/dist/orchestration/execution-observation.js.map +1 -0
  183. package/dist/orchestration/file-delivery.d.ts +16 -0
  184. package/dist/orchestration/file-delivery.d.ts.map +1 -0
  185. package/dist/orchestration/file-delivery.js +139 -0
  186. package/dist/orchestration/file-delivery.js.map +1 -0
  187. package/dist/orchestration/gateway-config.d.ts +17 -0
  188. package/dist/orchestration/gateway-config.d.ts.map +1 -0
  189. package/dist/orchestration/gateway-config.js +128 -0
  190. package/dist/orchestration/gateway-config.js.map +1 -0
  191. package/dist/orchestration/history.d.ts +13 -0
  192. package/dist/orchestration/history.d.ts.map +1 -0
  193. package/dist/orchestration/history.js +48 -0
  194. package/dist/orchestration/history.js.map +1 -0
  195. package/dist/orchestration/identity.d.ts +6 -0
  196. package/dist/orchestration/identity.d.ts.map +1 -0
  197. package/dist/orchestration/identity.js +13 -0
  198. package/dist/orchestration/identity.js.map +1 -0
  199. package/dist/orchestration/inference-errors.d.ts +3 -0
  200. package/dist/orchestration/inference-errors.d.ts.map +1 -0
  201. package/dist/orchestration/inference-errors.js +16 -0
  202. package/dist/orchestration/inference-errors.js.map +1 -0
  203. package/dist/orchestration/input-images.d.ts +12 -0
  204. package/dist/orchestration/input-images.d.ts.map +1 -0
  205. package/dist/orchestration/input-images.js +66 -0
  206. package/dist/orchestration/input-images.js.map +1 -0
  207. package/dist/orchestration/instance-lock.d.ts +5 -0
  208. package/dist/orchestration/instance-lock.d.ts.map +1 -0
  209. package/dist/orchestration/instance-lock.js +33 -0
  210. package/dist/orchestration/instance-lock.js.map +1 -0
  211. package/dist/orchestration/line-loading.d.ts +21 -0
  212. package/dist/orchestration/line-loading.d.ts.map +1 -0
  213. package/dist/orchestration/line-loading.js +89 -0
  214. package/dist/orchestration/line-loading.js.map +1 -0
  215. package/dist/orchestration/media.d.ts +3 -0
  216. package/dist/orchestration/media.d.ts.map +1 -0
  217. package/dist/orchestration/media.js +46 -0
  218. package/dist/orchestration/media.js.map +1 -0
  219. package/dist/orchestration/migrations/schema.d.ts +3 -0
  220. package/dist/orchestration/migrations/schema.d.ts.map +1 -0
  221. package/dist/orchestration/migrations/schema.js +80 -0
  222. package/dist/orchestration/migrations/schema.js.map +1 -0
  223. package/dist/orchestration/notification-mailbox.d.ts +5 -0
  224. package/dist/orchestration/notification-mailbox.d.ts.map +1 -0
  225. package/dist/orchestration/notification-mailbox.js +29 -0
  226. package/dist/orchestration/notification-mailbox.js.map +1 -0
  227. package/dist/orchestration/process-activity.d.ts +23 -0
  228. package/dist/orchestration/process-activity.d.ts.map +1 -0
  229. package/dist/orchestration/process-activity.js +95 -0
  230. package/dist/orchestration/process-activity.js.map +1 -0
  231. package/dist/orchestration/process-supervisor.d.ts +15 -0
  232. package/dist/orchestration/process-supervisor.d.ts.map +1 -0
  233. package/dist/orchestration/process-supervisor.js +92 -0
  234. package/dist/orchestration/process-supervisor.js.map +1 -0
  235. package/dist/orchestration/process-turn.d.ts +35 -0
  236. package/dist/orchestration/process-turn.d.ts.map +1 -0
  237. package/dist/orchestration/process-turn.js +246 -0
  238. package/dist/orchestration/process-turn.js.map +1 -0
  239. package/dist/orchestration/progress-review.d.ts +28 -0
  240. package/dist/orchestration/progress-review.d.ts.map +1 -0
  241. package/dist/orchestration/progress-review.js +48 -0
  242. package/dist/orchestration/progress-review.js.map +1 -0
  243. package/dist/orchestration/recovery.d.ts +8 -0
  244. package/dist/orchestration/recovery.d.ts.map +1 -0
  245. package/dist/orchestration/recovery.js +35 -0
  246. package/dist/orchestration/recovery.js.map +1 -0
  247. package/dist/orchestration/reply-context.d.ts +7 -0
  248. package/dist/orchestration/reply-context.d.ts.map +1 -0
  249. package/dist/orchestration/reply-context.js +54 -0
  250. package/dist/orchestration/reply-context.js.map +1 -0
  251. package/dist/orchestration/runtime.d.ts +237 -0
  252. package/dist/orchestration/runtime.d.ts.map +1 -0
  253. package/dist/orchestration/runtime.js +1031 -0
  254. package/dist/orchestration/runtime.js.map +1 -0
  255. package/dist/orchestration/skills.d.ts +17 -0
  256. package/dist/orchestration/skills.d.ts.map +1 -0
  257. package/dist/orchestration/skills.js +32 -0
  258. package/dist/orchestration/skills.js.map +1 -0
  259. package/dist/orchestration/source-policy.d.ts +6 -0
  260. package/dist/orchestration/source-policy.d.ts.map +1 -0
  261. package/dist/orchestration/source-policy.js +16 -0
  262. package/dist/orchestration/source-policy.js.map +1 -0
  263. package/dist/orchestration/speech.d.ts +24 -0
  264. package/dist/orchestration/speech.d.ts.map +1 -0
  265. package/dist/orchestration/speech.js +61 -0
  266. package/dist/orchestration/speech.js.map +1 -0
  267. package/dist/orchestration/stop-controls.d.ts +30 -0
  268. package/dist/orchestration/stop-controls.d.ts.map +1 -0
  269. package/dist/orchestration/stop-controls.js +79 -0
  270. package/dist/orchestration/stop-controls.js.map +1 -0
  271. package/dist/orchestration/store.d.ts +92 -0
  272. package/dist/orchestration/store.d.ts.map +1 -0
  273. package/dist/orchestration/store.js +326 -0
  274. package/dist/orchestration/store.js.map +1 -0
  275. package/dist/orchestration/task-controls.d.ts +172 -0
  276. package/dist/orchestration/task-controls.d.ts.map +1 -0
  277. package/dist/orchestration/task-controls.js +59 -0
  278. package/dist/orchestration/task-controls.js.map +1 -0
  279. package/dist/orchestration/task-files.d.ts +29 -0
  280. package/dist/orchestration/task-files.d.ts.map +1 -0
  281. package/dist/orchestration/task-files.js +200 -0
  282. package/dist/orchestration/task-files.js.map +1 -0
  283. package/dist/orchestration/task-questions.d.ts +26 -0
  284. package/dist/orchestration/task-questions.d.ts.map +1 -0
  285. package/dist/orchestration/task-questions.js +160 -0
  286. package/dist/orchestration/task-questions.js.map +1 -0
  287. package/dist/orchestration/task-report.d.ts +7 -0
  288. package/dist/orchestration/task-report.d.ts.map +1 -0
  289. package/dist/orchestration/task-report.js +33 -0
  290. package/dist/orchestration/task-report.js.map +1 -0
  291. package/dist/orchestration/tasks/checkpoint-hook.d.ts +19 -0
  292. package/dist/orchestration/tasks/checkpoint-hook.d.ts.map +1 -0
  293. package/dist/orchestration/tasks/checkpoint-hook.js +49 -0
  294. package/dist/orchestration/tasks/checkpoint-hook.js.map +1 -0
  295. package/dist/orchestration/tasks/cleanup.d.ts +18 -0
  296. package/dist/orchestration/tasks/cleanup.d.ts.map +1 -0
  297. package/dist/orchestration/tasks/cleanup.js +113 -0
  298. package/dist/orchestration/tasks/cleanup.js.map +1 -0
  299. package/dist/orchestration/tasks/driver.d.ts +23 -0
  300. package/dist/orchestration/tasks/driver.d.ts.map +1 -0
  301. package/dist/orchestration/tasks/driver.js +209 -0
  302. package/dist/orchestration/tasks/driver.js.map +1 -0
  303. package/dist/orchestration/tasks/failure.d.ts +5 -0
  304. package/dist/orchestration/tasks/failure.d.ts.map +1 -0
  305. package/dist/orchestration/tasks/failure.js +17 -0
  306. package/dist/orchestration/tasks/failure.js.map +1 -0
  307. package/dist/orchestration/tasks/pool.d.ts +18 -0
  308. package/dist/orchestration/tasks/pool.d.ts.map +1 -0
  309. package/dist/orchestration/tasks/pool.js +73 -0
  310. package/dist/orchestration/tasks/pool.js.map +1 -0
  311. package/dist/orchestration/tasks/scheduler.d.ts +38 -0
  312. package/dist/orchestration/tasks/scheduler.d.ts.map +1 -0
  313. package/dist/orchestration/tasks/scheduler.js +160 -0
  314. package/dist/orchestration/tasks/scheduler.js.map +1 -0
  315. package/dist/orchestration/tasks/service.d.ts +114 -0
  316. package/dist/orchestration/tasks/service.d.ts.map +1 -0
  317. package/dist/orchestration/tasks/service.js +760 -0
  318. package/dist/orchestration/tasks/service.js.map +1 -0
  319. package/dist/orchestration/tasks/shared-workspace.d.ts +25 -0
  320. package/dist/orchestration/tasks/shared-workspace.d.ts.map +1 -0
  321. package/dist/orchestration/tasks/shared-workspace.js +162 -0
  322. package/dist/orchestration/tasks/shared-workspace.js.map +1 -0
  323. package/dist/orchestration/tasks/task-directive.d.ts +6 -0
  324. package/dist/orchestration/tasks/task-directive.d.ts.map +1 -0
  325. package/dist/orchestration/tasks/task-directive.js +41 -0
  326. package/dist/orchestration/tasks/task-directive.js.map +1 -0
  327. package/dist/orchestration/tasks/timing.d.ts +15 -0
  328. package/dist/orchestration/tasks/timing.d.ts.map +1 -0
  329. package/dist/orchestration/tasks/timing.js +48 -0
  330. package/dist/orchestration/tasks/timing.js.map +1 -0
  331. package/dist/orchestration/tasks/tool-repetition.d.ts +3 -0
  332. package/dist/orchestration/tasks/tool-repetition.d.ts.map +1 -0
  333. package/dist/orchestration/tasks/tool-repetition.js +30 -0
  334. package/dist/orchestration/tasks/tool-repetition.js.map +1 -0
  335. package/dist/orchestration/tasks/workspace.d.ts +24 -0
  336. package/dist/orchestration/tasks/workspace.d.ts.map +1 -0
  337. package/dist/orchestration/tasks/workspace.js +147 -0
  338. package/dist/orchestration/tasks/workspace.js.map +1 -0
  339. package/dist/orchestration/telegram-speech.d.ts +17 -0
  340. package/dist/orchestration/telegram-speech.d.ts.map +1 -0
  341. package/dist/orchestration/telegram-speech.js +55 -0
  342. package/dist/orchestration/telegram-speech.js.map +1 -0
  343. package/dist/orchestration/telegram-tool-status.d.ts +23 -0
  344. package/dist/orchestration/telegram-tool-status.d.ts.map +1 -0
  345. package/dist/orchestration/telegram-tool-status.js +207 -0
  346. package/dist/orchestration/telegram-tool-status.js.map +1 -0
  347. package/dist/orchestration/telegram-voices.d.ts +42 -0
  348. package/dist/orchestration/telegram-voices.d.ts.map +1 -0
  349. package/dist/orchestration/telegram-voices.js +70 -0
  350. package/dist/orchestration/telegram-voices.js.map +1 -0
  351. package/dist/orchestration/tool-activity.d.ts +10 -0
  352. package/dist/orchestration/tool-activity.d.ts.map +1 -0
  353. package/dist/orchestration/tool-activity.js +38 -0
  354. package/dist/orchestration/tool-activity.js.map +1 -0
  355. package/dist/orchestration/types.d.ts +177 -0
  356. package/dist/orchestration/types.d.ts.map +1 -0
  357. package/dist/orchestration/types.js +13 -0
  358. package/dist/orchestration/types.js.map +1 -0
  359. package/dist/orchestration/voice-reply-policy.d.ts +8 -0
  360. package/dist/orchestration/voice-reply-policy.d.ts.map +1 -0
  361. package/dist/orchestration/voice-reply-policy.js +46 -0
  362. package/dist/orchestration/voice-reply-policy.js.map +1 -0
  363. package/dist/orchestration/worker-shares.d.ts +8 -0
  364. package/dist/orchestration/worker-shares.d.ts.map +1 -0
  365. package/dist/orchestration/worker-shares.js +59 -0
  366. package/dist/orchestration/worker-shares.js.map +1 -0
  367. package/dist/orchestration/workflow.d.ts +121 -0
  368. package/dist/orchestration/workflow.d.ts.map +1 -0
  369. package/dist/orchestration/workflow.js +69 -0
  370. package/dist/orchestration/workflow.js.map +1 -0
  371. package/dist/session/input-image.d.ts +10 -0
  372. package/dist/session/input-image.d.ts.map +1 -0
  373. package/dist/session/input-image.js +3 -0
  374. package/dist/session/input-image.js.map +1 -0
  375. package/dist/session/process.d.ts +15 -3
  376. package/dist/session/process.d.ts.map +1 -1
  377. package/dist/session/process.js +143 -35
  378. package/dist/session/process.js.map +1 -1
  379. package/dist/session/runtime-profile.d.ts +36 -0
  380. package/dist/session/runtime-profile.d.ts.map +1 -0
  381. package/dist/session/runtime-profile.js +63 -0
  382. package/dist/session/runtime-profile.js.map +1 -0
  383. package/dist/session/store.d.ts.map +1 -1
  384. package/dist/session/store.js +23 -1
  385. package/dist/session/store.js.map +1 -1
  386. package/dist/share/share-store.d.ts +3 -1
  387. package/dist/share/share-store.d.ts.map +1 -1
  388. package/dist/share/share-store.js +13 -2
  389. package/dist/share/share-store.js.map +1 -1
  390. package/dist/shared/line-request-order.d.ts +2 -0
  391. package/dist/shared/line-request-order.d.ts.map +1 -0
  392. package/dist/shared/line-request-order.js +16 -0
  393. package/dist/shared/line-request-order.js.map +1 -0
  394. package/dist/shared/task-elapsed.d.ts +3 -0
  395. package/dist/shared/task-elapsed.d.ts.map +1 -0
  396. package/dist/shared/task-elapsed.js +12 -0
  397. package/dist/shared/task-elapsed.js.map +1 -0
  398. package/dist/shared/task-updated-time.d.ts +3 -0
  399. package/dist/shared/task-updated-time.d.ts.map +1 -0
  400. package/dist/shared/task-updated-time.js +15 -0
  401. package/dist/shared/task-updated-time.js.map +1 -0
  402. package/dist/skills/loader.d.ts +2 -0
  403. package/dist/skills/loader.d.ts.map +1 -1
  404. package/dist/skills/loader.js.map +1 -1
  405. package/dist/telegram/chunks.d.ts +19 -0
  406. package/dist/telegram/chunks.d.ts.map +1 -0
  407. package/dist/telegram/chunks.js +129 -0
  408. package/dist/telegram/chunks.js.map +1 -0
  409. package/dist/telegram/markdown.d.ts.map +1 -1
  410. package/dist/telegram/markdown.js +18 -3
  411. package/dist/telegram/markdown.js.map +1 -1
  412. package/dist/telegram/receiver.d.ts +2 -1
  413. package/dist/telegram/receiver.d.ts.map +1 -1
  414. package/dist/telegram/receiver.js +6 -1
  415. package/dist/telegram/receiver.js.map +1 -1
  416. package/dist/types.d.ts +14 -0
  417. package/dist/types.d.ts.map +1 -1
  418. package/dist/ui/web-ui.d.ts.map +1 -1
  419. package/dist/ui/web-ui.js +31 -5
  420. package/dist/ui/web-ui.js.map +1 -1
  421. package/dist/voice/diagnostics.d.ts +29 -0
  422. package/dist/voice/diagnostics.d.ts.map +1 -0
  423. package/dist/voice/diagnostics.js +37 -0
  424. package/dist/voice/diagnostics.js.map +1 -0
  425. package/dist/voice/errors.d.ts +19 -0
  426. package/dist/voice/errors.d.ts.map +1 -0
  427. package/dist/voice/errors.js +133 -0
  428. package/dist/voice/errors.js.map +1 -0
  429. package/dist/voice/line-audio.d.ts +4 -0
  430. package/dist/voice/line-audio.d.ts.map +1 -0
  431. package/dist/voice/line-audio.js +27 -0
  432. package/dist/voice/line-audio.js.map +1 -0
  433. package/dist/voice/managed-quota.d.ts +5 -0
  434. package/dist/voice/managed-quota.d.ts.map +1 -0
  435. package/dist/voice/managed-quota.js +35 -0
  436. package/dist/voice/managed-quota.js.map +1 -0
  437. package/dist/voice/mp3.d.ts +3 -0
  438. package/dist/voice/mp3.d.ts.map +1 -0
  439. package/dist/voice/mp3.js +30 -0
  440. package/dist/voice/mp3.js.map +1 -0
  441. package/dist/voice/notes.d.ts +9 -0
  442. package/dist/voice/notes.d.ts.map +1 -0
  443. package/dist/voice/notes.js +68 -0
  444. package/dist/voice/notes.js.map +1 -0
  445. package/dist/voice/playback.d.ts +22 -0
  446. package/dist/voice/playback.d.ts.map +1 -0
  447. package/dist/voice/playback.js +52 -0
  448. package/dist/voice/playback.js.map +1 -0
  449. package/dist/voice/preview.d.ts +6 -0
  450. package/dist/voice/preview.d.ts.map +1 -0
  451. package/dist/voice/preview.js +44 -0
  452. package/dist/voice/preview.js.map +1 -0
  453. package/dist/voice/protocol.d.ts +10 -0
  454. package/dist/voice/protocol.d.ts.map +1 -0
  455. package/dist/voice/protocol.js +30 -0
  456. package/dist/voice/protocol.js.map +1 -0
  457. package/dist/voice/providers/cartesia-tts.d.ts +26 -0
  458. package/dist/voice/providers/cartesia-tts.d.ts.map +1 -0
  459. package/dist/voice/providers/cartesia-tts.js +95 -0
  460. package/dist/voice/providers/cartesia-tts.js.map +1 -0
  461. package/dist/voice/providers/deepgram-stt.d.ts +20 -0
  462. package/dist/voice/providers/deepgram-stt.d.ts.map +1 -0
  463. package/dist/voice/providers/deepgram-stt.js +66 -0
  464. package/dist/voice/providers/deepgram-stt.js.map +1 -0
  465. package/dist/voice/providers/elevenlabs-stt.d.ts +20 -0
  466. package/dist/voice/providers/elevenlabs-stt.d.ts.map +1 -0
  467. package/dist/voice/providers/elevenlabs-stt.js +92 -0
  468. package/dist/voice/providers/elevenlabs-stt.js.map +1 -0
  469. package/dist/voice/providers/elevenlabs-tts.d.ts +26 -0
  470. package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -0
  471. package/dist/voice/providers/elevenlabs-tts.js +82 -0
  472. package/dist/voice/providers/elevenlabs-tts.js.map +1 -0
  473. package/dist/voice/providers/encoded-audio-tts.d.ts +21 -0
  474. package/dist/voice/providers/encoded-audio-tts.d.ts.map +1 -0
  475. package/dist/voice/providers/encoded-audio-tts.js +175 -0
  476. package/dist/voice/providers/encoded-audio-tts.js.map +1 -0
  477. package/dist/voice/providers/fake.d.ts +39 -0
  478. package/dist/voice/providers/fake.d.ts.map +1 -0
  479. package/dist/voice/providers/fake.js +41 -0
  480. package/dist/voice/providers/fake.js.map +1 -0
  481. package/dist/voice/providers/gemini-live-stt.d.ts +21 -0
  482. package/dist/voice/providers/gemini-live-stt.d.ts.map +1 -0
  483. package/dist/voice/providers/gemini-live-stt.js +158 -0
  484. package/dist/voice/providers/gemini-live-stt.js.map +1 -0
  485. package/dist/voice/providers/gemini.d.ts +60 -0
  486. package/dist/voice/providers/gemini.d.ts.map +1 -0
  487. package/dist/voice/providers/gemini.js +124 -0
  488. package/dist/voice/providers/gemini.js.map +1 -0
  489. package/dist/voice/providers/model-ref.d.ts +9 -0
  490. package/dist/voice/providers/model-ref.d.ts.map +1 -0
  491. package/dist/voice/providers/model-ref.js +31 -0
  492. package/dist/voice/providers/model-ref.js.map +1 -0
  493. package/dist/voice/providers/openrouter.d.ts +39 -0
  494. package/dist/voice/providers/openrouter.d.ts.map +1 -0
  495. package/dist/voice/providers/openrouter.js +154 -0
  496. package/dist/voice/providers/openrouter.js.map +1 -0
  497. package/dist/voice/providers/paxalabs-stt.d.ts +12 -0
  498. package/dist/voice/providers/paxalabs-stt.d.ts.map +1 -0
  499. package/dist/voice/providers/paxalabs-stt.js +41 -0
  500. package/dist/voice/providers/paxalabs-stt.js.map +1 -0
  501. package/dist/voice/providers/paxalabs-tts.d.ts +23 -0
  502. package/dist/voice/providers/paxalabs-tts.d.ts.map +1 -0
  503. package/dist/voice/providers/paxalabs-tts.js +80 -0
  504. package/dist/voice/providers/paxalabs-tts.js.map +1 -0
  505. package/dist/voice/providers/recorded-stt.d.ts +34 -0
  506. package/dist/voice/providers/recorded-stt.d.ts.map +1 -0
  507. package/dist/voice/providers/recorded-stt.js +59 -0
  508. package/dist/voice/providers/recorded-stt.js.map +1 -0
  509. package/dist/voice/providers/registry.d.ts +10 -0
  510. package/dist/voice/providers/registry.d.ts.map +1 -0
  511. package/dist/voice/providers/registry.js +77 -0
  512. package/dist/voice/providers/registry.js.map +1 -0
  513. package/dist/voice/providers/socket.d.ts +10 -0
  514. package/dist/voice/providers/socket.d.ts.map +1 -0
  515. package/dist/voice/providers/socket.js +91 -0
  516. package/dist/voice/providers/socket.js.map +1 -0
  517. package/dist/voice/providers/upstream.d.ts +9 -0
  518. package/dist/voice/providers/upstream.d.ts.map +1 -0
  519. package/dist/voice/providers/upstream.js +51 -0
  520. package/dist/voice/providers/upstream.js.map +1 -0
  521. package/dist/voice/providers/voice-catalog.d.ts +17 -0
  522. package/dist/voice/providers/voice-catalog.d.ts.map +1 -0
  523. package/dist/voice/providers/voice-catalog.js +167 -0
  524. package/dist/voice/providers/voice-catalog.js.map +1 -0
  525. package/dist/voice/queue.d.ts +2 -0
  526. package/dist/voice/queue.d.ts.map +1 -0
  527. package/dist/voice/queue.js +6 -0
  528. package/dist/voice/queue.js.map +1 -0
  529. package/dist/voice/session.d.ts +86 -0
  530. package/dist/voice/session.d.ts.map +1 -0
  531. package/dist/voice/session.js +464 -0
  532. package/dist/voice/session.js.map +1 -0
  533. package/dist/voice/turn-manager.d.ts +27 -0
  534. package/dist/voice/turn-manager.d.ts.map +1 -0
  535. package/dist/voice/turn-manager.js +75 -0
  536. package/dist/voice/turn-manager.js.map +1 -0
  537. package/dist/voice/types.d.ts +78 -0
  538. package/dist/voice/types.d.ts.map +1 -0
  539. package/dist/voice/types.js +18 -0
  540. package/dist/voice/types.js.map +1 -0
  541. package/dist/voice/wav.d.ts +2 -0
  542. package/dist/voice/wav.d.ts.map +1 -0
  543. package/dist/voice/wav.js +21 -0
  544. package/dist/voice/wav.js.map +1 -0
  545. package/dist/wechat/ilink-client.d.ts +13 -0
  546. package/dist/wechat/ilink-client.d.ts.map +1 -1
  547. package/dist/wechat/ilink-client.js +19 -0
  548. package/dist/wechat/ilink-client.js.map +1 -1
  549. package/dist/whatsapp/manager.d.ts.map +1 -1
  550. package/dist/whatsapp/manager.js +51 -1
  551. package/dist/whatsapp/manager.js.map +1 -1
  552. package/mcp/capability-catalog.ts +206 -0
  553. package/mcp/modules.ts +56 -0
  554. package/mcp/server.ts +18 -37
  555. package/mcp/tools/browser/module.ts +1 -1
  556. package/mcp/tools/browser/skills/open-browser/SKILL.md +5 -3
  557. package/mcp/tools/discord/commands.ts +17 -1
  558. package/mcp/tools/discord/inbound.ts +11 -0
  559. package/mcp/tools/discord/module.ts +42 -2
  560. package/mcp/tools/discord/receiver-server.ts +10 -0
  561. package/mcp/tools/discord/types.ts +4 -1
  562. package/mcp/tools/image/module.ts +3 -1
  563. package/mcp/tools/receiver-spool.test.ts +28 -0
  564. package/mcp/tools/receiver-spool.ts +56 -0
  565. package/mcp/tools/share-file/module.ts +9 -1
  566. package/mcp/tools/shared/share-client.ts +19 -0
  567. package/mcp/tools/tasks/module.ts +35 -0
  568. package/mcp/tools/telegram/media-group.ts +21 -0
  569. package/mcp/tools/telegram/receiver-server.ts +246 -11
  570. package/mcp/tools/telegram/selection-confirmation.ts +20 -0
  571. package/mcp/tools/telegram/task-browser.ts +117 -0
  572. package/mcp/tools/telegram/task-detail.ts +36 -0
  573. package/mcp/tools/telegram/task-elapsed.ts +1 -0
  574. package/mcp/tools/telegram/typing.ts +6 -116
  575. package/mcp/tools/video/module.ts +1 -1
  576. package/mcp/types.ts +5 -0
  577. package/package.json +2 -1
  578. package/resource/claude_gateway.jpeg +0 -0
  579. package/scripts/orchestration/bench-store.cjs +30 -0
  580. package/scripts/orchestration/inspect.cjs +16 -0
  581. package/scripts/orchestration/probe-profile.cjs +67 -0
  582. package/scripts/orchestration/reconcile.cjs +21 -0
  583. package/scripts/orchestration/smoke-elevenlabs.cjs +90 -0
  584. package/scripts/orchestration/smoke-media.cjs +70 -0
  585. package/scripts/orchestration/smoke-text.cjs +101 -0
  586. package/scripts/orchestration/smoke-vision.cjs +49 -0
@@ -0,0 +1,5 @@
1
+ import type { AgentConfig } from '../types';
2
+ import type { ControlMenu } from './channel-controls';
3
+ /** Provider adapters keep menus native; LINE replaces quick replies instead of editing old messages. */
4
+ export declare function sendControlMenu(agent: AgentConfig, channel: string, chatId: string, menu: ControlMenu, meta: Record<string, string>, request?: typeof fetch): Promise<void>;
5
+ //# sourceMappingURL=control-delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-delivery.d.ts","sourceRoot":"","sources":["../../src/orchestration/control-delivery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,wGAAwG;AACxG,wBAAsB,eAAe,CAAC,KAAK,EAAC,WAAW,EAAC,OAAO,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,IAAI,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,CAAC,MAAM,EAAC,MAAM,CAAC,EAAC,OAAO,GAAC,OAAO,KAAW,GAAE,OAAO,CAAC,IAAI,CAAC,CAwBzK"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendControlMenu = sendControlMenu;
4
+ const line_pure_1 = require("../agent/line-pure");
5
+ const line_request_order_1 = require("../shared/line-request-order");
6
+ /** Provider adapters keep menus native; LINE replaces quick replies instead of editing old messages. */
7
+ async function sendControlMenu(agent, channel, chatId, menu, meta, request = fetch) {
8
+ const call = async (url, body, headers, method = 'POST') => {
9
+ const send = () => request(url, { method, headers: { 'Content-Type': 'application/json', ...headers }, body: JSON.stringify(body), signal: AbortSignal.timeout(15000) });
10
+ const response = await (channel === 'line' ? (0, line_request_order_1.orderLineRequest)(agent.id, chatId, send) : send());
11
+ if (!response.ok)
12
+ throw Object.assign(Error('CONTROL_DELIVERY_FAILED'), { status: response.status });
13
+ const result = await response.json();
14
+ if (result.ok === false)
15
+ throw Error('CONTROL_DELIVERY_FAILED');
16
+ };
17
+ const buttons = menu.buttons;
18
+ if (channel === 'discord' && agent.discord?.botToken) {
19
+ const components = [];
20
+ for (let i = 0; i < buttons.length; i += 5)
21
+ components.push({ type: 1, components: buttons.slice(i, i + 5).map(b => ({ type: 2, style: 2, label: b.label.slice(0, 80), custom_id: b.data })) });
22
+ await call(`https://discord.com/api/v10/channels/${encodeURIComponent(chatId)}/messages${meta.control_message_id ? '/' + encodeURIComponent(meta.control_message_id) : ''}`, { content: menu.text.slice(0, 1950), components, allowed_mentions: { parse: [] } }, { Authorization: `Bot ${agent.discord.botToken}` }, meta.control_message_id ? 'PATCH' : 'POST');
23
+ }
24
+ else if (channel === 'slack' && agent.slack?.botToken) {
25
+ const blocks = [{ type: 'section', text: { type: 'plain_text', text: menu.text.slice(0, 2900) } }];
26
+ for (let i = 0; i < buttons.length; i += 5)
27
+ blocks.push({ type: 'actions', elements: buttons.slice(i, i + 5).map(b => ({ type: 'button', text: { type: 'plain_text', text: b.label.slice(0, 75) }, action_id: b.data, value: b.data })) });
28
+ await call(`https://slack.com/api/${meta.control_message_id ? 'chat.update' : 'chat.postMessage'}`, { channel: chatId, text: menu.text.slice(0, 2900), blocks, mrkdwn: false, ...(meta.control_message_id ? { ts: meta.control_message_id } : meta.thread_ts ? { thread_ts: meta.thread_ts } : {}) }, { Authorization: `Bearer ${agent.slack.botToken}` });
29
+ }
30
+ else if (channel === 'line' && agent.line?.channelAccessToken) {
31
+ if (buttons.length > 13)
32
+ throw Error('TOO_MANY_QUICK_REPLIES');
33
+ const message = { type: 'text', text: (0, line_pure_1.stripMarkdownPreservingUrls)(menu.text).slice(0, 4900), ...(buttons.length ? { quickReply: { items: buttons.map(b => ({ type: 'action', action: { type: 'postback', label: b.label.slice(0, 20), data: b.data } })) } } : {}) };
34
+ const headers = { Authorization: `Bearer ${agent.line.channelAccessToken}` };
35
+ if (meta.reply_token) {
36
+ try {
37
+ await call('https://api.line.me/v2/bot/message/reply', { replyToken: meta.reply_token, messages: [message] }, headers);
38
+ return;
39
+ }
40
+ catch (error) {
41
+ if (error.status !== 400)
42
+ throw error; /* expired reply tokens fall back to push */
43
+ }
44
+ }
45
+ await call('https://api.line.me/v2/bot/message/push', { to: chatId, messages: [message] }, headers);
46
+ }
47
+ else
48
+ throw Error('CONTROL_DELIVERY_NOT_CONFIGURED');
49
+ }
50
+ //# sourceMappingURL=control-delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-delivery.js","sourceRoot":"","sources":["../../src/orchestration/control-delivery.ts"],"names":[],"mappings":";;AAMA,0CAwBC;AA9BD,kDAAiE;AACjE,qEAAgE;AAIhE,wGAAwG;AACjG,KAAK,UAAU,eAAe,CA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0 +1,32 @@
1
+ import { OrchestrationStore } from './store';
2
+ import { CommandContext } from './types';
3
+ export interface IntakeChoice {
4
+ mode: 'ready' | 'wait' | 'update';
5
+ acknowledgement?: string;
6
+ preparation?: string;
7
+ clarification?: string;
8
+ task_id?: string;
9
+ }
10
+ export declare const INTAKE_OVERLAY = "Use conversation_intake only for executable work, incomplete materials, or amendments to an existing task. Greetings, introductions, casual conversation and questions you can answer directly need one normal answer: do not call conversation_intake or emit a separate acknowledgement for them.\nBefore any work mutation, use conversation_intake to decide how to handle the user's latest input together with pending materials and current tasks.\nready: the requested executable action and required material are complete. Supply a brief, specific acknowledgement addressed directly to the user, in their language and your existing persona. This text is immediately displayed and spoken to the user; it is not a private classification, instruction to yourself, or reasoning field. Do not add a waiting period.\nwait: the user is supplying materials without an action, promises an attachment that has not arrived, or says the instruction will follow. Inspect available images now. Preserve useful facts in preparation, clearly distinguishing observed contents from instructions. Supply one short clarification to ask only if no further input arrives for the configured intake wait interval. Do not speculate about unavailable link contents. End this turn without user-facing text; the gateway owns the waiting timer. Each new item will be read as it arrives.\nupdate: the user changes or supplements a specific existing task. Supply its exact task_id and acknowledge the change; use task_update/task_answer, not an independent duplicate. If the target is ambiguous, ask a precise question instead of guessing.\nNever create work merely to acknowledge material. A complete instruction arriving after materials is ready now; do not request another waiting interval. Preserve all unchanged requirements and refer to the original input/attachment IDs. Urgent stop or prohibition may call task_cancel before acknowledgement; do not delay fencing unsafe work for speech playback.";
11
+ /** Durable preparation is scoped by conversation AND authenticated principal.
12
+ * Source inputs remain canonical; this cache only supplements their full contents. */
13
+ export declare class ConversationIntake {
14
+ private store;
15
+ constructor(store: OrchestrationStore);
16
+ context(conversationId: string, principalId: string, bindingId?: string): any;
17
+ touch(inputId: string): void;
18
+ /** A direct answer can consume preparation from an older decision. Never
19
+ * discard newer material or another binding's pending context. */
20
+ consume(inputId: string): void;
21
+ choose(context: CommandContext, choice: IntakeChoice): {
22
+ acknowledgement: string;
23
+ clarification: string;
24
+ preparation: string;
25
+ inputIds: string[];
26
+ preparedInputSeq: string | number | null;
27
+ mode: "ready" | "wait" | "update";
28
+ task_id?: string;
29
+ };
30
+ due(waitMs?: number, now?: number): import("./store").Row[];
31
+ }
32
+ //# sourceMappingURL=conversation-intake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-intake.d.ts","sourceRoot":"","sources":["../../src/orchestration/conversation-intake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAe,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAsB,MAAM,SAAS,CAAC;AAE7D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,eAAO,MAAM,cAAc,o7DAKgV,CAAC;AAE5W;sFACsF;AACtF,qBAAa,kBAAkB;IACjB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,kBAAkB;IAQ7C,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAMvE,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5B;sEACkE;IAClE,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAM9B,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY;;;;;;cA7C9C,OAAO,GAAG,MAAM,GAAG,QAAQ;kBAIvB,MAAM;;IAqEhB,GAAG,CAAC,MAAM,SAAO,EAAE,GAAG,SAAa;CAUpC"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationIntake = exports.INTAKE_OVERLAY = void 0;
4
+ const store_1 = require("./store");
5
+ const types_1 = require("./types");
6
+ exports.INTAKE_OVERLAY = `Use conversation_intake only for executable work, incomplete materials, or amendments to an existing task. Greetings, introductions, casual conversation and questions you can answer directly need one normal answer: do not call conversation_intake or emit a separate acknowledgement for them.
7
+ Before any work mutation, use conversation_intake to decide how to handle the user's latest input together with pending materials and current tasks.
8
+ ready: the requested executable action and required material are complete. Supply a brief, specific acknowledgement addressed directly to the user, in their language and your existing persona. This text is immediately displayed and spoken to the user; it is not a private classification, instruction to yourself, or reasoning field. Do not add a waiting period.
9
+ wait: the user is supplying materials without an action, promises an attachment that has not arrived, or says the instruction will follow. Inspect available images now. Preserve useful facts in preparation, clearly distinguishing observed contents from instructions. Supply one short clarification to ask only if no further input arrives for the configured intake wait interval. Do not speculate about unavailable link contents. End this turn without user-facing text; the gateway owns the waiting timer. Each new item will be read as it arrives.
10
+ update: the user changes or supplements a specific existing task. Supply its exact task_id and acknowledge the change; use task_update/task_answer, not an independent duplicate. If the target is ambiguous, ask a precise question instead of guessing.
11
+ Never create work merely to acknowledge material. A complete instruction arriving after materials is ready now; do not request another waiting interval. Preserve all unchanged requirements and refer to the original input/attachment IDs. Urgent stop or prohibition may call task_cancel before acknowledgement; do not delay fencing unsafe work for speech playback.`;
12
+ /** Durable preparation is scoped by conversation AND authenticated principal.
13
+ * Source inputs remain canonical; this cache only supplements their full contents. */
14
+ class ConversationIntake {
15
+ constructor(store) {
16
+ this.store = store;
17
+ store.run(`CREATE TABLE IF NOT EXISTS conversation_intake (
18
+ conversation_id TEXT NOT NULL REFERENCES conversations(id), principal_id TEXT NOT NULL,
19
+ binding_id TEXT NOT NULL, mode TEXT NOT NULL, data_json TEXT NOT NULL,
20
+ latest_input_seq INTEGER NOT NULL, last_received_at INTEGER NOT NULL,
21
+ clarified_seq INTEGER, decision_id TEXT NOT NULL,
22
+ PRIMARY KEY(conversation_id,principal_id))`);
23
+ }
24
+ context(conversationId, principalId, bindingId) {
25
+ this.store.assertMember(conversationId, principalId);
26
+ const row = this.store.get('SELECT * FROM conversation_intake WHERE conversation_id=? AND principal_id=?', conversationId, principalId);
27
+ if (row && bindingId !== undefined && row.binding_id !== bindingId)
28
+ return undefined;
29
+ return row ? { ...JSON.parse(String(row.data_json)), mode: row.mode, latestInputSeq: row.latest_input_seq } : undefined;
30
+ }
31
+ touch(inputId) {
32
+ const input = this.store.get('SELECT * FROM conversation_inputs WHERE id=?', inputId);
33
+ if (!input || !input.store_user_message)
34
+ return;
35
+ this.store.run(`UPDATE conversation_intake SET latest_input_seq=?,last_received_at=?
36
+ WHERE conversation_id=? AND principal_id=? AND binding_id=? AND latest_input_seq<?`, input.input_seq, input.created_at, input.conversation_id, input.principal_id, input.binding_id, input.input_seq);
37
+ }
38
+ /** A direct answer can consume preparation from an older decision. Never
39
+ * discard newer material or another binding's pending context. */
40
+ consume(inputId) {
41
+ const input = this.store.get('SELECT * FROM conversation_inputs WHERE id=?', inputId);
42
+ if (!input)
43
+ throw new types_1.OrchestrationError('INPUT_NOT_FOUND');
44
+ this.store.run(`DELETE FROM conversation_intake WHERE conversation_id=? AND principal_id=?
45
+ AND binding_id=? AND latest_input_seq<=?`, input.conversation_id, input.principal_id, input.binding_id, input.input_seq);
46
+ }
47
+ choose(context, choice) {
48
+ this.store.assertMember(context.conversationId, context.principalId);
49
+ const decision = this.store.get("SELECT * FROM conversation_decisions WHERE id=? AND conversation_id=? AND epoch=? AND state='running'", context.decisionId, context.conversationId, context.epoch);
50
+ const input = this.store.get('SELECT * FROM conversation_inputs WHERE id=? AND conversation_id=? AND principal_id=?', context.inputId, context.conversationId, context.principalId);
51
+ if (!decision || !input)
52
+ throw new types_1.OrchestrationError('STALE_DECISION');
53
+ if (!['ready', 'wait', 'update'].includes(choice.mode))
54
+ throw new types_1.OrchestrationError('INVALID_INPUT');
55
+ const acknowledgement = choice.mode !== 'wait' ? (0, store_1.boundedText)(choice.acknowledgement ?? '', 600) : '';
56
+ const clarification = choice.mode === 'wait' ? (0, store_1.boundedText)(choice.clarification ?? '', 600) : '';
57
+ if ((choice.mode !== 'wait' && !acknowledgement.trim()) || (choice.mode === 'wait' && !clarification.trim()))
58
+ throw new types_1.OrchestrationError('INTAKE_MESSAGE_REQUIRED');
59
+ const preparation = choice.preparation?.trim() ? (0, store_1.boundedText)(choice.preparation, 12000) : '';
60
+ if (choice.mode === 'update') {
61
+ const task = choice.task_id && this.store.task(choice.task_id);
62
+ if (!task || task.conversationId !== context.conversationId || ['completed', 'failed', 'cancelled'].includes(task.state))
63
+ throw new types_1.OrchestrationError('INTAKE_TASK_UNAVAILABLE');
64
+ }
65
+ if (choice.mode === 'wait' && this.store.get("SELECT action_id FROM task_commands WHERE decision_id=? AND command_type IN ('spawn','update','answer')", context.decisionId))
66
+ throw new types_1.OrchestrationError('INTAKE_AFTER_EXECUTION');
67
+ const previousRow = this.store.get('SELECT binding_id,data_json FROM conversation_intake WHERE conversation_id=? AND principal_id=?', context.conversationId, context.principalId);
68
+ const previous = previousRow?.binding_id === input.binding_id ? JSON.parse(String(previousRow.data_json)) : undefined;
69
+ const inputIds = [...new Set([...(previous?.inputIds ?? []), context.inputId])];
70
+ if (inputIds.length > 100)
71
+ throw new types_1.OrchestrationError('INTAKE_TOO_MANY_INPUTS');
72
+ const data = { ...choice, acknowledgement, clarification, preparation, inputIds, preparedInputSeq: input.input_seq };
73
+ this.store.run(`INSERT INTO conversation_intake (conversation_id,principal_id,binding_id,mode,data_json,
74
+ latest_input_seq,last_received_at,clarified_seq,decision_id) VALUES(?,?,?,?,?,?,?,?,?)
75
+ ON CONFLICT(conversation_id,principal_id) DO UPDATE SET binding_id=excluded.binding_id,mode=excluded.mode,data_json=excluded.data_json,
76
+ latest_input_seq=MAX(conversation_intake.latest_input_seq,excluded.latest_input_seq),
77
+ last_received_at=MAX(conversation_intake.last_received_at,excluded.last_received_at),decision_id=excluded.decision_id`, context.conversationId, context.principalId, input.binding_id, choice.mode, JSON.stringify(data), input.input_seq, input.created_at, null, context.decisionId);
78
+ return data;
79
+ }
80
+ due(waitMs = 2000, now = Date.now()) {
81
+ return this.store.all(`SELECT p.* FROM conversation_intake p WHERE p.mode='wait' AND p.last_received_at+?<=?
82
+ AND (p.clarified_seq IS NULL OR p.clarified_seq<p.latest_input_seq)
83
+ AND json_extract(p.data_json,'$.preparedInputSeq')=p.latest_input_seq
84
+ AND EXISTS(SELECT 1 FROM conversation_members m WHERE m.conversation_id=p.conversation_id AND m.principal_id=p.principal_id)
85
+ AND EXISTS(SELECT 1 FROM conversations c WHERE c.id=p.conversation_id AND c.status='active')
86
+ AND EXISTS(SELECT 1 FROM conversation_decisions d WHERE d.id=p.decision_id AND d.state='completed')
87
+ AND NOT EXISTS(SELECT 1 FROM conversation_decisions d WHERE d.conversation_id=p.conversation_id AND d.state IN ('running','interrupting'))
88
+ AND NOT EXISTS(SELECT 1 FROM conversation_inputs i WHERE i.conversation_id=p.conversation_id AND i.status IN ('accepted','assigned'))`, waitMs, now);
89
+ }
90
+ }
91
+ exports.ConversationIntake = ConversationIntake;
92
+ //# sourceMappingURL=conversation-intake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-intake.js","sourceRoot":"","sources":["../../src/orchestration/conversation-intake.ts"],"names":[],"mappings":";;;AAAA,mCAA0D;AAC1D,mCAA6D;AAShD,QAAA,cAAc,GAAG;;;;;2WAK6U,CAAC;AAE5W;sFACsF;AACtF,MAAa,kBAAkB;IAC7B,YAAoB,KAAyB;QAAzB,UAAK,GAAL,KAAK,CAAoB;QAC3C,KAAK,CAAC,GAAG,CAAC;;;;;iDAKmC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,CAAC,cAAsB,EAAE,WAAmB,EAAE,SAAkB;QACrE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QACrD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,8EAA8E,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;QACxI,IAAI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,GAAG,EAAE,GAAG,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QACrH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;;;;4HAIyG,EACxH,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC/J,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;;;;;;;4IAOkH,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACzJ,CAAC;CACF;AApED,gDAoEC"}
@@ -0,0 +1,27 @@
1
+ import { OrchestrationStore } from './store';
2
+ export interface DecisionReceipt {
3
+ decisionId: string;
4
+ epoch: number;
5
+ inputIds: string[];
6
+ requestId?: string;
7
+ responseId?: string;
8
+ }
9
+ export declare class DecisionService {
10
+ readonly store: OrchestrationStore;
11
+ private readonly deliver?;
12
+ constructor(store: OrchestrationStore, deliver?: ((responseId: string, bindingId: string, text: string) => void) | undefined);
13
+ /** Deterministic system notice: no inference, input consumption, or epoch change. */
14
+ notice(conversationId: string, text: string, deliver: boolean, inputId?: string): string;
15
+ begin(conversationId: string, principalId: string, inputIds: string[], requestId?: string): DecisionReceipt;
16
+ /** Independent durable receipt: task execution still belongs to the original
17
+ * running decision. This completed notice never consumes result notifications. */
18
+ acknowledge(receipt: DecisionReceipt, text: string, spoken?: string, allowCompleted?: boolean): string;
19
+ /** Explicit stop controls acknowledge cancellation themselves; retain history without redelivering. */
20
+ finish(receipt: DecisionReceipt, text: string, state?: 'completed' | 'interrupted' | 'failed', spoken?: string, deliver?: boolean): string;
21
+ /** Invalidate commands before asking the driver to stop. Caller must wait for
22
+ * its true terminal/exit acknowledgment before releaseInterrupted. */
23
+ interrupt(receipt: DecisionReceipt): void;
24
+ releaseInterrupted(receipt: DecisionReceipt, explicitStop: boolean): void;
25
+ private historyOperation;
26
+ }
27
+ //# sourceMappingURL=decisions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decisions.d.ts","sourceRoot":"","sources":["../../src/orchestration/decisions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAG7C,MAAM,WAAW,eAAe;IAAG,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAAE;AACpI,qBAAa,eAAe;IACd,QAAQ,CAAC,KAAK,EAAE,kBAAkB;IAAE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAApD,KAAK,EAAE,kBAAkB,EAAmB,OAAO,CAAC,GAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,aAAA;IACxI,qFAAqF;IACrF,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAgBxF,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,eAAe;IAwB3G;sFACkF;IAClF,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,cAAc,UAAQ,GAAG,MAAM;IAqBpG,uGAAuG;IACvG,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,WAAW,GAAG,aAAa,GAAG,QAAsB,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,UAAO,GAAG,MAAM;IA8BpJ;0EACsE;IACtE,SAAS,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAOzC,kBAAkB,CAAC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,GAAG,IAAI;IASzE,OAAO,CAAC,gBAAgB;CAIzB"}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DecisionService = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const types_1 = require("./types");
6
+ class DecisionService {
7
+ constructor(store, deliver) {
8
+ this.store = store;
9
+ this.deliver = deliver;
10
+ }
11
+ /** Deterministic system notice: no inference, input consumption, or epoch change. */
12
+ notice(conversationId, text, deliver, inputId) {
13
+ return this.store.transaction(() => {
14
+ const conversation = this.store.get("SELECT * FROM conversations WHERE id=? AND status='active'", conversationId);
15
+ if (!conversation)
16
+ throw new types_1.OrchestrationError('CONVERSATION_NOT_FOUND');
17
+ const input = inputId ? this.store.get('SELECT * FROM conversation_inputs WHERE id=? AND conversation_id=?', inputId, conversationId) : undefined;
18
+ if (inputId && !input)
19
+ throw new types_1.OrchestrationError('INPUT_NOT_FOUND');
20
+ const id = (0, crypto_1.randomUUID)(), responseId = (0, crypto_1.randomUUID)(), now = Date.now();
21
+ this.store.run('INSERT INTO conversation_decisions VALUES(?,?,?,?,?,?,?,?,?,?,?)', id, conversationId, conversation.epoch, 'notice', input?.request_id ?? null, 'completed', conversation.agent_session_id, JSON.stringify(inputId ? [inputId] : []), '[]', now, now);
22
+ this.store.run('INSERT INTO assistant_responses VALUES(?,?,?,?,?,?,?,?)', responseId, conversationId, id, input?.request_id ?? null, 'completed', text, now, now);
23
+ this.historyOperation(`response:${responseId}`, conversationId, null, responseId);
24
+ const binding = this.store.get('SELECT * FROM conversation_bindings WHERE conversation_id=? AND channel=? AND chat_id=? AND thread_key=?', conversationId, conversation.source, conversation.chat_id, conversation.thread_key);
25
+ if (deliver && binding && binding.channel !== 'api')
26
+ this.deliver?.(responseId, String(binding.id), text);
27
+ this.store.appendEvent(conversationId, 'response.completed', { responseId });
28
+ return responseId;
29
+ });
30
+ }
31
+ begin(conversationId, principalId, inputIds, requestId) {
32
+ if (!inputIds.length || inputIds.length > 100 || new Set(inputIds).size !== inputIds.length)
33
+ throw new types_1.OrchestrationError('INVALID_INPUT');
34
+ return this.store.transaction(() => {
35
+ const conversation = this.store.assertMember(conversationId, principalId);
36
+ if (this.store.get("SELECT id FROM conversation_decisions WHERE conversation_id=? AND state IN ('running','interrupting')", conversationId))
37
+ throw new types_1.OrchestrationError('AGENT_BUSY');
38
+ for (const inputId of inputIds) {
39
+ const input = this.store.get('SELECT * FROM conversation_inputs WHERE id=? AND conversation_id=? AND principal_id=?', inputId, conversationId, principalId);
40
+ if (!input || input.status !== 'accepted' || (input.request_id ?? undefined) !== requestId)
41
+ throw new types_1.OrchestrationError('INPUT_CONFLICT');
42
+ }
43
+ const decisionId = (0, crypto_1.randomUUID)(), epoch = Number(conversation.epoch) + 1;
44
+ this.store.run('UPDATE conversations SET epoch=? WHERE id=?', epoch, conversationId);
45
+ const notifications = this.store.all("SELECT id FROM notifications WHERE conversation_id=? AND status='pending' ORDER BY id LIMIT 100", conversationId).map(row => String(row.id));
46
+ this.store.run('INSERT INTO conversation_decisions VALUES(?,?,?,?,?,?,?,?,?,?,?)', decisionId, conversationId, epoch, 'user', requestId ?? null, 'running', conversation.agent_session_id, JSON.stringify(inputIds), JSON.stringify(notifications), Date.now(), null);
47
+ const responseId = (0, crypto_1.randomUUID)();
48
+ this.store.run('INSERT INTO assistant_responses VALUES(?,?,?,?,?,?,?,?)', responseId, conversationId, decisionId, requestId ?? null, 'generating', '', Date.now(), null);
49
+ for (const inputId of inputIds) {
50
+ this.store.run("UPDATE conversation_inputs SET status='assigned' WHERE id=?", inputId);
51
+ this.store.run("UPDATE outbox SET state='completed' WHERE dedup_key=? AND kind='input'", `input:${inputId}`);
52
+ }
53
+ for (const id of notifications)
54
+ this.store.run("UPDATE notifications SET status='assigned',decision_id=? WHERE id=?", decisionId, id);
55
+ return { decisionId, epoch, inputIds, requestId, responseId };
56
+ });
57
+ }
58
+ /** Independent durable receipt: task execution still belongs to the original
59
+ * running decision. This completed notice never consumes result notifications. */
60
+ acknowledge(receipt, text, spoken, allowCompleted = false) {
61
+ if (!text.trim() || Buffer.byteLength(text) > 2400)
62
+ throw new types_1.OrchestrationError('INVALID_INPUT');
63
+ return this.store.transaction(() => {
64
+ const current = this.store.get("SELECT * FROM conversation_decisions WHERE id=? AND epoch=? AND (state='running' OR (? AND state='completed'))", receipt.decisionId, receipt.epoch, allowCompleted ? 1 : 0);
65
+ if (!current)
66
+ throw new types_1.OrchestrationError('STALE_DECISION');
67
+ const ackDecisionId = `ack:${receipt.decisionId}`, previous = this.store.get('SELECT id FROM assistant_responses WHERE decision_id=?', ackDecisionId);
68
+ if (previous)
69
+ return String(previous.id);
70
+ const now = Date.now(), id = (0, crypto_1.randomUUID)();
71
+ this.store.run('INSERT INTO conversation_decisions VALUES(?,?,?,?,?,?,?,?,?,?,?)', ackDecisionId, current.conversation_id, current.epoch, 'acknowledgement', null, 'completed', current.session_id, current.input_ids_json, '[]', now, now);
72
+ this.store.run('INSERT INTO assistant_responses VALUES(?,?,?,?,?,?,?,?)', id, current.conversation_id, ackDecisionId, null, 'completed', text, now, now);
73
+ for (const inputId of receipt.inputIds)
74
+ this.historyOperation(`input:${inputId}`, String(current.conversation_id), inputId, null);
75
+ this.historyOperation(`response:${id}`, String(current.conversation_id), null, id);
76
+ if (spoken)
77
+ this.store.run('INSERT INTO response_speech VALUES(?,?)', id, spoken);
78
+ const input = this.store.get('SELECT binding_id FROM conversation_inputs WHERE id=?', receipt.inputIds[0]);
79
+ const binding = input && this.store.get('SELECT channel FROM conversation_bindings WHERE id=?', input.binding_id);
80
+ if (binding && binding.channel !== 'api')
81
+ this.deliver?.(id, String(input.binding_id), text);
82
+ this.store.appendEvent(String(current.conversation_id), 'response.completed', { responseId: id });
83
+ return id;
84
+ });
85
+ }
86
+ /** Explicit stop controls acknowledge cancellation themselves; retain history without redelivering. */
87
+ finish(receipt, text, state = 'completed', spoken, deliver = true) {
88
+ if (Buffer.byteLength(text) > 262144)
89
+ throw new types_1.OrchestrationError('PAYLOAD_TOO_LARGE');
90
+ return this.store.transaction(() => {
91
+ const decision = this.store.get(`SELECT d.* FROM conversation_decisions d JOIN conversations c ON c.id=d.conversation_id
92
+ WHERE d.id=? AND d.epoch=? AND ((d.epoch=c.epoch AND d.state='running') OR (d.epoch+1=c.epoch AND d.state='interrupting' AND ?='interrupted'))`, receipt.decisionId, receipt.epoch, state);
93
+ if (!decision)
94
+ throw new types_1.OrchestrationError('STALE_DECISION');
95
+ const now = Date.now(), responseId = String(this.store.get('SELECT id FROM assistant_responses WHERE decision_id=?', receipt.decisionId).id);
96
+ this.store.run('UPDATE assistant_responses SET state=?,generated_text=?,completed_at=? WHERE id=?', state, text, now, responseId);
97
+ this.store.run('UPDATE conversation_decisions SET state=?,ended_at=? WHERE id=?', state, now, receipt.decisionId);
98
+ for (const id of JSON.parse(String(decision.input_ids_json))) {
99
+ this.store.run("UPDATE conversation_inputs SET status='handled' WHERE id=?", id);
100
+ this.historyOperation(`input:${id}`, String(decision.conversation_id), id, null);
101
+ }
102
+ this.historyOperation(`response:${responseId}`, String(decision.conversation_id), null, responseId);
103
+ if (state === 'completed' && text.trim())
104
+ this.store.run(`UPDATE task_files SET response_id=? WHERE response_id IS NULL AND task_id IN
105
+ (SELECT n.task_id FROM notifications n JOIN tasks t ON t.id=n.task_id WHERE n.decision_id=? AND t.state='completed')
106
+ AND id IN (SELECT j.value FROM tasks t,json_each(t.snapshot_json,'$.result.artifactIds') j WHERE t.id=task_files.task_id)`, responseId, receipt.decisionId);
107
+ if (state === 'completed' && spoken)
108
+ this.store.run('INSERT INTO response_speech VALUES(?,?) ON CONFLICT(response_id) DO UPDATE SET text=excluded.text', responseId, spoken);
109
+ const firstInput = this.store.get('SELECT binding_id FROM conversation_inputs WHERE id=?', receipt.inputIds[0]);
110
+ const binding = firstInput && this.store.get('SELECT channel FROM conversation_bindings WHERE id=?', firstInput.binding_id);
111
+ if (deliver && binding && binding.channel !== 'api')
112
+ this.deliver?.(responseId, String(firstInput.binding_id), text);
113
+ if (state === 'completed')
114
+ this.store.run("UPDATE notifications SET status='handled' WHERE decision_id=? AND status='assigned'", receipt.decisionId);
115
+ else
116
+ this.store.run("UPDATE notifications SET status='pending',decision_id=NULL WHERE decision_id=? AND status='assigned'", receipt.decisionId);
117
+ for (const id of state === 'completed' ? JSON.parse(String(decision.notification_ids_json)) : []) {
118
+ this.store.run("UPDATE outbox SET state='completed' WHERE kind='notification' AND json_extract(payload_json,'$.notificationId')=?", id);
119
+ }
120
+ this.store.appendEvent(String(decision.conversation_id), `response.${state}`, { responseId });
121
+ return responseId;
122
+ });
123
+ }
124
+ /** Invalidate commands before asking the driver to stop. Caller must wait for
125
+ * its true terminal/exit acknowledgment before releaseInterrupted. */
126
+ interrupt(receipt) {
127
+ this.store.transaction(() => {
128
+ const row = this.store.get("UPDATE conversation_decisions SET state='interrupting' WHERE id=? AND epoch=? AND state='running' RETURNING conversation_id", receipt.decisionId, receipt.epoch);
129
+ if (!row)
130
+ throw new types_1.OrchestrationError('STALE_DECISION');
131
+ this.store.run('UPDATE conversations SET epoch=epoch+1 WHERE id=? AND epoch=?', row.conversation_id, receipt.epoch);
132
+ });
133
+ }
134
+ releaseInterrupted(receipt, explicitStop) {
135
+ this.store.transaction(() => {
136
+ const row = this.store.get("SELECT * FROM conversation_decisions WHERE id=? AND epoch=? AND state='interrupting'", receipt.decisionId, receipt.epoch);
137
+ if (!row)
138
+ throw new types_1.OrchestrationError('STALE_DECISION');
139
+ this.store.run("UPDATE conversation_decisions SET state='interrupted',ended_at=? WHERE id=?", Date.now(), receipt.decisionId);
140
+ for (const id of JSON.parse(String(row.input_ids_json)))
141
+ this.store.run('UPDATE conversation_inputs SET status=? WHERE id=?', explicitStop ? 'handled' : 'accepted', id);
142
+ this.store.run("UPDATE notifications SET status='pending',decision_id=NULL WHERE decision_id=? AND status='assigned'", receipt.decisionId);
143
+ });
144
+ }
145
+ historyOperation(operationId, conversationId, inputId, responseId) {
146
+ this.store.run('INSERT INTO history_operations VALUES(?,?,?,?,?,?,?,?) ON CONFLICT(operation_id) DO NOTHING', operationId, conversationId, inputId, responseId, 'append', null, 'pending', Date.now());
147
+ this.store.enqueue('history', operationId, { operationId });
148
+ }
149
+ }
150
+ exports.DecisionService = DecisionService;
151
+ //# sourceMappingURL=decisions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decisions.js","sourceRoot":"","sources":["../../src/orchestration/decisions.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,mCAA6C;AAG7C,MAAa,eAAe;IAC1B,YAAqB,KAAyB,EAAmB,OAAuE;QAAnH,UAAK,GAAL,KAAK,CAAoB;QAAmB,YAAO,GAAP,OAAO,CAAgE;IAAG,CAAC;IAC5I,qFAAqF;IACrF,MAAM,CAAC,cAAsB,EAAE,IAAY,EAAE,OAAgB,EAAE,OAAgB;QAC7E,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;YACjC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,4DAA4D,EAAE,cAAc,CAAC,CAAC;YAClH,IAAI,CAAC,YAAY;gBAAE,MAAM,IAAI,0BAAkB,CAAC,wBAAwB,CAAC,CAAC;YAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,oEAAoE,EAAE,OAAO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AAC,GAAG,CAAC,sGAAsG,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7I,CAAC,CAAC,CAAC;IACL,CAAC;IACO,gBAAgB,CAAC,WAAmB,EAAE,cAAsB,EAAE,OAAsB,EAAE,UAAyB;QACrH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,6FAA6F,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACvM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AAvHD,0CAuHC"}
@@ -0,0 +1,34 @@
1
+ import { SpeechDelivery } from './telegram-speech';
2
+ import type { AgentConfig } from '../types';
3
+ import { OrchestrationStore, Row } from './store';
4
+ import { ChannelFile } from './file-delivery';
5
+ export type DeliveryOutcome = {
6
+ state: 'delivered';
7
+ providerId?: string;
8
+ } | {
9
+ state: 'failed' | 'unknown';
10
+ code: string;
11
+ speechSynthesisFailed?: boolean;
12
+ };
13
+ export type DeliveryControl = {
14
+ label: string;
15
+ data: string;
16
+ };
17
+ export type ChannelSender = (binding: Row, text: string, deliveryId: string, file?: ChannelFile, speech?: SpeechDelivery, textFormat?: 'HTML' | 'text', controls?: DeliveryControl[]) => Promise<DeliveryOutcome>;
18
+ /** A transport receipt means provider acceptance, never that a human read it.
19
+ * Ambiguous network failures are retained for reconciliation, not blind retry. */
20
+ export declare function channelSender(config: AgentConfig | (() => AgentConfig), request?: typeof fetch, speechEnabled?: (binding: Row, speech: SpeechDelivery) => boolean, linkedSender?: ChannelSender): ChannelSender;
21
+ /** Channel notices share one provider-independent vocabulary; details stay in logs. */
22
+ export declare function speechFailureNotice(code: string): string;
23
+ export declare class DeliveryOutbox {
24
+ private readonly store;
25
+ private readonly send;
26
+ private active?;
27
+ constructor(store: OrchestrationStore, send: ChannelSender);
28
+ /** Called inside the decision commit transaction. Each chunk has its own receipt. */
29
+ enqueue(responseId: string, bindingId: string, text: string, controls?: DeliveryControl[]): void;
30
+ enqueueSpeech(responseId: string, bindingId: string, speech: SpeechDelivery): void;
31
+ tick(): Promise<void>;
32
+ private run;
33
+ }
34
+ //# sourceMappingURL=delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery.d.ts","sourceRoot":"","sources":["../../src/orchestration/delivery.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAmB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAC3J,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,eAAe,EAAE,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;AAElN;kFACkF;AAClF,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,CAAC,MA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