@0xmaxma/claude-gateway 2.0.20 → 2.1.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 (358) hide show
  1. package/README.md +1 -0
  2. package/config.template.json +3 -2
  3. package/dist/agent/builtin-commands.d.ts +4 -0
  4. package/dist/agent/builtin-commands.d.ts.map +1 -1
  5. package/dist/agent/builtin-commands.js +11 -4
  6. package/dist/agent/builtin-commands.js.map +1 -1
  7. package/dist/agent/command-help.d.ts +11 -2
  8. package/dist/agent/command-help.d.ts.map +1 -1
  9. package/dist/agent/command-help.js +29 -8
  10. package/dist/agent/command-help.js.map +1 -1
  11. package/dist/agent/model-registry.d.ts +48 -0
  12. package/dist/agent/model-registry.d.ts.map +1 -0
  13. package/dist/agent/model-registry.js +144 -0
  14. package/dist/agent/model-registry.js.map +1 -0
  15. package/dist/agent/runner.d.ts +73 -43
  16. package/dist/agent/runner.d.ts.map +1 -1
  17. package/dist/agent/runner.js +361 -120
  18. package/dist/agent/runner.js.map +1 -1
  19. package/dist/agent/session-confirmations.d.ts +1 -1
  20. package/dist/agent/session-confirmations.d.ts.map +1 -1
  21. package/dist/agent/session-confirmations.js +5 -3
  22. package/dist/agent/session-confirmations.js.map +1 -1
  23. package/dist/agent/skill-learning/reviewer.d.ts.map +1 -1
  24. package/dist/agent/skill-learning/reviewer.js +2 -1
  25. package/dist/agent/skill-learning/reviewer.js.map +1 -1
  26. package/dist/agent/turn-stream.d.ts +2 -1
  27. package/dist/agent/turn-stream.d.ts.map +1 -1
  28. package/dist/agent/turn-stream.js.map +1 -1
  29. package/dist/api/gateway-router.d.ts.map +1 -1
  30. package/dist/api/gateway-router.js +17 -1
  31. package/dist/api/gateway-router.js.map +1 -1
  32. package/dist/api/manifest-sources.d.ts.map +1 -1
  33. package/dist/api/manifest-sources.js +3 -0
  34. package/dist/api/manifest-sources.js.map +1 -1
  35. package/dist/api/pstack-router.d.ts +14 -0
  36. package/dist/api/pstack-router.d.ts.map +1 -0
  37. package/dist/api/pstack-router.js +93 -0
  38. package/dist/api/pstack-router.js.map +1 -0
  39. package/dist/api/router.d.ts.map +1 -1
  40. package/dist/api/router.js +32 -83
  41. package/dist/api/router.js.map +1 -1
  42. package/dist/api/voice-call-router.d.ts +21 -0
  43. package/dist/api/voice-call-router.d.ts.map +1 -0
  44. package/dist/api/voice-call-router.js +119 -0
  45. package/dist/api/voice-call-router.js.map +1 -0
  46. package/dist/api/voice-router.d.ts +27 -0
  47. package/dist/api/voice-router.d.ts.map +1 -1
  48. package/dist/api/voice-router.js +126 -63
  49. package/dist/api/voice-router.js.map +1 -1
  50. package/dist/api/voice-settings-router.d.ts.map +1 -1
  51. package/dist/api/voice-settings-router.js +3 -1
  52. package/dist/api/voice-settings-router.js.map +1 -1
  53. package/dist/automation/computer-use.d.ts.map +1 -1
  54. package/dist/automation/computer-use.js +8 -1
  55. package/dist/automation/computer-use.js.map +1 -1
  56. package/dist/build-provenance.json +4 -4
  57. package/dist/cli/commands.generated.d.ts.map +1 -1
  58. package/dist/cli/commands.generated.js +36 -1
  59. package/dist/cli/commands.generated.js.map +1 -1
  60. package/dist/cli-viewer/pairing-store.d.ts +4 -0
  61. package/dist/cli-viewer/pairing-store.d.ts.map +1 -1
  62. package/dist/cli-viewer/pairing-store.js +6 -6
  63. package/dist/cli-viewer/pairing-store.js.map +1 -1
  64. package/dist/cli-viewer/telegram-initdata.d.ts +1 -1
  65. package/dist/cli-viewer/telegram-initdata.d.ts.map +1 -1
  66. package/dist/cli-viewer/telegram-initdata.js +2 -2
  67. package/dist/cli-viewer/telegram-initdata.js.map +1 -1
  68. package/dist/cli-viewer/url.d.ts +2 -0
  69. package/dist/cli-viewer/url.d.ts.map +1 -1
  70. package/dist/cli-viewer/url.js +6 -0
  71. package/dist/cli-viewer/url.js.map +1 -1
  72. package/dist/config/loader.d.ts.map +1 -1
  73. package/dist/config/loader.js +7 -0
  74. package/dist/config/loader.js.map +1 -1
  75. package/dist/config/reload-policy.js +1 -1
  76. package/dist/config/reload-policy.js.map +1 -1
  77. package/dist/config/watcher.d.ts.map +1 -1
  78. package/dist/config/watcher.js +2 -0
  79. package/dist/config/watcher.js.map +1 -1
  80. package/dist/orchestration/agent-tool-schemas.js +1 -1
  81. package/dist/orchestration/agent-tool-schemas.js.map +1 -1
  82. package/dist/orchestration/bridge.d.ts +6 -2
  83. package/dist/orchestration/bridge.d.ts.map +1 -1
  84. package/dist/orchestration/bridge.js +122 -6
  85. package/dist/orchestration/bridge.js.map +1 -1
  86. package/dist/orchestration/capabilities.d.ts.map +1 -1
  87. package/dist/orchestration/capabilities.js +10 -3
  88. package/dist/orchestration/capabilities.js.map +1 -1
  89. package/dist/orchestration/capacity.d.ts +9 -2
  90. package/dist/orchestration/capacity.d.ts.map +1 -1
  91. package/dist/orchestration/capacity.js +18 -7
  92. package/dist/orchestration/capacity.js.map +1 -1
  93. package/dist/orchestration/cli-skills.d.ts.map +1 -1
  94. package/dist/orchestration/cli-skills.js +4 -2
  95. package/dist/orchestration/cli-skills.js.map +1 -1
  96. package/dist/orchestration/config.d.ts +47 -0
  97. package/dist/orchestration/config.d.ts.map +1 -1
  98. package/dist/orchestration/config.js +25 -4
  99. package/dist/orchestration/config.js.map +1 -1
  100. package/dist/orchestration/conversation-intake.d.ts.map +1 -1
  101. package/dist/orchestration/conversation-intake.js +3 -1
  102. package/dist/orchestration/conversation-intake.js.map +1 -1
  103. package/dist/orchestration/dashboard-reader-worker.js +5 -3
  104. package/dist/orchestration/dashboard-reader-worker.js.map +1 -1
  105. package/dist/orchestration/decisions.d.ts.map +1 -1
  106. package/dist/orchestration/decisions.js +4 -2
  107. package/dist/orchestration/decisions.js.map +1 -1
  108. package/dist/orchestration/delivery.d.ts.map +1 -1
  109. package/dist/orchestration/delivery.js +1 -0
  110. package/dist/orchestration/delivery.js.map +1 -1
  111. package/dist/orchestration/display-stream.d.ts +6 -0
  112. package/dist/orchestration/display-stream.d.ts.map +1 -1
  113. package/dist/orchestration/display-stream.js +13 -8
  114. package/dist/orchestration/display-stream.js.map +1 -1
  115. package/dist/orchestration/gateway-tasks/computer.d.ts +2 -0
  116. package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
  117. package/dist/orchestration/gateway-tasks/computer.js +68 -28
  118. package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
  119. package/dist/orchestration/gateway-tasks/controller.d.ts +6 -6
  120. package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -1
  121. package/dist/orchestration/identity.d.ts +5 -1
  122. package/dist/orchestration/identity.d.ts.map +1 -1
  123. package/dist/orchestration/identity.js +6 -0
  124. package/dist/orchestration/identity.js.map +1 -1
  125. package/dist/orchestration/input-batch.d.ts +8 -2
  126. package/dist/orchestration/input-batch.d.ts.map +1 -1
  127. package/dist/orchestration/input-batch.js +28 -8
  128. package/dist/orchestration/input-batch.js.map +1 -1
  129. package/dist/orchestration/live-voice-transcript.d.ts +13 -0
  130. package/dist/orchestration/live-voice-transcript.d.ts.map +1 -0
  131. package/dist/orchestration/live-voice-transcript.js +36 -0
  132. package/dist/orchestration/live-voice-transcript.js.map +1 -0
  133. package/dist/orchestration/mutation-recovery.js +1 -1
  134. package/dist/orchestration/mutation-recovery.js.map +1 -1
  135. package/dist/orchestration/notification-mailbox.d.ts.map +1 -1
  136. package/dist/orchestration/notification-mailbox.js +4 -2
  137. package/dist/orchestration/notification-mailbox.js.map +1 -1
  138. package/dist/orchestration/process-turn.d.ts +6 -1
  139. package/dist/orchestration/process-turn.d.ts.map +1 -1
  140. package/dist/orchestration/process-turn.js +9 -5
  141. package/dist/orchestration/process-turn.js.map +1 -1
  142. package/dist/orchestration/recovery.d.ts.map +1 -1
  143. package/dist/orchestration/recovery.js +21 -0
  144. package/dist/orchestration/recovery.js.map +1 -1
  145. package/dist/orchestration/response-errors.d.ts +5 -0
  146. package/dist/orchestration/response-errors.d.ts.map +1 -1
  147. package/dist/orchestration/response-errors.js +25 -0
  148. package/dist/orchestration/response-errors.js.map +1 -1
  149. package/dist/orchestration/runtime.d.ts +26 -2
  150. package/dist/orchestration/runtime.d.ts.map +1 -1
  151. package/dist/orchestration/runtime.js +221 -48
  152. package/dist/orchestration/runtime.js.map +1 -1
  153. package/dist/orchestration/speech.d.ts +3 -0
  154. package/dist/orchestration/speech.d.ts.map +1 -1
  155. package/dist/orchestration/speech.js +13 -5
  156. package/dist/orchestration/speech.js.map +1 -1
  157. package/dist/orchestration/store.d.ts +5 -0
  158. package/dist/orchestration/store.d.ts.map +1 -1
  159. package/dist/orchestration/store.js +13 -5
  160. package/dist/orchestration/store.js.map +1 -1
  161. package/dist/orchestration/subagent-tool-schemas.d.ts +12 -0
  162. package/dist/orchestration/subagent-tool-schemas.d.ts.map +1 -0
  163. package/dist/orchestration/subagent-tool-schemas.js +23 -0
  164. package/dist/orchestration/subagent-tool-schemas.js.map +1 -0
  165. package/dist/orchestration/task-controls.d.ts.map +1 -1
  166. package/dist/orchestration/task-controls.js +2 -1
  167. package/dist/orchestration/task-controls.js.map +1 -1
  168. package/dist/orchestration/task-questions.d.ts.map +1 -1
  169. package/dist/orchestration/task-questions.js +3 -1
  170. package/dist/orchestration/task-questions.js.map +1 -1
  171. package/dist/orchestration/tasks/automation-session.d.ts +12 -0
  172. package/dist/orchestration/tasks/automation-session.d.ts.map +1 -1
  173. package/dist/orchestration/tasks/automation-session.js +26 -1
  174. package/dist/orchestration/tasks/automation-session.js.map +1 -1
  175. package/dist/orchestration/tasks/driver.d.ts.map +1 -1
  176. package/dist/orchestration/tasks/driver.js +54 -14
  177. package/dist/orchestration/tasks/driver.js.map +1 -1
  178. package/dist/orchestration/tasks/scheduler.d.ts.map +1 -1
  179. package/dist/orchestration/tasks/scheduler.js +17 -3
  180. package/dist/orchestration/tasks/scheduler.js.map +1 -1
  181. package/dist/orchestration/tasks/service.d.ts +110 -34
  182. package/dist/orchestration/tasks/service.d.ts.map +1 -1
  183. package/dist/orchestration/tasks/service.js +234 -19
  184. package/dist/orchestration/tasks/service.js.map +1 -1
  185. package/dist/orchestration/tasks/task-directive.d.ts.map +1 -1
  186. package/dist/orchestration/tasks/task-directive.js +5 -1
  187. package/dist/orchestration/tasks/task-directive.js.map +1 -1
  188. package/dist/orchestration/telegram-tool-status.d.ts +8 -1
  189. package/dist/orchestration/telegram-tool-status.d.ts.map +1 -1
  190. package/dist/orchestration/telegram-tool-status.js +57 -6
  191. package/dist/orchestration/telegram-tool-status.js.map +1 -1
  192. package/dist/orchestration/telegram-voices.d.ts +4 -0
  193. package/dist/orchestration/telegram-voices.d.ts.map +1 -1
  194. package/dist/orchestration/telegram-voices.js +6 -2
  195. package/dist/orchestration/telegram-voices.js.map +1 -1
  196. package/dist/orchestration/token-ledger.d.ts +14 -0
  197. package/dist/orchestration/token-ledger.d.ts.map +1 -1
  198. package/dist/orchestration/token-ledger.js +28 -2
  199. package/dist/orchestration/token-ledger.js.map +1 -1
  200. package/dist/orchestration/token-usage.d.ts +14 -0
  201. package/dist/orchestration/token-usage.d.ts.map +1 -1
  202. package/dist/orchestration/token-usage.js +16 -2
  203. package/dist/orchestration/token-usage.js.map +1 -1
  204. package/dist/orchestration/tool-name.d.ts.map +1 -1
  205. package/dist/orchestration/tool-name.js +5 -1
  206. package/dist/orchestration/tool-name.js.map +1 -1
  207. package/dist/orchestration/types.d.ts +29 -0
  208. package/dist/orchestration/types.d.ts.map +1 -1
  209. package/dist/orchestration/types.js +11 -0
  210. package/dist/orchestration/types.js.map +1 -1
  211. package/dist/orchestration/worker-harness.d.ts.map +1 -1
  212. package/dist/orchestration/worker-harness.js +5 -2
  213. package/dist/orchestration/worker-harness.js.map +1 -1
  214. package/dist/pstack/config.d.ts +48 -0
  215. package/dist/pstack/config.d.ts.map +1 -0
  216. package/dist/pstack/config.js +147 -0
  217. package/dist/pstack/config.js.map +1 -0
  218. package/dist/pstack/menu.d.ts +71 -0
  219. package/dist/pstack/menu.d.ts.map +1 -0
  220. package/dist/pstack/menu.js +286 -0
  221. package/dist/pstack/menu.js.map +1 -0
  222. package/dist/pstack/overlay.d.ts +30 -0
  223. package/dist/pstack/overlay.d.ts.map +1 -0
  224. package/dist/pstack/overlay.js +121 -0
  225. package/dist/pstack/overlay.js.map +1 -0
  226. package/dist/pstack/plugin-info.d.ts +36 -0
  227. package/dist/pstack/plugin-info.d.ts.map +1 -0
  228. package/dist/pstack/plugin-info.js +51 -0
  229. package/dist/pstack/plugin-info.js.map +1 -0
  230. package/dist/pstack/reflect.d.ts +14 -0
  231. package/dist/pstack/reflect.d.ts.map +1 -0
  232. package/dist/pstack/reflect.js +49 -0
  233. package/dist/pstack/reflect.js.map +1 -0
  234. package/dist/pstack/setup.d.ts +17 -0
  235. package/dist/pstack/setup.d.ts.map +1 -0
  236. package/dist/pstack/setup.js +47 -0
  237. package/dist/pstack/setup.js.map +1 -0
  238. package/dist/pstack/sheet.d.ts +19 -0
  239. package/dist/pstack/sheet.d.ts.map +1 -0
  240. package/dist/pstack/sheet.js +44 -0
  241. package/dist/pstack/sheet.js.map +1 -0
  242. package/dist/pstack/templates.d.ts +14 -0
  243. package/dist/pstack/templates.d.ts.map +1 -0
  244. package/dist/pstack/templates.js +41 -0
  245. package/dist/pstack/templates.js.map +1 -0
  246. package/dist/session/codex-process.d.ts +0 -3
  247. package/dist/session/codex-process.d.ts.map +1 -1
  248. package/dist/session/codex-process.js +8 -3
  249. package/dist/session/codex-process.js.map +1 -1
  250. package/dist/session/compactor.d.ts.map +1 -1
  251. package/dist/session/compactor.js +2 -1
  252. package/dist/session/compactor.js.map +1 -1
  253. package/dist/session/process-diagnostics.d.ts +3 -0
  254. package/dist/session/process-diagnostics.d.ts.map +1 -1
  255. package/dist/session/process-diagnostics.js +10 -0
  256. package/dist/session/process-diagnostics.js.map +1 -1
  257. package/dist/session/process.d.ts.map +1 -1
  258. package/dist/session/process.js +9 -4
  259. package/dist/session/process.js.map +1 -1
  260. package/dist/session/provider-refusal.d.ts +36 -0
  261. package/dist/session/provider-refusal.d.ts.map +1 -0
  262. package/dist/session/provider-refusal.js +109 -0
  263. package/dist/session/provider-refusal.js.map +1 -0
  264. package/dist/session/runtime-profile.d.ts +13 -2
  265. package/dist/session/runtime-profile.d.ts.map +1 -1
  266. package/dist/session/runtime-profile.js +35 -2
  267. package/dist/session/runtime-profile.js.map +1 -1
  268. package/dist/session/worker-extensions.d.ts +5 -2
  269. package/dist/session/worker-extensions.d.ts.map +1 -1
  270. package/dist/session/worker-extensions.js +10 -5
  271. package/dist/session/worker-extensions.js.map +1 -1
  272. package/dist/telegram/access.d.ts +23 -0
  273. package/dist/telegram/access.d.ts.map +1 -0
  274. package/dist/telegram/access.js +105 -0
  275. package/dist/telegram/access.js.map +1 -0
  276. package/dist/types.d.ts +3 -0
  277. package/dist/types.d.ts.map +1 -1
  278. package/dist/ui/cli-viewer-ui.d.ts +5 -0
  279. package/dist/ui/cli-viewer-ui.d.ts.map +1 -1
  280. package/dist/ui/cli-viewer-ui.js +9 -6
  281. package/dist/ui/cli-viewer-ui.js.map +1 -1
  282. package/dist/ui/dashboard-client.d.ts.map +1 -1
  283. package/dist/ui/dashboard-client.js +14 -4
  284. package/dist/ui/dashboard-client.js.map +1 -1
  285. package/dist/ui/dashboard-presentation.d.ts +29 -0
  286. package/dist/ui/dashboard-presentation.d.ts.map +1 -1
  287. package/dist/ui/dashboard-presentation.js +26 -1
  288. package/dist/ui/dashboard-presentation.js.map +1 -1
  289. package/dist/ui/token-report.d.ts +3 -0
  290. package/dist/ui/token-report.d.ts.map +1 -1
  291. package/dist/ui/token-report.js +1 -1
  292. package/dist/ui/token-report.js.map +1 -1
  293. package/dist/ui/voice-call-client.d.ts +142 -0
  294. package/dist/ui/voice-call-client.d.ts.map +1 -0
  295. package/dist/ui/voice-call-client.js +328 -0
  296. package/dist/ui/voice-call-client.js.map +1 -0
  297. package/dist/ui/voice-call-ui.d.ts +21 -0
  298. package/dist/ui/voice-call-ui.d.ts.map +1 -0
  299. package/dist/ui/voice-call-ui.js +488 -0
  300. package/dist/ui/voice-call-ui.js.map +1 -0
  301. package/dist/voice/audio-tags.d.ts +7 -0
  302. package/dist/voice/audio-tags.d.ts.map +1 -0
  303. package/dist/voice/audio-tags.js +66 -0
  304. package/dist/voice/audio-tags.js.map +1 -0
  305. package/dist/voice/call-pairing.d.ts +76 -0
  306. package/dist/voice/call-pairing.d.ts.map +1 -0
  307. package/dist/voice/call-pairing.js +126 -0
  308. package/dist/voice/call-pairing.js.map +1 -0
  309. package/dist/voice/diagnostics.d.ts +12 -9
  310. package/dist/voice/diagnostics.d.ts.map +1 -1
  311. package/dist/voice/diagnostics.js +2 -1
  312. package/dist/voice/diagnostics.js.map +1 -1
  313. package/dist/voice/errors.d.ts +6 -1
  314. package/dist/voice/errors.d.ts.map +1 -1
  315. package/dist/voice/errors.js +12 -1
  316. package/dist/voice/errors.js.map +1 -1
  317. package/dist/voice/fast-ack.d.ts +27 -0
  318. package/dist/voice/fast-ack.d.ts.map +1 -0
  319. package/dist/voice/fast-ack.js +52 -0
  320. package/dist/voice/fast-ack.js.map +1 -0
  321. package/dist/voice/managed-quota.d.ts +29 -3
  322. package/dist/voice/managed-quota.d.ts.map +1 -1
  323. package/dist/voice/managed-quota.js +68 -23
  324. package/dist/voice/managed-quota.js.map +1 -1
  325. package/dist/voice/notes.d.ts +27 -3
  326. package/dist/voice/notes.d.ts.map +1 -1
  327. package/dist/voice/notes.js +59 -10
  328. package/dist/voice/notes.js.map +1 -1
  329. package/dist/voice/providers/elevenlabs-tts.d.ts +1 -0
  330. package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -1
  331. package/dist/voice/providers/elevenlabs-tts.js +62 -12
  332. package/dist/voice/providers/elevenlabs-tts.js.map +1 -1
  333. package/dist/voice/providers/gemini.d.ts +4 -0
  334. package/dist/voice/providers/gemini.d.ts.map +1 -1
  335. package/dist/voice/providers/gemini.js +7 -1
  336. package/dist/voice/providers/gemini.js.map +1 -1
  337. package/dist/voice/providers/registry.d.ts.map +1 -1
  338. package/dist/voice/providers/registry.js +34 -2
  339. package/dist/voice/providers/registry.js.map +1 -1
  340. package/dist/voice/scope.d.ts +13 -0
  341. package/dist/voice/scope.d.ts.map +1 -0
  342. package/dist/voice/scope.js +3 -0
  343. package/dist/voice/scope.js.map +1 -0
  344. package/dist/voice/session.d.ts +16 -1
  345. package/dist/voice/session.d.ts.map +1 -1
  346. package/dist/voice/session.js +90 -16
  347. package/dist/voice/session.js.map +1 -1
  348. package/dist/voice/telegram-avatar.d.ts +38 -0
  349. package/dist/voice/telegram-avatar.d.ts.map +1 -0
  350. package/dist/voice/telegram-avatar.js +95 -0
  351. package/dist/voice/telegram-avatar.js.map +1 -0
  352. package/mcp/lazy-tools.ts +4 -2
  353. package/mcp/server.ts +6 -2
  354. package/mcp/tools/tasks/module.ts +3 -1
  355. package/mcp/tools/telegram/pstack-menu.ts +22 -0
  356. package/mcp/tools/telegram/pure.ts +40 -0
  357. package/mcp/tools/telegram/receiver-server.ts +86 -7
  358. package/package.json +1 -1
@@ -58,11 +58,11 @@ const auth_1 = require("./auth");
58
58
  const media_store_1 = require("../history/media-store");
59
59
  const db_1 = require("../history/db");
60
60
  const types_2 = require("../history/types");
61
+ const access_1 = require("../telegram/access");
61
62
  const wizard_state_1 = require("./wizard-state");
62
63
  const pending_senders_1 = require("./pending-senders");
63
64
  const create_agent_prompts_1 = require("../agent/create-agent-prompts");
64
- const model_catalog_1 = require("../agent/model-catalog");
65
- const runner_2 = require("../agent/runner");
65
+ const model_registry_1 = require("../agent/model-registry");
66
66
  const whatsapp_accounts_1 = require("../config/whatsapp-accounts");
67
67
  const whatsapp_access_1 = require("./whatsapp-access");
68
68
  const MAX_MESSAGE_LENGTH = 10000;
@@ -134,6 +134,15 @@ function isValidSessionId(v) {
134
134
  function isValidAgentId(v) {
135
135
  return typeof v === 'string' && AGENT_ID_RE.test(v);
136
136
  }
137
+ /**
138
+ * The structured part of a built-in command reply, beside its text: `command`
139
+ * (the base command), `result` (its fields) and `actions` (buttons; each
140
+ * `command` is sent back as the next message, so it runs with the same key,
141
+ * session and checks as anything typed).
142
+ */
143
+ function commandReplyFields(message, reply) {
144
+ return { command: message.trim().split(/\s+/)[0], result: reply.result, actions: reply.actions ?? [] };
145
+ }
137
146
  /**
138
147
  * The one place a turn's stream events become SSE frames (#421).
139
148
  *
@@ -164,7 +173,7 @@ function createSseCallbacks(res, meta) {
164
173
  }
165
174
  catch { /* client gone */ }
166
175
  },
167
- onDone: (fullText, attachments, seq) => {
176
+ onDone: (fullText, attachments, seq, extra) => {
168
177
  try {
169
178
  const frame = {
170
179
  type: 'result',
@@ -172,6 +181,7 @@ function createSseCallbacks(res, meta) {
172
181
  seq,
173
182
  ...ids(),
174
183
  duration_ms: Date.now() - meta.startTime,
184
+ ...extra,
175
185
  };
176
186
  if (attachments?.length)
177
187
  frame['attachments'] = attachments;
@@ -844,9 +854,9 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
844
854
  if (isBuiltinCommand) {
845
855
  openSseStream(res);
846
856
  try {
847
- const { responseText } = await runner.executeApiCommand(sessionId, chatIdStr, commandMessage, { skipPersist: skipUserMessage, model: modelStr, principalId: (0, identity_1.apiPrincipal)(apiKey), displayCommand: trimmedMessage, clientMessageId });
848
- sseCallbacks.onChunk({ type: 'text_delta', text: responseText });
849
- sseCallbacks.onDone(responseText, []);
857
+ const reply = await runner.executeApiCommand(sessionId, chatIdStr, commandMessage, { skipPersist: skipUserMessage, model: modelStr, principalId: (0, identity_1.apiPrincipal)(apiKey), displayCommand: trimmedMessage, clientMessageId, canWriteAgent: (0, auth_1.canWriteAgent)(apiKey, agentId), implicitSession: session_id === undefined });
858
+ sseCallbacks.onChunk({ type: 'text_delta', text: reply.responseText });
859
+ sseCallbacks.onDone(reply.responseText, [], undefined, commandReplyFields(commandMessage, reply));
850
860
  }
851
861
  catch (err) {
852
862
  sseCallbacks.onError(err);
@@ -891,9 +901,12 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
891
901
  try {
892
902
  let responseText;
893
903
  let attachments = [];
904
+ let commandFields = {};
894
905
  if (isBuiltinCommand) {
895
- // Built-in command — answer locally, return the same JSON shape as a normal reply.
896
- ({ responseText } = await runner.executeApiCommand(sessionId, chatIdStr, commandMessage, { skipPersist: skipUserMessage, principalId: (0, identity_1.apiPrincipal)(apiKey), displayCommand: trimmedMessage, clientMessageId }));
906
+ // Built-in command — answer locally, return the same JSON shape as a normal reply plus its structured part.
907
+ const reply = await runner.executeApiCommand(sessionId, chatIdStr, commandMessage, { skipPersist: skipUserMessage, principalId: (0, identity_1.apiPrincipal)(apiKey), displayCommand: trimmedMessage, clientMessageId, canWriteAgent: (0, auth_1.canWriteAgent)(apiKey, agentId), implicitSession: session_id === undefined });
908
+ responseText = reply.responseText;
909
+ commandFields = commandReplyFields(commandMessage, reply);
897
910
  }
898
911
  else {
899
912
  const agentCfgSync = agentConfigs.get(agentId);
@@ -917,6 +930,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
917
930
  response: responseText,
918
931
  session_id: sessionId,
919
932
  duration_ms: Date.now() - startTime,
933
+ ...commandFields,
920
934
  };
921
935
  if (attachments.length)
922
936
  syncResult['attachments'] = attachments;
@@ -948,19 +962,11 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
948
962
  * into config.json at provisioning time (issue #409).
949
963
  */
950
964
  router.get('/v1/models', auth, async (_req, res) => {
951
- // `?? DEFAULT_MODELS`, not `?? []`, and that is load-bearing rather than
952
- // cosmetic. fetchModelCatalog caches one parsed catalog per process, and
953
- // the alias/contextWindow/multiplier on it are inherited from whichever
954
- // caller's list populated the cache first. AgentRunner passes
955
- // `gateway.models ?? DEFAULT_MODELS`; if this route passed `[]` on a
956
- // gateway whose config has no `gateway.models`, one request here would
957
- // cache a catalog with every alias set to its id and every context window
958
- // at the 200k default — and the picker and all six contextWindowFor()
959
- // callers would read that degraded list for the next 60 seconds. It also
960
- // makes this endpoint agree with the picker on an unconfigured gateway
961
- // instead of reporting no models at all.
962
- const staticModels = (typeof models === 'function' ? models() : models) ?? runner_2.DEFAULT_MODELS;
963
- const available = (await (0, model_catalog_1.fetchModelCatalog)(staticModels)) ?? staticModels;
965
+ // availableModels() falls back to DEFAULT_MODELS, never `[]`: the
966
+ // catalog cache inherits alias/contextWindow/multiplier from whichever
967
+ // caller's list populated it first, so this route must pass the same list
968
+ // the runner does or one request here degrades the picker for 60 seconds.
969
+ const available = await (0, model_registry_1.availableModels)(typeof models === 'function' ? models() : models);
964
970
  res.json({ models: available.map((m) => ({ id: m.id, name: m.label, alias: m.alias, contextWindow: m.contextWindow, multiplier: m.multiplier ?? 1 })) });
965
971
  });
966
972
  /**
@@ -1197,67 +1203,10 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
1197
1203
  return (0, agent_env_1.agentsDirForConfig)(configPath);
1198
1204
  }
1199
1205
  function getTelegramStateDir(agentId) {
1200
- const agentsBase = getAgentsBaseDir();
1201
- const cfg = agentConfigs.get(agentId);
1202
- const workspace = cfg?.workspace
1203
- ? (cfg.workspace.startsWith('~') ? path.join(os.homedir(), cfg.workspace.slice(1)) : cfg.workspace)
1204
- : path.join(agentsBase, agentId, 'workspace');
1205
- return path.join(workspace, '.telegram-state');
1206
+ return (0, access_1.telegramStateDir)(agentConfigs.get(agentId)?.workspace, getAgentsBaseDir(), agentId);
1206
1207
  }
1207
1208
  function readTelegramAccess(agentId) {
1208
- const accessFile = path.join(getTelegramStateDir(agentId), 'access.json');
1209
- try {
1210
- const raw = fs.readFileSync(accessFile, 'utf8');
1211
- const parsed = JSON.parse(raw);
1212
- // Migrate the legacy 4-value dmPolicy (pairing folded in) to the split
1213
- // model. SECURITY: a legacy 'allowlist' file was locked down → pairing:false
1214
- // (an absent pairing on an existing file means pre-split); 'pairing' → mint on.
1215
- // Mirrors migrateAccess() in mcp/tools/telegram/pure.ts — keep in sync.
1216
- const legacy = parsed.dmPolicy;
1217
- let dmPolicy;
1218
- let pairing;
1219
- if (legacy === 'pairing') {
1220
- dmPolicy = 'allowlist';
1221
- pairing = true;
1222
- }
1223
- else {
1224
- dmPolicy = legacy ?? 'allowlist';
1225
- pairing = parsed.pairing ?? false;
1226
- }
1227
- // Group tier: flatten legacy per-group `groups` map to a flat allowlist,
1228
- // behavior-preserving (groups were closed-by-default). Mirrors pure.ts.
1229
- // A group's per-user `allowFrom` override has no flat-model equivalent,
1230
- // but it's a real restriction — preserve it (mirrors
1231
- // deriveLegacyGroupAllowFrom in pure.ts, keep in sync) rather than
1232
- // silently dropping it and widening the group to every member.
1233
- const groupAllowlist = parsed.groupAllowlist ?? Object.keys(parsed.groups ?? {});
1234
- const groupPolicy = parsed.groupPolicy ?? 'allowlist';
1235
- const requireMention = parsed.requireMention ?? true;
1236
- let legacyGroupAllowFrom = parsed.legacyGroupAllowFrom;
1237
- if (!legacyGroupAllowFrom && parsed.groups) {
1238
- const derived = {};
1239
- for (const [groupId, g] of Object.entries(parsed.groups)) {
1240
- if (g.allowFrom && g.allowFrom.length > 0)
1241
- derived[groupId] = [...g.allowFrom];
1242
- }
1243
- if (Object.keys(derived).length > 0)
1244
- legacyGroupAllowFrom = derived;
1245
- }
1246
- return {
1247
- dmPolicy,
1248
- pairing,
1249
- allowFrom: parsed.allowFrom ?? [],
1250
- groupPolicy,
1251
- groupAllowlist,
1252
- requireMention,
1253
- legacyGroupAllowFrom,
1254
- pending: parsed.pending ?? {},
1255
- };
1256
- }
1257
- catch {
1258
- // Brand-new agent (no file): closed base + pairing on (capture owner id).
1259
- return { dmPolicy: 'allowlist', pairing: true, allowFrom: [], groupPolicy: 'allowlist', groupAllowlist: [], requireMention: true, pending: {} };
1260
- }
1209
+ return (0, access_1.readTelegramAccess)(getTelegramStateDir(agentId));
1261
1210
  }
1262
1211
  function writeTelegramAccess(agentId, access) {
1263
1212
  const stateDir = getTelegramStateDir(agentId);
@@ -4941,7 +4890,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4941
4890
  const { runner, chatId } = ctx;
4942
4891
  const { sessionId } = req.params;
4943
4892
  try {
4944
- const { result } = await runner.executeApiCommand(sessionId, chatId, '/clear', { skipPersist: true });
4893
+ const { result } = await runner.executeApiCommand(sessionId, chatId, '/clear confirm', { skipPersist: true });
4945
4894
  res.json(result);
4946
4895
  }
4947
4896
  catch (err) {
@@ -4958,7 +4907,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4958
4907
  const { runner, chatId } = ctx;
4959
4908
  const { sessionId } = req.params;
4960
4909
  try {
4961
- const { result } = await runner.executeApiCommand(sessionId, chatId, '/compact', { skipPersist: true });
4910
+ const { result } = await runner.executeApiCommand(sessionId, chatId, '/compact confirm', { skipPersist: true });
4962
4911
  res.json(result);
4963
4912
  }
4964
4913
  catch (err) {
@@ -4992,7 +4941,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4992
4941
  const { runner, chatId } = ctx;
4993
4942
  const { sessionId } = req.params;
4994
4943
  try {
4995
- const { result } = await runner.executeApiCommand(sessionId, chatId, '/restart', { skipPersist: true });
4944
+ const { result } = await runner.executeApiCommand(sessionId, chatId, '/restart confirm', { skipPersist: true });
4996
4945
  res.json(result);
4997
4946
  }
4998
4947
  catch (err) {