lua-cli 3.5.0-beta.1 → 3.6.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 (520) hide show
  1. package/README.md +0 -2
  2. package/dist/api/agent.api.service.d.ts +3 -6
  3. package/dist/api/agent.api.service.d.ts.map +1 -0
  4. package/dist/api/agent.api.service.js.map +1 -1
  5. package/dist/api/auth.api.service.d.ts +1 -0
  6. package/dist/api/auth.api.service.d.ts.map +1 -0
  7. package/dist/api/backup.api.service.d.ts +10 -12
  8. package/dist/api/backup.api.service.d.ts.map +1 -0
  9. package/dist/api/backup.api.service.js +11 -11
  10. package/dist/api/backup.api.service.js.map +1 -1
  11. package/dist/api/basket.api.service.d.ts +1 -0
  12. package/dist/api/basket.api.service.d.ts.map +1 -0
  13. package/dist/api/cdn.api.service.d.ts +1 -0
  14. package/dist/api/cdn.api.service.d.ts.map +1 -0
  15. package/dist/api/cdn.api.service.js.map +1 -1
  16. package/dist/api/chat.api.service.d.ts +1 -0
  17. package/dist/api/chat.api.service.d.ts.map +1 -0
  18. package/dist/api/credentials.d.ts +1 -0
  19. package/dist/api/credentials.d.ts.map +1 -0
  20. package/dist/api/custom.data.api.service.d.ts +1 -0
  21. package/dist/api/custom.data.api.service.d.ts.map +1 -0
  22. package/dist/api/developer.api.service.d.ts +1 -0
  23. package/dist/api/developer.api.service.d.ts.map +1 -0
  24. package/dist/api/http.client.d.ts +1 -0
  25. package/dist/api/http.client.d.ts.map +1 -0
  26. package/dist/api/http.client.js +5 -1
  27. package/dist/api/http.client.js.map +1 -1
  28. package/dist/api/job.api.service.d.ts +1 -0
  29. package/dist/api/job.api.service.d.ts.map +1 -0
  30. package/dist/api/lazy-instances.d.ts +1 -0
  31. package/dist/api/lazy-instances.d.ts.map +1 -0
  32. package/dist/api/logs.api.service.d.ts +1 -0
  33. package/dist/api/logs.api.service.d.ts.map +1 -0
  34. package/dist/api/marketplace.api.service.d.ts +1 -0
  35. package/dist/api/marketplace.api.service.d.ts.map +1 -0
  36. package/dist/api/order.api.service.d.ts +1 -0
  37. package/dist/api/order.api.service.d.ts.map +1 -0
  38. package/dist/api/persona.api.service.d.ts +1 -0
  39. package/dist/api/persona.api.service.d.ts.map +1 -0
  40. package/dist/api/postprocessor.api.service.d.ts +1 -0
  41. package/dist/api/postprocessor.api.service.d.ts.map +1 -0
  42. package/dist/api/preprocessor.api.service.d.ts +1 -0
  43. package/dist/api/preprocessor.api.service.d.ts.map +1 -0
  44. package/dist/api/products.api.service.d.ts +1 -0
  45. package/dist/api/products.api.service.d.ts.map +1 -0
  46. package/dist/api/resource.api.service.d.ts +1 -0
  47. package/dist/api/resource.api.service.d.ts.map +1 -0
  48. package/dist/api/skills.api.service.d.ts +1 -0
  49. package/dist/api/skills.api.service.d.ts.map +1 -0
  50. package/dist/api/tool.api.service.d.ts +1 -0
  51. package/dist/api/tool.api.service.d.ts.map +1 -0
  52. package/dist/api/unifiedto.api.service.d.ts +31 -2
  53. package/dist/api/unifiedto.api.service.d.ts.map +1 -0
  54. package/dist/api/unifiedto.api.service.js +17 -2
  55. package/dist/api/unifiedto.api.service.js.map +1 -1
  56. package/dist/api/user.data.api.service.d.ts +1 -0
  57. package/dist/api/user.data.api.service.d.ts.map +1 -0
  58. package/dist/api/webhook.api.service.d.ts +1 -0
  59. package/dist/api/webhook.api.service.d.ts.map +1 -0
  60. package/dist/api/whatsapp-templates.api.service.d.ts +1 -0
  61. package/dist/api/whatsapp-templates.api.service.d.ts.map +1 -0
  62. package/dist/api-exports.d.ts +3 -2
  63. package/dist/api-exports.d.ts.map +1 -0
  64. package/dist/api-exports.js.map +1 -1
  65. package/dist/cli/command-definitions.d.ts +1 -0
  66. package/dist/cli/command-definitions.d.ts.map +1 -0
  67. package/dist/cli/command-definitions.js +26 -3
  68. package/dist/cli/command-definitions.js.map +1 -1
  69. package/dist/commands/admin.d.ts +1 -0
  70. package/dist/commands/admin.d.ts.map +1 -0
  71. package/dist/commands/admin.js +2 -0
  72. package/dist/commands/admin.js.map +1 -1
  73. package/dist/commands/agents.d.ts +1 -0
  74. package/dist/commands/agents.d.ts.map +1 -0
  75. package/dist/commands/agents.js +7 -0
  76. package/dist/commands/agents.js.map +1 -1
  77. package/dist/commands/apiKey.d.ts +1 -0
  78. package/dist/commands/apiKey.d.ts.map +1 -0
  79. package/dist/commands/apiKey.js +4 -0
  80. package/dist/commands/apiKey.js.map +1 -1
  81. package/dist/commands/channels.d.ts +1 -0
  82. package/dist/commands/channels.d.ts.map +1 -0
  83. package/dist/commands/channels.js +69 -34
  84. package/dist/commands/channels.js.map +1 -1
  85. package/dist/commands/chat.d.ts +1 -0
  86. package/dist/commands/chat.d.ts.map +1 -0
  87. package/dist/commands/chat.js +8 -0
  88. package/dist/commands/chat.js.map +1 -1
  89. package/dist/commands/chatClear.d.ts +1 -0
  90. package/dist/commands/chatClear.d.ts.map +1 -0
  91. package/dist/commands/chatClear.js +2 -0
  92. package/dist/commands/chatClear.js.map +1 -1
  93. package/dist/commands/compile.d.ts +1 -1
  94. package/dist/commands/compile.d.ts.map +1 -0
  95. package/dist/commands/compile.js +35 -11
  96. package/dist/commands/compile.js.map +1 -1
  97. package/dist/commands/completion.d.ts +1 -0
  98. package/dist/commands/completion.d.ts.map +1 -0
  99. package/dist/commands/completion.js +2 -0
  100. package/dist/commands/completion.js.map +1 -1
  101. package/dist/commands/configure.d.ts +1 -0
  102. package/dist/commands/configure.d.ts.map +1 -0
  103. package/dist/commands/configure.js +25 -15
  104. package/dist/commands/configure.js.map +1 -1
  105. package/dist/commands/deploy.d.ts +1 -0
  106. package/dist/commands/deploy.d.ts.map +1 -0
  107. package/dist/commands/deploy.js +11 -0
  108. package/dist/commands/deploy.js.map +1 -1
  109. package/dist/commands/destroy.d.ts +1 -0
  110. package/dist/commands/destroy.d.ts.map +1 -0
  111. package/dist/commands/destroy.js +6 -1
  112. package/dist/commands/destroy.js.map +1 -1
  113. package/dist/commands/dev.d.ts +1 -0
  114. package/dist/commands/dev.d.ts.map +1 -0
  115. package/dist/commands/dev.js +9 -0
  116. package/dist/commands/dev.js.map +1 -1
  117. package/dist/commands/docs.d.ts +1 -0
  118. package/dist/commands/docs.d.ts.map +1 -0
  119. package/dist/commands/docs.js +2 -0
  120. package/dist/commands/docs.js.map +1 -1
  121. package/dist/commands/env.d.ts +1 -0
  122. package/dist/commands/env.d.ts.map +1 -0
  123. package/dist/commands/env.js +6 -0
  124. package/dist/commands/env.js.map +1 -1
  125. package/dist/commands/evals.d.ts +1 -0
  126. package/dist/commands/evals.d.ts.map +1 -0
  127. package/dist/commands/evals.js +2 -0
  128. package/dist/commands/evals.js.map +1 -1
  129. package/dist/commands/features.d.ts +1 -0
  130. package/dist/commands/features.d.ts.map +1 -0
  131. package/dist/commands/features.js +6 -0
  132. package/dist/commands/features.js.map +1 -1
  133. package/dist/commands/index.d.ts +3 -0
  134. package/dist/commands/index.d.ts.map +1 -0
  135. package/dist/commands/index.js +2 -0
  136. package/dist/commands/index.js.map +1 -1
  137. package/dist/commands/init.d.ts +1 -0
  138. package/dist/commands/init.d.ts.map +1 -0
  139. package/dist/commands/init.js +11 -0
  140. package/dist/commands/init.js.map +1 -1
  141. package/dist/commands/integrations.d.ts +1 -0
  142. package/dist/commands/integrations.d.ts.map +1 -0
  143. package/dist/commands/integrations.js +128 -251
  144. package/dist/commands/integrations.js.map +1 -1
  145. package/dist/commands/jobs.d.ts +1 -0
  146. package/dist/commands/jobs.d.ts.map +1 -0
  147. package/dist/commands/jobs.js +6 -0
  148. package/dist/commands/jobs.js.map +1 -1
  149. package/dist/commands/logs.d.ts +1 -0
  150. package/dist/commands/logs.d.ts.map +1 -0
  151. package/dist/commands/logs.js +7 -0
  152. package/dist/commands/logs.js.map +1 -1
  153. package/dist/commands/marketplace.d.ts +1 -0
  154. package/dist/commands/marketplace.d.ts.map +1 -0
  155. package/dist/commands/marketplace.js +6 -0
  156. package/dist/commands/marketplace.js.map +1 -1
  157. package/dist/commands/mcp.d.ts +1 -0
  158. package/dist/commands/mcp.d.ts.map +1 -0
  159. package/dist/commands/mcp.js +6 -0
  160. package/dist/commands/mcp.js.map +1 -1
  161. package/dist/commands/persona.d.ts +1 -0
  162. package/dist/commands/persona.d.ts.map +1 -0
  163. package/dist/commands/persona.js +7 -0
  164. package/dist/commands/persona.js.map +1 -1
  165. package/dist/commands/postprocessors.d.ts +1 -0
  166. package/dist/commands/postprocessors.d.ts.map +1 -0
  167. package/dist/commands/postprocessors.js +6 -0
  168. package/dist/commands/postprocessors.js.map +1 -1
  169. package/dist/commands/preprocessors.d.ts +1 -0
  170. package/dist/commands/preprocessors.d.ts.map +1 -0
  171. package/dist/commands/preprocessors.js +6 -0
  172. package/dist/commands/preprocessors.js.map +1 -1
  173. package/dist/commands/production.d.ts +1 -0
  174. package/dist/commands/production.d.ts.map +1 -0
  175. package/dist/commands/production.js +5 -0
  176. package/dist/commands/production.js.map +1 -1
  177. package/dist/commands/push.d.ts +6 -13
  178. package/dist/commands/push.d.ts.map +1 -0
  179. package/dist/commands/push.js +145 -68
  180. package/dist/commands/push.js.map +1 -1
  181. package/dist/commands/pushBackup.d.ts +4 -2
  182. package/dist/commands/pushBackup.d.ts.map +1 -0
  183. package/dist/commands/pushBackup.js +21 -20
  184. package/dist/commands/pushBackup.js.map +1 -1
  185. package/dist/commands/resources.d.ts +1 -0
  186. package/dist/commands/resources.d.ts.map +1 -0
  187. package/dist/commands/resources.js +6 -0
  188. package/dist/commands/resources.js.map +1 -1
  189. package/dist/commands/skills.d.ts +1 -0
  190. package/dist/commands/skills.d.ts.map +1 -0
  191. package/dist/commands/skills.js +4 -0
  192. package/dist/commands/skills.js.map +1 -1
  193. package/dist/commands/sync.d.ts +1 -0
  194. package/dist/commands/sync.d.ts.map +1 -0
  195. package/dist/commands/sync.js +128 -81
  196. package/dist/commands/sync.js.map +1 -1
  197. package/dist/commands/telemetry.d.ts +6 -0
  198. package/dist/commands/telemetry.d.ts.map +1 -0
  199. package/dist/commands/telemetry.js +38 -0
  200. package/dist/commands/telemetry.js.map +1 -0
  201. package/dist/commands/test.d.ts +1 -0
  202. package/dist/commands/test.d.ts.map +1 -0
  203. package/dist/commands/test.js +7 -0
  204. package/dist/commands/test.js.map +1 -1
  205. package/dist/commands/update.d.ts +14 -0
  206. package/dist/commands/update.d.ts.map +1 -0
  207. package/dist/commands/update.js +85 -0
  208. package/dist/commands/update.js.map +1 -0
  209. package/dist/commands/webhooks.d.ts +1 -0
  210. package/dist/commands/webhooks.d.ts.map +1 -0
  211. package/dist/commands/webhooks.js +6 -0
  212. package/dist/commands/webhooks.js.map +1 -1
  213. package/dist/compiler/agent-traverser.d.ts +30 -28
  214. package/dist/compiler/agent-traverser.d.ts.map +1 -0
  215. package/dist/compiler/agent-traverser.js +62 -54
  216. package/dist/compiler/agent-traverser.js.map +1 -1
  217. package/dist/compiler/bundler.d.ts +2 -1
  218. package/dist/compiler/bundler.d.ts.map +1 -0
  219. package/dist/compiler/bundler.js +2 -1
  220. package/dist/compiler/bundler.js.map +1 -1
  221. package/dist/compiler/compiler.d.ts +1 -2
  222. package/dist/compiler/compiler.d.ts.map +1 -0
  223. package/dist/compiler/compiler.js +11 -24
  224. package/dist/compiler/compiler.js.map +1 -1
  225. package/dist/compiler/index.d.ts +5 -3
  226. package/dist/compiler/index.d.ts.map +1 -0
  227. package/dist/compiler/index.js +3 -2
  228. package/dist/compiler/index.js.map +1 -1
  229. package/dist/compiler/plugins/agent.plugin.d.ts +48 -0
  230. package/dist/compiler/plugins/agent.plugin.d.ts.map +1 -0
  231. package/dist/compiler/plugins/agent.plugin.js +123 -0
  232. package/dist/compiler/plugins/agent.plugin.js.map +1 -0
  233. package/dist/compiler/plugins/base.d.ts +25 -4
  234. package/dist/compiler/plugins/base.d.ts.map +1 -0
  235. package/dist/compiler/plugins/base.js +37 -1
  236. package/dist/compiler/plugins/base.js.map +1 -1
  237. package/dist/compiler/plugins/job.plugin.d.ts +3 -2
  238. package/dist/compiler/plugins/job.plugin.d.ts.map +1 -0
  239. package/dist/compiler/plugins/job.plugin.js +20 -68
  240. package/dist/compiler/plugins/job.plugin.js.map +1 -1
  241. package/dist/compiler/plugins/mcp-server.plugin.d.ts +4 -16
  242. package/dist/compiler/plugins/mcp-server.plugin.d.ts.map +1 -0
  243. package/dist/compiler/plugins/mcp-server.plugin.js +27 -112
  244. package/dist/compiler/plugins/mcp-server.plugin.js.map +1 -1
  245. package/dist/compiler/plugins/postprocessor.plugin.d.ts +3 -2
  246. package/dist/compiler/plugins/postprocessor.plugin.d.ts.map +1 -0
  247. package/dist/compiler/plugins/postprocessor.plugin.js +2 -11
  248. package/dist/compiler/plugins/postprocessor.plugin.js.map +1 -1
  249. package/dist/compiler/plugins/preprocessor.plugin.d.ts +3 -2
  250. package/dist/compiler/plugins/preprocessor.plugin.d.ts.map +1 -0
  251. package/dist/compiler/plugins/preprocessor.plugin.js +5 -18
  252. package/dist/compiler/plugins/preprocessor.plugin.js.map +1 -1
  253. package/dist/compiler/plugins/processor-base.d.ts +1 -0
  254. package/dist/compiler/plugins/processor-base.d.ts.map +1 -0
  255. package/dist/compiler/plugins/processor-base.js +2 -9
  256. package/dist/compiler/plugins/processor-base.js.map +1 -1
  257. package/dist/compiler/plugins/registry.d.ts +1 -0
  258. package/dist/compiler/plugins/registry.d.ts.map +1 -0
  259. package/dist/compiler/plugins/registry.js +2 -0
  260. package/dist/compiler/plugins/registry.js.map +1 -1
  261. package/dist/compiler/plugins/skill.plugin.d.ts +4 -3
  262. package/dist/compiler/plugins/skill.plugin.d.ts.map +1 -0
  263. package/dist/compiler/plugins/skill.plugin.js +44 -41
  264. package/dist/compiler/plugins/skill.plugin.js.map +1 -1
  265. package/dist/compiler/plugins/tool.plugin.d.ts +4 -2
  266. package/dist/compiler/plugins/tool.plugin.d.ts.map +1 -0
  267. package/dist/compiler/plugins/tool.plugin.js +10 -31
  268. package/dist/compiler/plugins/tool.plugin.js.map +1 -1
  269. package/dist/compiler/plugins/webhook.plugin.d.ts +3 -2
  270. package/dist/compiler/plugins/webhook.plugin.d.ts.map +1 -0
  271. package/dist/compiler/plugins/webhook.plugin.js +12 -24
  272. package/dist/compiler/plugins/webhook.plugin.js.map +1 -1
  273. package/dist/compiler/source-writer.d.ts +10 -0
  274. package/dist/compiler/source-writer.d.ts.map +1 -0
  275. package/dist/compiler/source-writer.js +11 -0
  276. package/dist/compiler/source-writer.js.map +1 -1
  277. package/dist/compiler/types.d.ts +32 -14
  278. package/dist/compiler/types.d.ts.map +1 -0
  279. package/dist/compiler/types.js +8 -0
  280. package/dist/compiler/types.js.map +1 -1
  281. package/dist/compiler/utils/ast-helpers.d.ts +70 -17
  282. package/dist/compiler/utils/ast-helpers.d.ts.map +1 -0
  283. package/dist/compiler/utils/ast-helpers.js +250 -61
  284. package/dist/compiler/utils/ast-helpers.js.map +1 -1
  285. package/dist/compiler/utils/common.d.ts +1 -0
  286. package/dist/compiler/utils/common.d.ts.map +1 -0
  287. package/dist/compiler/utils/file-discovery.d.ts +1 -0
  288. package/dist/compiler/utils/file-discovery.d.ts.map +1 -0
  289. package/dist/compiler/utils/path-resolver.d.ts +1 -0
  290. package/dist/compiler/utils/path-resolver.d.ts.map +1 -0
  291. package/dist/compiler/utils/schema-converter.d.ts +1 -0
  292. package/dist/compiler/utils/schema-converter.d.ts.map +1 -0
  293. package/dist/config/compile.constants.d.ts +27 -0
  294. package/dist/config/compile.constants.d.ts.map +1 -0
  295. package/dist/config/compile.constants.js +44 -0
  296. package/dist/config/compile.constants.js.map +1 -1
  297. package/dist/config/constants.d.ts +21 -0
  298. package/dist/config/constants.d.ts.map +1 -0
  299. package/dist/config/constants.js +31 -0
  300. package/dist/config/constants.js.map +1 -1
  301. package/dist/config/dev.constants.d.ts +1 -0
  302. package/dist/config/dev.constants.d.ts.map +1 -0
  303. package/dist/errors/auth.error.d.ts +1 -0
  304. package/dist/errors/auth.error.d.ts.map +1 -0
  305. package/dist/errors/index.d.ts +1 -0
  306. package/dist/errors/index.d.ts.map +1 -0
  307. package/dist/index.d.ts +1 -0
  308. package/dist/index.d.ts.map +1 -0
  309. package/dist/index.js +22 -20
  310. package/dist/index.js.map +1 -1
  311. package/dist/instances/basket.instance.d.ts +1 -0
  312. package/dist/instances/basket.instance.d.ts.map +1 -0
  313. package/dist/instances/data.entry.instance.d.ts +1 -0
  314. package/dist/instances/data.entry.instance.d.ts.map +1 -0
  315. package/dist/instances/job.instance.d.ts +1 -0
  316. package/dist/instances/job.instance.d.ts.map +1 -0
  317. package/dist/instances/order.instance.d.ts +1 -0
  318. package/dist/instances/order.instance.d.ts.map +1 -0
  319. package/dist/instances/product.instance.d.ts +1 -0
  320. package/dist/instances/product.instance.d.ts.map +1 -0
  321. package/dist/instances/product.pagination.instance.d.ts +1 -0
  322. package/dist/instances/product.pagination.instance.d.ts.map +1 -0
  323. package/dist/instances/product.search.instance.d.ts +1 -0
  324. package/dist/instances/product.search.instance.d.ts.map +1 -0
  325. package/dist/instances/user.instance.d.ts +1 -0
  326. package/dist/instances/user.instance.d.ts.map +1 -0
  327. package/dist/interfaces/admin.d.ts +1 -0
  328. package/dist/interfaces/admin.d.ts.map +1 -0
  329. package/dist/interfaces/agent.d.ts +36 -5
  330. package/dist/interfaces/agent.d.ts.map +1 -0
  331. package/dist/interfaces/backup.d.ts +1 -25
  332. package/dist/interfaces/backup.d.ts.map +1 -0
  333. package/dist/interfaces/baskets.d.ts +1 -0
  334. package/dist/interfaces/baskets.d.ts.map +1 -0
  335. package/dist/interfaces/cdn.d.ts +1 -0
  336. package/dist/interfaces/cdn.d.ts.map +1 -0
  337. package/dist/interfaces/chat.d.ts +1 -0
  338. package/dist/interfaces/chat.d.ts.map +1 -0
  339. package/dist/interfaces/common.d.ts +1 -0
  340. package/dist/interfaces/common.d.ts.map +1 -0
  341. package/dist/interfaces/custom.data.d.ts +1 -0
  342. package/dist/interfaces/custom.data.d.ts.map +1 -0
  343. package/dist/interfaces/deploy.d.ts +1 -0
  344. package/dist/interfaces/deploy.d.ts.map +1 -0
  345. package/dist/interfaces/dev.d.ts +1 -0
  346. package/dist/interfaces/dev.d.ts.map +1 -0
  347. package/dist/interfaces/index.d.ts +1 -0
  348. package/dist/interfaces/index.d.ts.map +1 -0
  349. package/dist/interfaces/init.d.ts +1 -0
  350. package/dist/interfaces/init.d.ts.map +1 -0
  351. package/dist/interfaces/jobs.d.ts +1 -0
  352. package/dist/interfaces/jobs.d.ts.map +1 -0
  353. package/dist/interfaces/logs.d.ts +1 -0
  354. package/dist/interfaces/logs.d.ts.map +1 -0
  355. package/dist/interfaces/lua.d.ts +1 -0
  356. package/dist/interfaces/lua.d.ts.map +1 -0
  357. package/dist/interfaces/marketplace.d.ts +1 -0
  358. package/dist/interfaces/marketplace.d.ts.map +1 -0
  359. package/dist/interfaces/mcp.d.ts +1 -0
  360. package/dist/interfaces/mcp.d.ts.map +1 -0
  361. package/dist/interfaces/message.d.ts +1 -0
  362. package/dist/interfaces/message.d.ts.map +1 -0
  363. package/dist/interfaces/orders.d.ts +1 -0
  364. package/dist/interfaces/orders.d.ts.map +1 -0
  365. package/dist/interfaces/persona.d.ts +1 -0
  366. package/dist/interfaces/persona.d.ts.map +1 -0
  367. package/dist/interfaces/postprocessors.d.ts +1 -0
  368. package/dist/interfaces/postprocessors.d.ts.map +1 -0
  369. package/dist/interfaces/preprocessors.d.ts +1 -0
  370. package/dist/interfaces/preprocessors.d.ts.map +1 -0
  371. package/dist/interfaces/product.d.ts +1 -0
  372. package/dist/interfaces/product.d.ts.map +1 -0
  373. package/dist/interfaces/push.d.ts +1 -0
  374. package/dist/interfaces/push.d.ts.map +1 -0
  375. package/dist/interfaces/skills.d.ts +1 -0
  376. package/dist/interfaces/skills.d.ts.map +1 -0
  377. package/dist/interfaces/test.d.ts +1 -0
  378. package/dist/interfaces/test.d.ts.map +1 -0
  379. package/dist/interfaces/unifiedto.d.ts +27 -0
  380. package/dist/interfaces/unifiedto.d.ts.map +1 -0
  381. package/dist/interfaces/user.d.ts +1 -0
  382. package/dist/interfaces/user.d.ts.map +1 -0
  383. package/dist/interfaces/webhooks.d.ts +1 -0
  384. package/dist/interfaces/webhooks.d.ts.map +1 -0
  385. package/dist/interfaces/whatsapp-templates.d.ts +1 -0
  386. package/dist/interfaces/whatsapp-templates.d.ts.map +1 -0
  387. package/dist/primitives/agent.handler.d.ts +61 -0
  388. package/dist/primitives/agent.handler.d.ts.map +1 -0
  389. package/dist/primitives/agent.handler.js +142 -0
  390. package/dist/primitives/agent.handler.js.map +1 -0
  391. package/dist/primitives/base.handler.d.ts +46 -6
  392. package/dist/primitives/base.handler.d.ts.map +1 -0
  393. package/dist/primitives/base.handler.js +121 -17
  394. package/dist/primitives/base.handler.js.map +1 -1
  395. package/dist/primitives/index.d.ts +5 -5
  396. package/dist/primitives/index.d.ts.map +1 -0
  397. package/dist/primitives/index.js +7 -17
  398. package/dist/primitives/index.js.map +1 -1
  399. package/dist/primitives/job.handler.d.ts +1 -5
  400. package/dist/primitives/job.handler.d.ts.map +1 -0
  401. package/dist/primitives/job.handler.js +1 -15
  402. package/dist/primitives/job.handler.js.map +1 -1
  403. package/dist/primitives/mcp-server.handler.d.ts +5 -1
  404. package/dist/primitives/mcp-server.handler.d.ts.map +1 -0
  405. package/dist/primitives/mcp-server.handler.js +26 -6
  406. package/dist/primitives/mcp-server.handler.js.map +1 -1
  407. package/dist/primitives/postprocessor.handler.d.ts +1 -11
  408. package/dist/primitives/postprocessor.handler.d.ts.map +1 -0
  409. package/dist/primitives/postprocessor.handler.js +1 -24
  410. package/dist/primitives/postprocessor.handler.js.map +1 -1
  411. package/dist/primitives/preprocessor.handler.d.ts +1 -11
  412. package/dist/primitives/preprocessor.handler.d.ts.map +1 -0
  413. package/dist/primitives/preprocessor.handler.js +1 -24
  414. package/dist/primitives/preprocessor.handler.js.map +1 -1
  415. package/dist/primitives/skill.handler.d.ts +4 -1
  416. package/dist/primitives/skill.handler.d.ts.map +1 -0
  417. package/dist/primitives/skill.handler.js +10 -29
  418. package/dist/primitives/skill.handler.js.map +1 -1
  419. package/dist/primitives/types.d.ts +19 -0
  420. package/dist/primitives/types.d.ts.map +1 -0
  421. package/dist/primitives/types.js.map +1 -1
  422. package/dist/primitives/webhook.handler.d.ts +1 -5
  423. package/dist/primitives/webhook.handler.d.ts.map +1 -0
  424. package/dist/primitives/webhook.handler.js +1 -15
  425. package/dist/primitives/webhook.handler.js.map +1 -1
  426. package/dist/services/analytics.d.ts +51 -0
  427. package/dist/services/analytics.d.ts.map +1 -0
  428. package/dist/services/analytics.js +293 -0
  429. package/dist/services/analytics.js.map +1 -0
  430. package/dist/services/auth.d.ts +1 -0
  431. package/dist/services/auth.d.ts.map +1 -0
  432. package/dist/services/sandbox.service.d.ts +1 -0
  433. package/dist/services/sandbox.service.d.ts.map +1 -0
  434. package/dist/types/api-contracts.d.ts +1 -0
  435. package/dist/types/api-contracts.d.ts.map +1 -0
  436. package/dist/types/index.d.ts +2 -1
  437. package/dist/types/index.d.ts.map +1 -0
  438. package/dist/types/skill.d.ts +28 -0
  439. package/dist/types/skill.d.ts.map +1 -0
  440. package/dist/types/skill.js +5 -0
  441. package/dist/types/skill.js.map +1 -1
  442. package/dist/types/tool-validation.d.ts +1 -0
  443. package/dist/types/tool-validation.d.ts.map +1 -0
  444. package/dist/types/yaml.types.d.ts +1 -0
  445. package/dist/types/yaml.types.d.ts.map +1 -0
  446. package/dist/utils/artifact-loader.d.ts +5 -10
  447. package/dist/utils/artifact-loader.d.ts.map +1 -0
  448. package/dist/utils/artifact-loader.js +17 -16
  449. package/dist/utils/artifact-loader.js.map +1 -1
  450. package/dist/utils/auth-flows.d.ts +1 -0
  451. package/dist/utils/auth-flows.d.ts.map +1 -0
  452. package/dist/utils/backup-helpers.d.ts +10 -7
  453. package/dist/utils/backup-helpers.d.ts.map +1 -0
  454. package/dist/utils/backup-helpers.js +54 -22
  455. package/dist/utils/backup-helpers.js.map +1 -1
  456. package/dist/utils/cli.d.ts +3 -1
  457. package/dist/utils/cli.d.ts.map +1 -0
  458. package/dist/utils/cli.js +74 -6
  459. package/dist/utils/cli.js.map +1 -1
  460. package/dist/utils/command-utils.d.ts +13 -10
  461. package/dist/utils/command-utils.d.ts.map +1 -0
  462. package/dist/utils/command-utils.js +19 -17
  463. package/dist/utils/command-utils.js.map +1 -1
  464. package/dist/utils/deploy-helpers.d.ts +1 -0
  465. package/dist/utils/deploy-helpers.d.ts.map +1 -0
  466. package/dist/utils/dev-api.d.ts +1 -0
  467. package/dist/utils/dev-api.d.ts.map +1 -0
  468. package/dist/utils/dev-server.d.ts +1 -0
  469. package/dist/utils/dev-server.d.ts.map +1 -0
  470. package/dist/utils/dev-watcher.d.ts +1 -0
  471. package/dist/utils/dev-watcher.d.ts.map +1 -0
  472. package/dist/utils/env-loader.utils.d.ts +1 -0
  473. package/dist/utils/env-loader.utils.d.ts.map +1 -0
  474. package/dist/utils/files.d.ts +11 -0
  475. package/dist/utils/files.d.ts.map +1 -0
  476. package/dist/utils/files.js +34 -0
  477. package/dist/utils/files.js.map +1 -1
  478. package/dist/utils/init-agent.d.ts +1 -0
  479. package/dist/utils/init-agent.d.ts.map +1 -0
  480. package/dist/utils/init-helpers.d.ts +1 -0
  481. package/dist/utils/init-helpers.d.ts.map +1 -0
  482. package/dist/utils/init-prompts.d.ts +1 -0
  483. package/dist/utils/init-prompts.d.ts.map +1 -0
  484. package/dist/utils/prompt-handler.d.ts +1 -0
  485. package/dist/utils/prompt-handler.d.ts.map +1 -0
  486. package/dist/utils/sandbox-storage.d.ts +1 -0
  487. package/dist/utils/sandbox-storage.d.ts.map +1 -0
  488. package/dist/utils/sandbox.d.ts +1 -0
  489. package/dist/utils/sandbox.d.ts.map +1 -0
  490. package/dist/utils/sandbox.js +3 -20
  491. package/dist/utils/sandbox.js.map +1 -1
  492. package/dist/utils/semver.d.ts +1 -0
  493. package/dist/utils/semver.d.ts.map +1 -0
  494. package/dist/utils/sync-display.d.ts +2 -0
  495. package/dist/utils/sync-display.d.ts.map +1 -0
  496. package/dist/utils/sync-display.js +8 -0
  497. package/dist/utils/sync-display.js.map +1 -1
  498. package/dist/utils/sync-fetch.d.ts +8 -0
  499. package/dist/utils/sync-fetch.d.ts.map +1 -0
  500. package/dist/utils/sync-fetch.js +23 -3
  501. package/dist/utils/sync-fetch.js.map +1 -1
  502. package/dist/utils/sync-helpers.d.ts +3 -2
  503. package/dist/utils/sync-helpers.d.ts.map +1 -0
  504. package/dist/utils/sync-helpers.js +2 -2
  505. package/dist/utils/sync-helpers.js.map +1 -1
  506. package/dist/utils/version-check.d.ts +37 -0
  507. package/dist/utils/version-check.d.ts.map +1 -0
  508. package/dist/utils/version-check.js +117 -0
  509. package/dist/utils/version-check.js.map +1 -0
  510. package/dist/web/app.css +401 -2172
  511. package/dist/web/app.js +105 -93
  512. package/docs/API_REFERENCE.md +0 -3
  513. package/docs/CLI_REFERENCE.md +1 -4
  514. package/docs/GETTING_STARTED.md +1 -4
  515. package/docs/README.md +3 -3
  516. package/docs/api/LuaAgent.md +29 -6
  517. package/package.json +17 -12
  518. package/template/.gitignore +21 -0
  519. package/template/package.json +1 -1
  520. package/template/package-lock.json +0 -7895
@@ -24,23 +24,23 @@ import { initializeCommand } from '../utils/command-utils.js';
24
24
  import DeveloperApi from '../api/developer.api.service.js';
25
25
  import UnifiedToApi from '../api/unifiedto.api.service.js';
26
26
  import { fetchServersCore, activateServerCore, deactivateServerCore, } from './mcp.js';
27
+ import { trackEvent } from '../services/analytics.js';
27
28
  // ─────────────────────────────────────────────────────────────────────────────
28
29
  // Configuration
29
30
  // ─────────────────────────────────────────────────────────────────────────────
30
- const UNIFIED_MCP_BASE_URL = 'https://mcp-api.unified.to/mcp';
31
31
  const CALLBACK_PORT = 19837; // Random high port for OAuth callback
32
32
  const CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`;
33
- // Webhook trigger configuration
33
+ // Webhook trigger configuration (AGENT_WEBHOOK_URL still used for display/info commands)
34
34
  const AGENT_WEBHOOK_URL = `${BASE_URLS.API}/webhook/unifiedto/data`;
35
- const DEFAULT_VIRTUAL_WEBHOOK_INTERVAL = 60; // minutes
35
+ const DEFAULT_VIRTUAL_WEBHOOK_INTERVAL = 1; // minutes (paid Unified.to plan)
36
36
  // ─────────────────────────────────────────────────────────────────────────────
37
37
  // Integration API Functions (via Lua API)
38
38
  // ─────────────────────────────────────────────────────────────────────────────
39
39
  /**
40
40
  * Fetches available (activated) integrations via Lua API
41
41
  */
42
- async function fetchAvailableIntegrations(unifiedToApi) {
43
- const result = await unifiedToApi.getAvailableIntegrations();
42
+ async function fetchAvailableIntegrations(unifiedToApi, agentId) {
43
+ const result = await unifiedToApi.getAvailableIntegrations(agentId);
44
44
  if (!result.success || !result.data) {
45
45
  throw new Error(`Failed to fetch integrations: ${result.error?.message || 'Unknown error'}`);
46
46
  }
@@ -68,26 +68,31 @@ function startCallbackServer(timeoutMs = 300000) {
68
68
  if (reqUrl.pathname === '/callback') {
69
69
  const connectionId = reqUrl.searchParams.get('id');
70
70
  const error = reqUrl.searchParams.get('error');
71
+ const logId = reqUrl.searchParams.get('log_id');
71
72
  const integrationType = reqUrl.searchParams.get('type');
72
73
  resolved = true;
73
74
  if (error) {
74
- // Send error page
75
+ // Unified.to redirects to failure_redirect with ?error=<oauth_error>&log_id=<trace_id>
76
+ const logIdHtml = logId
77
+ ? `<p style="color: #888; font-size: 0.85em;">Log ID: <code>${logId}</code></p>`
78
+ : '';
75
79
  res.writeHead(200, { 'Content-Type': 'text/html' });
76
80
  res.end(`
77
81
  <!DOCTYPE html>
78
82
  <html>
79
83
  <head><title>Connection Failed</title></head>
80
84
  <body style="font-family: system-ui; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #1a1a2e;">
81
- <div style="text-align: center; color: white;">
82
- <h1 style="color: #ff6b6b;">āŒ Connection Failed</h1>
85
+ <div style="text-align: center; color: white; max-width: 500px; padding: 0 20px;">
86
+ <h1 style="color: #ff6b6b;">Connection Failed</h1>
83
87
  <p style="color: #ccc;">Error: ${error}</p>
88
+ ${logIdHtml}
84
89
  <p style="color: #888;">You can close this window and try again.</p>
85
90
  </div>
86
91
  </body>
87
92
  </html>
88
93
  `);
89
94
  server.close();
90
- resolve({ success: false, error });
95
+ resolve({ success: false, error, logId: logId || undefined });
91
96
  }
92
97
  else if (connectionId) {
93
98
  // Send success page
@@ -137,7 +142,7 @@ function startCallbackServer(timeoutMs = 300000) {
137
142
  export async function integrationsCommand(action, subaction, cmdObj) {
138
143
  return withErrorHandling(async () => {
139
144
  // Initialize command (validates config + auth)
140
- const { agentId, apiKey, userData } = await initializeCommand({ showProgress: false });
145
+ const { agentId, apiKey, userData } = await initializeCommand({ showProgress: false, validateAuth: true });
141
146
  const userId = userData?.admin?.userId;
142
147
  if (!userId) {
143
148
  console.error("āŒ Failed to get user ID from authentication.");
@@ -160,6 +165,12 @@ export async function integrationsCommand(action, subaction, cmdObj) {
160
165
  else {
161
166
  await interactiveIntegrationsManagement(context);
162
167
  }
168
+ trackEvent('cli_integration_action', {
169
+ action: action || 'interactive',
170
+ sub_action: subaction || null,
171
+ integration_type: cmdObj?.integration || null,
172
+ non_interactive: !!action,
173
+ });
163
174
  }, "integrations");
164
175
  }
165
176
  // ─────────────────────────────────────────────────────────────────────────────
@@ -456,32 +467,18 @@ async function showIntegrationInfo(context, integrationType, jsonOutput = false)
456
467
  // Connect Flow
457
468
  // ─────────────────────────────────────────────────────────────────────────────
458
469
  async function connectIntegrationFlow(context, options = {}) {
459
- // Step 1: Fetch available integrations and existing connections
470
+ // Step 1: Fetch available integrations (API excludes already-connected types)
460
471
  writeProgress("šŸ”„ Fetching integrations...");
461
- let integrations;
462
- let existingConnections = [];
472
+ let availableIntegrations;
463
473
  try {
464
- const [integrationsResult, connectionsResult] = await Promise.all([
465
- fetchAvailableIntegrations(context.unifiedToApi),
466
- context.unifiedToApi.getConnections(context.agentId)
467
- ]);
468
- integrations = integrationsResult;
469
- existingConnections = connectionsResult.success ? connectionsResult.data || [] : [];
474
+ availableIntegrations = await fetchAvailableIntegrations(context.unifiedToApi, context.agentId);
470
475
  }
471
476
  catch (error) {
472
477
  writeError(`āŒ Failed to fetch integrations: ${error.message}`);
473
478
  return;
474
479
  }
475
- if (integrations.length === 0) {
476
- writeError("āŒ No integrations available.");
477
- console.log("šŸ’” Contact support to enable integrations for your workspace.\n");
478
- return;
479
- }
480
- // Filter out integrations that already have a connection (1 connection per integration type)
481
- const connectedTypes = new Set(existingConnections.map(c => c.integrationType));
482
- const availableIntegrations = integrations.filter(i => !connectedTypes.has(i.value));
483
480
  if (availableIntegrations.length === 0) {
484
- writeInfo("All available integrations are already connected.");
481
+ writeInfo("All available integrations are already connected (or none are enabled).");
485
482
  console.log("šŸ’” Use 'lua integrations update' to change scopes on an existing connection.\n");
486
483
  return;
487
484
  }
@@ -489,17 +486,15 @@ async function connectIntegrationFlow(context, options = {}) {
489
486
  // Step 2: Select integration (with search/filter support)
490
487
  let selectedIntegration;
491
488
  if (options.integration) {
492
- // Check if already connected
493
- if (connectedTypes.has(options.integration)) {
494
- console.error(`āŒ Integration "${options.integration}" is already connected.`);
495
- console.log("šŸ’” Use 'lua integrations update --integration " + options.integration + "' to change scopes.\n");
496
- throw new Error("Integration");
497
- }
498
489
  selectedIntegration = availableIntegrations.find(i => i.value === options.integration);
499
490
  if (!selectedIntegration) {
500
- console.error(`āŒ Integration "${options.integration}" not found or not available.`);
501
- console.log('\nAvailable integrations to connect:');
502
- availableIntegrations.forEach(i => console.log(` - ${i.value} (${i.name})`));
491
+ // Not in available list — either already connected or doesn't exist
492
+ console.error(`āŒ Integration "${options.integration}" not found or already connected.`);
493
+ console.log("šŸ’” If already connected, use 'lua integrations update --integration " + options.integration + "' to change scopes.");
494
+ if (availableIntegrations.length > 0) {
495
+ console.log('\nAvailable integrations to connect:');
496
+ availableIntegrations.forEach(i => console.log(` - ${i.value} (${i.name})`));
497
+ }
503
498
  throw new Error("Integration");
504
499
  }
505
500
  }
@@ -522,16 +517,8 @@ async function connectIntegrationFlow(context, options = {}) {
522
517
  i.value.toLowerCase().includes(searchLower) ||
523
518
  i.categories.some(c => c.toLowerCase().includes(searchLower)));
524
519
  if (filteredIntegrations.length === 0) {
525
- // Check if the search matches an already-connected integration
526
- const matchingConnected = existingConnections.filter(c => c.integrationType.toLowerCase().includes(searchLower) ||
527
- (c.integrationName && c.integrationName.toLowerCase().includes(searchLower)));
528
- if (matchingConnected.length > 0) {
529
- const connectedName = matchingConnected[0].integrationName || matchingConnected[0].integrationType;
530
- writeInfo(`"${connectedName}" is already connected.`);
531
- console.log(`šŸ’” Use 'lua integrations update' to change scopes.\n`);
532
- return;
533
- }
534
- writeInfo(`No integrations found matching "${searchAnswer.searchTerm}"`);
520
+ writeInfo(`No available integrations found matching "${searchAnswer.searchTerm}"`);
521
+ console.log(`šŸ’” If the integration is already connected, use 'lua integrations update' to change scopes.`);
535
522
  // Offer to browse all
536
523
  const browseAnswer = await safePrompt([
537
524
  {
@@ -858,7 +845,7 @@ async function connectIntegrationFlow(context, options = {}) {
858
845
  });
859
846
  const authUrlResult = await context.unifiedToApi.getAuthUrl(selectedIntegration.value, {
860
847
  successRedirect: CALLBACK_URL,
861
- failureRedirect: `${CALLBACK_URL}?error=auth_failed`,
848
+ failureRedirect: CALLBACK_URL,
862
849
  scopes: authMethod === 'oauth' ? selectedScopes : undefined,
863
850
  state,
864
851
  externalXref, // Contains both agentId and userId as JSON
@@ -867,36 +854,19 @@ async function connectIntegrationFlow(context, options = {}) {
867
854
  writeError(`āŒ Failed to get authorization URL: ${authUrlResult.error?.message || 'Unknown error'}`);
868
855
  return;
869
856
  }
857
+ // Auth URL is already resolved by the API (redirect wrappers followed server-side)
870
858
  const authUrl = authUrlResult.data.authUrl;
871
- // Step 4: Pre-fetch the auth URL to handle redirects
872
- let finalAuthUrl = authUrl;
873
- try {
874
- const response = await fetch(authUrl);
875
- const responseText = await response.text();
876
- if (responseText.includes('test.html?redirect=')) {
877
- const urlMatch = responseText.match(/redirect=([^&\s]+)/);
878
- if (urlMatch) {
879
- finalAuthUrl = decodeURIComponent(urlMatch[1]);
880
- }
881
- }
882
- else if (responseText.startsWith('https://')) {
883
- finalAuthUrl = responseText.trim();
884
- }
885
- }
886
- catch (error) {
887
- // Use original auth URL if pre-fetch fails
888
- }
889
- // Step 5: Start callback server and open browser
859
+ // Step 4: Start callback server and open browser
890
860
  console.log("\n" + "─".repeat(60));
891
861
  console.log("🌐 Starting OAuth authorization flow...");
892
862
  console.log("─".repeat(60));
893
863
  console.log(`\nIntegration: ${selectedIntegration.name}`);
894
- console.log(`\nšŸ“‹ Authorization URL (copy if browser doesn't open):\n ${finalAuthUrl}\n`);
864
+ console.log(`\nšŸ“‹ Authorization URL (copy if browser doesn't open):\n ${authUrl}\n`);
895
865
  // Start the callback server
896
866
  const callbackPromise = startCallbackServer(300000); // 5 minute timeout
897
867
  // Auto-open browser
898
868
  try {
899
- await open(finalAuthUrl);
869
+ await open(authUrl);
900
870
  writeInfo("🌐 Browser opened - please complete the authorization");
901
871
  }
902
872
  catch (error) {
@@ -917,93 +887,48 @@ async function connectIntegrationFlow(context, options = {}) {
917
887
  }
918
888
  else {
919
889
  writeError(`\nāŒ Authorization failed: ${result.error || 'Unknown error'}`);
890
+ if (result.logId) {
891
+ console.log(` Log ID: ${result.logId}`);
892
+ }
893
+ // Report auth failure for observability (fire and forget)
894
+ context.unifiedToApi.reportAuthFailure({
895
+ integrationType: selectedIntegration.value,
896
+ error: result.error || 'Unknown OAuth failure',
897
+ logId: result.logId,
898
+ agentId: context.agentId,
899
+ source: 'cli',
900
+ }).catch(() => { });
920
901
  console.log("šŸ’” Please try again with 'lua integrations connect'\n");
921
902
  }
922
903
  }
923
904
  /**
924
- * Finalizes a new connection by setting up the MCP server and creating webhooks
925
- * The MCP server enables the agent to use tools from this connection
926
- * Webhooks enable the agent to be triggered by events from the connection
905
+ * Finalizes a new connection by calling the API to atomically set up MCP server and webhooks
906
+ * The API handles: MCP URL construction, upsert, activation, and webhook creation
927
907
  */
928
908
  async function finalizeConnection(context, integration, connectionId, scopes, hideSensitive = true, webhookConfig = { triggers: [], webhookUrl: '', isCustomWebhook: false }) {
929
909
  writeProgress(`šŸ”„ Setting up ${integration.name} connection...`);
930
- // Build MCP URL
931
- let mcpUrl = `${UNIFIED_MCP_BASE_URL}?connection=${connectionId}`;
932
- if (hideSensitive) {
933
- mcpUrl += '&hide_sensitive=true';
934
- }
935
- if (scopes.length > 0) {
936
- mcpUrl += `&permissions=${scopes.join(',')}`;
937
- }
938
- // Always defer tools to reduce initial tool loading overhead with LLMs
939
- mcpUrl += '&defer_tools=true';
940
- // Use simple integration type as name (e.g., 'discord', 'linear')
941
- // This makes tool names cleaner: discord_create_message vs unified-discord-abc123_create_message
942
- const serverName = integration.value;
943
- const mcpServerData = {
944
- name: serverName,
945
- transport: 'streamable-http',
946
- url: mcpUrl,
947
- source: 'unifiedto', // Flag for runtime auth injection
948
- timeout: 30000,
949
- };
950
- // ─────────────────────────────────────────────────────────────────────────
951
- // Step 1: Set up MCP Server (for tools)
952
- // ─────────────────────────────────────────────────────────────────────────
953
- let mcpSetupSuccess = false;
954
- let isActive = false;
955
- let mcpError = null;
956
- try {
957
- writeProgress(`šŸ”„ Setting up MCP server...`);
958
- const result = await context.developerApi.createMCPServer(mcpServerData);
959
- if (result.success && result.data) {
960
- // Auto-activate the MCP server so the agent can use the connection immediately
961
- const activateResult = await context.developerApi.activateMCPServer(result.data.id);
962
- isActive = activateResult.success && activateResult.data?.active === true;
963
- mcpSetupSuccess = true;
964
- }
965
- else {
966
- mcpError = result.error?.message || 'Unknown error';
967
- }
968
- }
969
- catch (error) {
970
- mcpError = error.message || 'Unknown error';
971
- }
972
- // ─────────────────────────────────────────────────────────────────────────
973
- // Step 2: Set up Webhook Triggers (for event-driven agent wake-up)
974
- // ─────────────────────────────────────────────────────────────────────────
975
- const createdWebhooks = [];
976
- const failedWebhooks = [];
977
- if (webhookConfig.triggers.length > 0) {
978
- writeProgress(`šŸ”„ Setting up ${webhookConfig.triggers.length} trigger(s)...`);
979
- for (const trigger of webhookConfig.triggers) {
980
- try {
981
- // Use per-trigger hookUrl/interval if available, otherwise fall back to defaults
982
- const hookUrl = trigger.hookUrl || webhookConfig.webhookUrl || AGENT_WEBHOOK_URL;
983
- const interval = trigger.interval ?? (trigger.webhookType === 'virtual' ? DEFAULT_VIRTUAL_WEBHOOK_INTERVAL : undefined);
984
- const webhookResult = await context.unifiedToApi.createWebhookSubscription(context.agentId, {
985
- connectionId,
986
- objectType: trigger.objectType,
987
- event: trigger.event,
988
- hookUrl,
989
- interval,
990
- });
991
- if (webhookResult.success && webhookResult.data) {
992
- createdWebhooks.push(webhookResult.data);
993
- }
994
- else {
995
- const errorMsg = webhookResult.error?.message || 'Unknown error';
996
- failedWebhooks.push(`${trigger.objectType}.${trigger.event}: ${errorMsg}`);
997
- }
998
- }
999
- catch (error) {
1000
- const errorMsg = error?.message || 'Unknown error';
1001
- failedWebhooks.push(`${trigger.objectType}.${trigger.event}: ${errorMsg}`);
1002
- }
1003
- }
910
+ // Build trigger params for the API (include per-trigger hookUrl/interval if set)
911
+ const triggers = webhookConfig.triggers.map(t => ({
912
+ objectType: t.objectType,
913
+ event: t.event,
914
+ hookUrl: t.hookUrl || (webhookConfig.isCustomWebhook ? webhookConfig.webhookUrl : undefined),
915
+ interval: t.interval,
916
+ }));
917
+ // Single API call replaces: MCP URL build + upsert + activate + N webhook creates
918
+ const result = await context.unifiedToApi.finalizeConnection(context.agentId, {
919
+ connectionId,
920
+ integrationType: integration.value,
921
+ scopes: scopes.length > 0 ? scopes : undefined,
922
+ hideSensitive,
923
+ triggers: triggers.length > 0 ? triggers : undefined,
924
+ });
925
+ if (!result.success || !result.data) {
926
+ writeError(`āŒ Failed to finalize connection: ${result.error?.message || 'Unknown error'}`);
927
+ return;
1004
928
  }
929
+ const { mcpServer, webhooks, failedWebhooks } = result.data;
1005
930
  // ─────────────────────────────────────────────────────────────────────────
1006
- // Step 3: Display Results
931
+ // Display Results
1007
932
  // ─────────────────────────────────────────────────────────────────────────
1008
933
  console.log("\n" + "─".repeat(60));
1009
934
  console.log("šŸŽ‰ Connection Established!");
@@ -1012,15 +937,9 @@ async function finalizeConnection(context, integration, connectionId, scopes, hi
1012
937
  console.log(` Connection ID: ${connectionId}`);
1013
938
  // MCP Server status
1014
939
  console.log(`\n šŸ“¦ MCP Server (Tools):`);
1015
- if (mcpSetupSuccess) {
1016
- console.log(` Status: ${isActive ? '🟢 Active' : '🟔 Pending activation'}`);
1017
- console.log(` Name: ${serverName}`);
1018
- console.log(` Hide Sensitive: ${hideSensitive ? 'āœ… Yes' : 'āŒ No'}`);
1019
- }
1020
- else {
1021
- console.log(` Status: āŒ Failed`);
1022
- console.log(` Error: ${mcpError}`);
1023
- }
940
+ console.log(` Status: ${mcpServer.active ? '🟢 Active' : '🟔 Pending activation'}`);
941
+ console.log(` Name: ${mcpServer.name}`);
942
+ console.log(` Hide Sensitive: ${hideSensitive ? 'āœ… Yes' : 'āŒ No'}`);
1024
943
  // Show requested scopes with friendly labels
1025
944
  if (scopes.length > 0) {
1026
945
  console.log(`\n šŸ”‘ Permissions (${scopes.length}):`);
@@ -1038,83 +957,56 @@ async function finalizeConnection(context, integration, connectionId, scopes, hi
1038
957
  console.log(`\n šŸ”‘ Permissions: Default`);
1039
958
  }
1040
959
  // Webhook/Triggers status
1041
- if (webhookConfig.triggers.length > 0) {
1042
- console.log(`\n ⚔ Triggers (${createdWebhooks.length}/${webhookConfig.triggers.length}):`);
1043
- // Compute actual URLs being used (per-trigger hookUrl or default)
1044
- const actualUrls = webhookConfig.triggers.map(t => t.hookUrl || webhookConfig.webhookUrl || AGENT_WEBHOOK_URL);
1045
- const uniqueUrls = [...new Set(actualUrls)];
1046
- const allAgentTriggers = uniqueUrls.every(url => url === AGENT_WEBHOOK_URL);
1047
- if (allAgentTriggers) {
1048
- console.log(` Mode: Agent wake-up`);
1049
- }
1050
- else if (uniqueUrls.length === 1) {
960
+ if (triggers.length > 0) {
961
+ console.log(`\n ⚔ Triggers (${webhooks.length}/${triggers.length}):`);
962
+ if (webhookConfig.isCustomWebhook) {
1051
963
  console.log(` Mode: Custom webhook`);
1052
- console.log(` URL: ${uniqueUrls[0]}`);
1053
964
  }
1054
965
  else {
1055
- console.log(` Mode: Mixed (per-trigger URLs)`);
1056
- }
1057
- if (createdWebhooks.length > 0) {
1058
- createdWebhooks.forEach(wh => {
1059
- const trigger = webhookConfig.triggers.find(t => t.objectType === wh.objectType && t.event === wh.event);
1060
- const desc = trigger?.friendlyDescription || `${wh.objectType}.${wh.event}`;
1061
- console.log(` āœ“ ${desc}`);
1062
- });
966
+ console.log(` Mode: Agent wake-up`);
1063
967
  }
1064
- if (failedWebhooks.length > 0) {
1065
- failedWebhooks.forEach(t => console.log(` āœ— ${t}`));
968
+ webhooks.forEach(wh => {
969
+ const trigger = webhookConfig.triggers.find(t => t.objectType === wh.objectType && t.event === wh.event);
970
+ const desc = trigger?.friendlyDescription || `${wh.objectType}.${wh.event}`;
971
+ console.log(` āœ“ ${desc}`);
972
+ });
973
+ if (failedWebhooks && failedWebhooks.length > 0) {
974
+ failedWebhooks.forEach(t => console.log(` āœ— ${t.objectType}.${t.event}: ${t.error}`));
1066
975
  }
1067
976
  }
1068
977
  // Summary message
1069
978
  console.log("\n" + "─".repeat(60));
1070
979
  const capabilities = [];
1071
- if (mcpSetupSuccess && isActive) {
980
+ if (mcpServer.active) {
1072
981
  capabilities.push('tools via MCP');
1073
982
  }
1074
- if (createdWebhooks.length > 0) {
1075
- // Check if any triggers use custom URLs
1076
- const hasCustomUrls = webhookConfig.triggers.some(t => {
1077
- const url = t.hookUrl || webhookConfig.webhookUrl || AGENT_WEBHOOK_URL;
1078
- return url !== AGENT_WEBHOOK_URL;
1079
- });
1080
- if (hasCustomUrls) {
1081
- capabilities.push('webhooks to custom URL');
1082
- }
1083
- else {
1084
- capabilities.push('event-driven triggers');
1085
- }
983
+ if (webhooks.length > 0) {
984
+ capabilities.push(webhookConfig.isCustomWebhook ? 'webhooks to custom URL' : 'event-driven triggers');
1086
985
  }
1087
986
  if (capabilities.length > 0) {
1088
987
  console.log(`āœ… ${integration.name} connected! Your agent now has: ${capabilities.join(', ')}`);
1089
988
  }
1090
- else if (mcpSetupSuccess && !isActive) {
989
+ else if (!mcpServer.active) {
1091
990
  console.log(`āš ļø Connection created but MCP server pending activation.`);
1092
- console.log(` Run: lua mcp activate --server-name ${serverName}`);
991
+ console.log(` Run: lua mcp activate --server-name ${mcpServer.name}`);
1093
992
  }
1094
993
  else {
1095
994
  console.log(`āš ļø Connection created but setup incomplete. Check errors above.`);
1096
995
  }
1097
996
  console.log();
997
+ trackEvent('cli_integration_connected', {
998
+ integration_type: integration.value,
999
+ integration_name: integration.name,
1000
+ mcp_server_active: mcpServer.active,
1001
+ webhooks_count: webhooks.length,
1002
+ });
1098
1003
  }
1099
1004
  async function listConnections(context) {
1100
1005
  writeProgress("šŸ”„ Loading connections...");
1101
1006
  try {
1102
- // Fetch both connections and MCP servers (MCP status is secondary info)
1103
- const [connectionsResult, serversResult] = await Promise.all([
1104
- context.unifiedToApi.getConnections(context.agentId),
1105
- context.developerApi.getMCPServers()
1106
- ]);
1007
+ // API now returns connections enriched with MCP server info
1008
+ const connectionsResult = await context.unifiedToApi.getConnections(context.agentId);
1107
1009
  const connections = connectionsResult.success ? connectionsResult.data || [] : [];
1108
- const servers = serversResult.success ? serversResult.data || [] : [];
1109
- const unifiedServers = servers.filter(s => s.source === 'unifiedto');
1110
- // Map connection IDs to MCP servers to check tool availability
1111
- const serverByConnectionId = new Map();
1112
- for (const server of unifiedServers) {
1113
- const connectionMatch = server.url?.match(/connection=([a-f0-9]+)/i);
1114
- if (connectionMatch) {
1115
- serverByConnectionId.set(connectionMatch[1], server);
1116
- }
1117
- }
1118
1010
  console.log("\n" + "=".repeat(60));
1119
1011
  console.log("šŸ”— Connected Integrations");
1120
1012
  console.log("=".repeat(60) + "\n");
@@ -1124,8 +1016,7 @@ async function listConnections(context) {
1124
1016
  return;
1125
1017
  }
1126
1018
  for (const connection of connections) {
1127
- const linkedServer = serverByConnectionId.get(connection.id);
1128
- const toolsAvailable = linkedServer?.active === true;
1019
+ const toolsAvailable = connection.mcpServer?.active === true;
1129
1020
  // Status based on connection health + tool availability
1130
1021
  let statusIcon = '⚪';
1131
1022
  let statusText = 'Inactive';
@@ -1148,8 +1039,8 @@ async function listConnections(context) {
1148
1039
  console.log(`${statusIcon} ${connection.integrationName || connection.integrationType}`);
1149
1040
  console.log(` Connection: ${connection.id}`);
1150
1041
  console.log(` Status: ${statusText}`);
1151
- if (linkedServer) {
1152
- console.log(` MCP Server: ${linkedServer.name} (${linkedServer.active ? 'active' : 'inactive'})`);
1042
+ if (connection.mcpServer) {
1043
+ console.log(` MCP Server: ${connection.mcpServer.name} (${connection.mcpServer.active ? 'active' : 'inactive'})`);
1153
1044
  }
1154
1045
  console.log(` Connected: ${new Date(connection.createdAt).toLocaleDateString()}`);
1155
1046
  console.log();
@@ -1164,15 +1055,7 @@ async function listConnections(context) {
1164
1055
  async function disconnectIntegration(context, connectionId) {
1165
1056
  writeProgress(`šŸ”„ Disconnecting... (please wait, do not close this window)`);
1166
1057
  try {
1167
- // Clean up associated MCP server (internal implementation detail)
1168
- const mcpServers = await context.developerApi.getMCPServers();
1169
- if (mcpServers.success && mcpServers.data) {
1170
- const associatedServer = mcpServers.data.find(s => s.source === 'unifiedto' && s.url?.includes(`connection=${connectionId}`));
1171
- if (associatedServer) {
1172
- await context.developerApi.deleteMCPServer(associatedServer.id);
1173
- }
1174
- }
1175
- // Delete the connection (also deletes webhook subscriptions)
1058
+ // Delete the connection (API handles MCP server + webhook cleanup)
1176
1059
  const deleteResult = await context.unifiedToApi.deleteConnection(connectionId, context.agentId);
1177
1060
  if (deleteResult.success) {
1178
1061
  writeSuccess(`āœ… Integration disconnected successfully!`);
@@ -1180,6 +1063,9 @@ async function disconnectIntegration(context, connectionId) {
1180
1063
  console.log(` āœ“ Deleted ${deleteResult.data.deletedWebhooksCount} trigger(s)`);
1181
1064
  }
1182
1065
  console.log();
1066
+ trackEvent('cli_integration_disconnected', {
1067
+ webhooks_deleted: deleteResult.data?.deletedWebhooksCount || 0,
1068
+ });
1183
1069
  }
1184
1070
  else {
1185
1071
  writeError(`āŒ Failed to disconnect: ${deleteResult.error?.message}`);
@@ -1410,15 +1296,7 @@ async function updateConnectionFlow(context, options = {}) {
1410
1296
  // Step 7: Delete the old connection (silently)
1411
1297
  writeProgress(`šŸ”„ Updating ${selectedIntegration.name}...`);
1412
1298
  try {
1413
- // Clean up old MCP server
1414
- const mcpServers = await context.developerApi.getMCPServers();
1415
- if (mcpServers.success && mcpServers.data) {
1416
- const associatedServer = mcpServers.data.find(s => s.source === 'unifiedto' && s.url?.includes(`connection=${selectedConnection.id}`));
1417
- if (associatedServer) {
1418
- await context.developerApi.deleteMCPServer(associatedServer.id);
1419
- }
1420
- }
1421
- // Delete old connection (this also deletes associated webhooks in Unified.to)
1299
+ // Delete old connection (API handles MCP server + webhook cleanup)
1422
1300
  await context.unifiedToApi.deleteConnection(selectedConnection.id, context.agentId);
1423
1301
  }
1424
1302
  catch (error) {
@@ -1438,7 +1316,7 @@ async function updateConnectionFlow(context, options = {}) {
1438
1316
  });
1439
1317
  const authUrlResult = await context.unifiedToApi.getAuthUrl(selectedIntegration.value, {
1440
1318
  successRedirect: CALLBACK_URL,
1441
- failureRedirect: `${CALLBACK_URL}?error=auth_failed`,
1319
+ failureRedirect: CALLBACK_URL,
1442
1320
  scopes: selectedScopes,
1443
1321
  state,
1444
1322
  externalXref,
@@ -1447,33 +1325,16 @@ async function updateConnectionFlow(context, options = {}) {
1447
1325
  writeError(`āŒ Failed to get authorization URL: ${authUrlResult.error?.message || 'Unknown error'}`);
1448
1326
  return;
1449
1327
  }
1328
+ // Auth URL is already resolved by the API (redirect wrappers followed server-side)
1450
1329
  const authUrl = authUrlResult.data.authUrl;
1451
- // Pre-fetch to handle redirects
1452
- let finalAuthUrl = authUrl;
1453
- try {
1454
- const response = await fetch(authUrl);
1455
- const responseText = await response.text();
1456
- if (responseText.includes('test.html?redirect=')) {
1457
- const urlMatch = responseText.match(/redirect=([^&\s]+)/);
1458
- if (urlMatch) {
1459
- finalAuthUrl = decodeURIComponent(urlMatch[1]);
1460
- }
1461
- }
1462
- else if (responseText.startsWith('https://')) {
1463
- finalAuthUrl = responseText.trim();
1464
- }
1465
- }
1466
- catch (error) {
1467
- // Use original auth URL if pre-fetch fails
1468
- }
1469
1330
  // Step 9: Open browser and wait for callback
1470
1331
  console.log("\n" + "─".repeat(60));
1471
1332
  console.log("🌐 Re-authorizing with new scopes...");
1472
1333
  console.log("─".repeat(60));
1473
- console.log(`\nšŸ“‹ Authorization URL (copy if browser doesn't open):\n ${finalAuthUrl}\n`);
1334
+ console.log(`\nšŸ“‹ Authorization URL (copy if browser doesn't open):\n ${authUrl}\n`);
1474
1335
  const callbackPromise = startCallbackServer(300000);
1475
1336
  try {
1476
- await open(finalAuthUrl);
1337
+ await open(authUrl);
1477
1338
  writeInfo("🌐 Browser opened - please complete the authorization");
1478
1339
  }
1479
1340
  catch (error) {
@@ -1520,6 +1381,17 @@ async function updateConnectionFlow(context, options = {}) {
1520
1381
  }
1521
1382
  else {
1522
1383
  writeError(`\nāŒ Authorization failed: ${result.error || 'Unknown error'}`);
1384
+ if (result.logId) {
1385
+ console.log(` Log ID: ${result.logId}`);
1386
+ }
1387
+ // Report auth failure for observability (fire and forget)
1388
+ context.unifiedToApi.reportAuthFailure({
1389
+ integrationType: selectedIntegration.value,
1390
+ error: result.error || 'Unknown OAuth failure',
1391
+ logId: result.logId,
1392
+ agentId: context.agentId,
1393
+ source: 'cli',
1394
+ }).catch(() => { });
1523
1395
  console.log("šŸ’” The old connection was removed. Please reconnect with 'lua integrations connect'\n");
1524
1396
  }
1525
1397
  }
@@ -1906,6 +1778,11 @@ async function webhooksCreateFlow(context, options) {
1906
1778
  // Step 6: Get interval for virtual webhooks
1907
1779
  let interval;
1908
1780
  const intervalOptions = [
1781
+ { name: '1 minute', value: 1 },
1782
+ { name: '5 minutes', value: 5 },
1783
+ { name: '10 minutes', value: 10 },
1784
+ { name: '15 minutes', value: 15 },
1785
+ { name: '30 minutes', value: 30 },
1909
1786
  { name: '1 hour', value: 60 },
1910
1787
  { name: '2 hours', value: 120 },
1911
1788
  { name: '4 hours', value: 240 },
@@ -1925,7 +1802,7 @@ async function webhooksCreateFlow(context, options) {
1925
1802
  name: 'interval',
1926
1803
  message: 'Select polling interval:',
1927
1804
  choices: intervalOptions,
1928
- default: 60,
1805
+ default: 1,
1929
1806
  }
1930
1807
  ]);
1931
1808
  if (!intervalAnswer)