lua-cli 3.15.3 → 3.16.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.
- package/dist/api-exports.d.ts +5029 -698
- package/dist/api-exports.js +6509 -772
- package/dist/api-exports.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +41174 -82
- package/dist/index.js.map +1 -1
- package/dist/voice/test/index.d.ts +1217 -0
- package/dist/voice/test/index.js +386 -0
- package/dist/voice/test/index.js.map +1 -0
- package/dist/voice-exports.d.ts +40 -0
- package/dist/voice-exports.js +16 -0
- package/dist/voice-exports.js.map +1 -0
- package/docs/README.md +1 -1
- package/package.json +38 -21
- package/scripts/build-vendor.mjs +6 -3
- package/scripts/run-api-extractor.mjs +79 -0
- package/template/.gitignore +21 -0
- package/template/package.json +1 -1
- package/dist/api/agent.api.service.d.ts +0 -165
- package/dist/api/agent.api.service.d.ts.map +0 -1
- package/dist/api/agent.api.service.js +0 -207
- package/dist/api/agent.api.service.js.map +0 -1
- package/dist/api/agents.api.service.d.ts +0 -21
- package/dist/api/agents.api.service.d.ts.map +0 -1
- package/dist/api/agents.api.service.js +0 -51
- package/dist/api/agents.api.service.js.map +0 -1
- package/dist/api/ai.api.service.d.ts +0 -20
- package/dist/api/ai.api.service.d.ts.map +0 -1
- package/dist/api/ai.api.service.js +0 -40
- package/dist/api/ai.api.service.js.map +0 -1
- package/dist/api/auth.api.service.d.ts +0 -49
- package/dist/api/auth.api.service.d.ts.map +0 -1
- package/dist/api/auth.api.service.js +0 -55
- package/dist/api/auth.api.service.js.map +0 -1
- package/dist/api/backup.api.service.d.ts +0 -78
- package/dist/api/backup.api.service.d.ts.map +0 -1
- package/dist/api/backup.api.service.js +0 -115
- package/dist/api/backup.api.service.js.map +0 -1
- package/dist/api/basket.api.service.d.ts +0 -85
- package/dist/api/basket.api.service.d.ts.map +0 -1
- package/dist/api/basket.api.service.js +0 -160
- package/dist/api/basket.api.service.js.map +0 -1
- package/dist/api/cdn.api.service.d.ts +0 -21
- package/dist/api/cdn.api.service.d.ts.map +0 -1
- package/dist/api/cdn.api.service.js +0 -46
- package/dist/api/cdn.api.service.js.map +0 -1
- package/dist/api/chat.api.service.d.ts +0 -40
- package/dist/api/chat.api.service.d.ts.map +0 -1
- package/dist/api/chat.api.service.js +0 -121
- package/dist/api/chat.api.service.js.map +0 -1
- package/dist/api/credentials.d.ts +0 -25
- package/dist/api/credentials.d.ts.map +0 -1
- package/dist/api/credentials.js +0 -44
- package/dist/api/credentials.js.map +0 -1
- package/dist/api/custom.data.api.service.d.ts +0 -71
- package/dist/api/custom.data.api.service.d.ts.map +0 -1
- package/dist/api/custom.data.api.service.js +0 -126
- package/dist/api/custom.data.api.service.js.map +0 -1
- package/dist/api/developer.api.service.d.ts +0 -121
- package/dist/api/developer.api.service.d.ts.map +0 -1
- package/dist/api/developer.api.service.js +0 -162
- package/dist/api/developer.api.service.js.map +0 -1
- package/dist/api/device-trigger.api.service.d.ts +0 -136
- package/dist/api/device-trigger.api.service.d.ts.map +0 -1
- package/dist/api/device-trigger.api.service.js +0 -120
- package/dist/api/device-trigger.api.service.js.map +0 -1
- package/dist/api/device.api.service.d.ts +0 -61
- package/dist/api/device.api.service.d.ts.map +0 -1
- package/dist/api/device.api.service.js +0 -72
- package/dist/api/device.api.service.js.map +0 -1
- package/dist/api/http.client.d.ts +0 -90
- package/dist/api/http.client.d.ts.map +0 -1
- package/dist/api/http.client.js +0 -265
- package/dist/api/http.client.js.map +0 -1
- package/dist/api/job.api.service.d.ts +0 -154
- package/dist/api/job.api.service.d.ts.map +0 -1
- package/dist/api/job.api.service.js +0 -230
- package/dist/api/job.api.service.js.map +0 -1
- package/dist/api/lazy-instances.d.ts +0 -107
- package/dist/api/lazy-instances.d.ts.map +0 -1
- package/dist/api/lazy-instances.js +0 -220
- package/dist/api/lazy-instances.js.map +0 -1
- package/dist/api/logs.api.service.d.ts +0 -38
- package/dist/api/logs.api.service.d.ts.map +0 -1
- package/dist/api/logs.api.service.js +0 -50
- package/dist/api/logs.api.service.js.map +0 -1
- package/dist/api/marketplace.api.service.d.ts +0 -28
- package/dist/api/marketplace.api.service.d.ts.map +0 -1
- package/dist/api/marketplace.api.service.js +0 -112
- package/dist/api/marketplace.api.service.js.map +0 -1
- package/dist/api/order.api.service.d.ts +0 -53
- package/dist/api/order.api.service.d.ts.map +0 -1
- package/dist/api/order.api.service.js +0 -94
- package/dist/api/order.api.service.js.map +0 -1
- package/dist/api/persona.api.service.d.ts +0 -56
- package/dist/api/persona.api.service.d.ts.map +0 -1
- package/dist/api/persona.api.service.js +0 -90
- package/dist/api/persona.api.service.js.map +0 -1
- package/dist/api/postprocessor.api.service.d.ts +0 -151
- package/dist/api/postprocessor.api.service.d.ts.map +0 -1
- package/dist/api/postprocessor.api.service.js +0 -109
- package/dist/api/postprocessor.api.service.js.map +0 -1
- package/dist/api/preprocessor.api.service.d.ts +0 -155
- package/dist/api/preprocessor.api.service.d.ts.map +0 -1
- package/dist/api/preprocessor.api.service.js +0 -111
- package/dist/api/preprocessor.api.service.js.map +0 -1
- package/dist/api/products.api.service.d.ts +0 -80
- package/dist/api/products.api.service.d.ts.map +0 -1
- package/dist/api/products.api.service.js +0 -126
- package/dist/api/products.api.service.js.map +0 -1
- package/dist/api/resource.api.service.d.ts +0 -77
- package/dist/api/resource.api.service.d.ts.map +0 -1
- package/dist/api/resource.api.service.js +0 -74
- package/dist/api/resource.api.service.js.map +0 -1
- package/dist/api/skills.api.service.d.ts +0 -94
- package/dist/api/skills.api.service.d.ts.map +0 -1
- package/dist/api/skills.api.service.js +0 -120
- package/dist/api/skills.api.service.js.map +0 -1
- package/dist/api/tool.api.service.d.ts +0 -53
- package/dist/api/tool.api.service.d.ts.map +0 -1
- package/dist/api/tool.api.service.js +0 -74
- package/dist/api/tool.api.service.js.map +0 -1
- package/dist/api/unifiedto.api.service.d.ts +0 -133
- package/dist/api/unifiedto.api.service.d.ts.map +0 -1
- package/dist/api/unifiedto.api.service.js +0 -166
- package/dist/api/unifiedto.api.service.js.map +0 -1
- package/dist/api/user.data.api.service.d.ts +0 -69
- package/dist/api/user.data.api.service.d.ts.map +0 -1
- package/dist/api/user.data.api.service.js +0 -158
- package/dist/api/user.data.api.service.js.map +0 -1
- package/dist/api/webhook.api.service.d.ts +0 -163
- package/dist/api/webhook.api.service.d.ts.map +0 -1
- package/dist/api/webhook.api.service.js +0 -140
- package/dist/api/webhook.api.service.js.map +0 -1
- package/dist/api/whatsapp-templates.api.service.d.ts +0 -41
- package/dist/api/whatsapp-templates.api.service.d.ts.map +0 -1
- package/dist/api/whatsapp-templates.api.service.js +0 -79
- package/dist/api/whatsapp-templates.api.service.js.map +0 -1
- package/dist/api-exports.d.ts.map +0 -1
- package/dist/cli/command-definitions.d.ts +0 -29
- package/dist/cli/command-definitions.d.ts.map +0 -1
- package/dist/cli/command-definitions.js +0 -943
- package/dist/cli/command-definitions.js.map +0 -1
- package/dist/commands/admin.d.ts +0 -24
- package/dist/commands/admin.d.ts.map +0 -1
- package/dist/commands/admin.js +0 -44
- package/dist/commands/admin.js.map +0 -1
- package/dist/commands/agents.d.ts +0 -23
- package/dist/commands/agents.d.ts.map +0 -1
- package/dist/commands/agents.js +0 -83
- package/dist/commands/agents.js.map +0 -1
- package/dist/commands/apiKey.d.ts +0 -8
- package/dist/commands/apiKey.d.ts.map +0 -1
- package/dist/commands/apiKey.js +0 -43
- package/dist/commands/apiKey.js.map +0 -1
- package/dist/commands/channels.d.ts +0 -13
- package/dist/commands/channels.d.ts.map +0 -1
- package/dist/commands/channels.js +0 -747
- package/dist/commands/channels.js.map +0 -1
- package/dist/commands/chat-log-probe.d.ts +0 -59
- package/dist/commands/chat-log-probe.d.ts.map +0 -1
- package/dist/commands/chat-log-probe.js +0 -87
- package/dist/commands/chat-log-probe.js.map +0 -1
- package/dist/commands/chat.d.ts +0 -20
- package/dist/commands/chat.d.ts.map +0 -1
- package/dist/commands/chat.js +0 -618
- package/dist/commands/chat.js.map +0 -1
- package/dist/commands/chatClear.d.ts +0 -25
- package/dist/commands/chatClear.d.ts.map +0 -1
- package/dist/commands/chatClear.js +0 -71
- package/dist/commands/chatClear.js.map +0 -1
- package/dist/commands/compile.d.ts +0 -48
- package/dist/commands/compile.d.ts.map +0 -1
- package/dist/commands/compile.js +0 -216
- package/dist/commands/compile.js.map +0 -1
- package/dist/commands/completion.d.ts +0 -12
- package/dist/commands/completion.d.ts.map +0 -1
- package/dist/commands/completion.js +0 -211
- package/dist/commands/completion.js.map +0 -1
- package/dist/commands/configure.d.ts +0 -42
- package/dist/commands/configure.d.ts.map +0 -1
- package/dist/commands/configure.js +0 -76
- package/dist/commands/configure.js.map +0 -1
- package/dist/commands/deploy.d.ts +0 -14
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js +0 -517
- package/dist/commands/deploy.js.map +0 -1
- package/dist/commands/destroy.d.ts +0 -8
- package/dist/commands/destroy.d.ts.map +0 -1
- package/dist/commands/destroy.js +0 -66
- package/dist/commands/destroy.js.map +0 -1
- package/dist/commands/devices.d.ts +0 -6
- package/dist/commands/devices.d.ts.map +0 -1
- package/dist/commands/devices.js +0 -265
- package/dist/commands/devices.js.map +0 -1
- package/dist/commands/docs.d.ts +0 -20
- package/dist/commands/docs.d.ts.map +0 -1
- package/dist/commands/docs.js +0 -33
- package/dist/commands/docs.js.map +0 -1
- package/dist/commands/env.d.ts +0 -34
- package/dist/commands/env.d.ts.map +0 -1
- package/dist/commands/env.js +0 -612
- package/dist/commands/env.js.map +0 -1
- package/dist/commands/evals.d.ts +0 -9
- package/dist/commands/evals.d.ts.map +0 -1
- package/dist/commands/evals.js +0 -27
- package/dist/commands/evals.js.map +0 -1
- package/dist/commands/features.d.ts +0 -13
- package/dist/commands/features.d.ts.map +0 -1
- package/dist/commands/features.js +0 -455
- package/dist/commands/features.js.map +0 -1
- package/dist/commands/governance.d.ts +0 -7
- package/dist/commands/governance.d.ts.map +0 -1
- package/dist/commands/governance.js +0 -258
- package/dist/commands/governance.js.map +0 -1
- package/dist/commands/index.d.ts +0 -38
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js +0 -38
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/init.d.ts +0 -53
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -992
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/integrations.d.ts +0 -18
- package/dist/commands/integrations.d.ts.map +0 -1
- package/dist/commands/integrations.js +0 -2666
- package/dist/commands/integrations.js.map +0 -1
- package/dist/commands/jobs.d.ts +0 -13
- package/dist/commands/jobs.d.ts.map +0 -1
- package/dist/commands/jobs.js +0 -736
- package/dist/commands/jobs.js.map +0 -1
- package/dist/commands/log-tip.d.ts +0 -79
- package/dist/commands/log-tip.d.ts.map +0 -1
- package/dist/commands/log-tip.js +0 -83
- package/dist/commands/log-tip.js.map +0 -1
- package/dist/commands/logs.d.ts +0 -13
- package/dist/commands/logs.d.ts.map +0 -1
- package/dist/commands/logs.js +0 -493
- package/dist/commands/logs.js.map +0 -1
- package/dist/commands/marketplace.d.ts +0 -34
- package/dist/commands/marketplace.d.ts.map +0 -1
- package/dist/commands/marketplace.js +0 -2105
- package/dist/commands/marketplace.js.map +0 -1
- package/dist/commands/mcp.d.ts +0 -32
- package/dist/commands/mcp.d.ts.map +0 -1
- package/dist/commands/mcp.js +0 -395
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/models.d.ts +0 -18
- package/dist/commands/models.d.ts.map +0 -1
- package/dist/commands/models.js +0 -207
- package/dist/commands/models.js.map +0 -1
- package/dist/commands/persona.d.ts +0 -13
- package/dist/commands/persona.d.ts.map +0 -1
- package/dist/commands/persona.js +0 -560
- package/dist/commands/persona.js.map +0 -1
- package/dist/commands/postprocessors.d.ts +0 -13
- package/dist/commands/postprocessors.d.ts.map +0 -1
- package/dist/commands/postprocessors.js +0 -558
- package/dist/commands/postprocessors.js.map +0 -1
- package/dist/commands/preprocessors.d.ts +0 -13
- package/dist/commands/preprocessors.d.ts.map +0 -1
- package/dist/commands/preprocessors.js +0 -558
- package/dist/commands/preprocessors.js.map +0 -1
- package/dist/commands/production.d.ts +0 -13
- package/dist/commands/production.d.ts.map +0 -1
- package/dist/commands/production.js +0 -588
- package/dist/commands/production.js.map +0 -1
- package/dist/commands/push-helpers.d.ts +0 -42
- package/dist/commands/push-helpers.d.ts.map +0 -1
- package/dist/commands/push-helpers.js +0 -48
- package/dist/commands/push-helpers.js.map +0 -1
- package/dist/commands/push.d.ts +0 -31
- package/dist/commands/push.d.ts.map +0 -1
- package/dist/commands/push.js +0 -1262
- package/dist/commands/push.js.map +0 -1
- package/dist/commands/pushBackup.d.ts +0 -78
- package/dist/commands/pushBackup.d.ts.map +0 -1
- package/dist/commands/pushBackup.js +0 -274
- package/dist/commands/pushBackup.js.map +0 -1
- package/dist/commands/resources.d.ts +0 -13
- package/dist/commands/resources.d.ts.map +0 -1
- package/dist/commands/resources.js +0 -377
- package/dist/commands/resources.js.map +0 -1
- package/dist/commands/skills.d.ts +0 -13
- package/dist/commands/skills.d.ts.map +0 -1
- package/dist/commands/skills.js +0 -618
- package/dist/commands/skills.js.map +0 -1
- package/dist/commands/source.d.ts +0 -72
- package/dist/commands/source.d.ts.map +0 -1
- package/dist/commands/source.js +0 -134
- package/dist/commands/source.js.map +0 -1
- package/dist/commands/status.d.ts +0 -14
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -731
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/sync.d.ts +0 -28
- package/dist/commands/sync.d.ts.map +0 -1
- package/dist/commands/sync.js +0 -802
- package/dist/commands/sync.js.map +0 -1
- package/dist/commands/telemetry.d.ts +0 -6
- package/dist/commands/telemetry.d.ts.map +0 -1
- package/dist/commands/telemetry.js +0 -42
- package/dist/commands/telemetry.js.map +0 -1
- package/dist/commands/test-output.helpers.d.ts +0 -24
- package/dist/commands/test-output.helpers.d.ts.map +0 -1
- package/dist/commands/test-output.helpers.js +0 -62
- package/dist/commands/test-output.helpers.js.map +0 -1
- package/dist/commands/test.d.ts +0 -9
- package/dist/commands/test.d.ts.map +0 -1
- package/dist/commands/test.js +0 -787
- package/dist/commands/test.js.map +0 -1
- package/dist/commands/update.d.ts +0 -14
- package/dist/commands/update.d.ts.map +0 -1
- package/dist/commands/update.js +0 -97
- package/dist/commands/update.js.map +0 -1
- package/dist/commands/webhooks.d.ts +0 -13
- package/dist/commands/webhooks.d.ts.map +0 -1
- package/dist/commands/webhooks.js +0 -691
- package/dist/commands/webhooks.js.map +0 -1
- package/dist/compiler/agent-traverser.d.ts +0 -140
- package/dist/compiler/agent-traverser.d.ts.map +0 -1
- package/dist/compiler/agent-traverser.js +0 -420
- package/dist/compiler/agent-traverser.js.map +0 -1
- package/dist/compiler/bundler.d.ts +0 -43
- package/dist/compiler/bundler.d.ts.map +0 -1
- package/dist/compiler/bundler.js +0 -188
- package/dist/compiler/bundler.js.map +0 -1
- package/dist/compiler/compiler.d.ts +0 -208
- package/dist/compiler/compiler.d.ts.map +0 -1
- package/dist/compiler/compiler.js +0 -706
- package/dist/compiler/compiler.js.map +0 -1
- package/dist/compiler/index.d.ts +0 -38
- package/dist/compiler/index.d.ts.map +0 -1
- package/dist/compiler/index.js +0 -43
- package/dist/compiler/index.js.map +0 -1
- package/dist/compiler/plugins/agent.plugin.d.ts +0 -58
- package/dist/compiler/plugins/agent.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/agent.plugin.js +0 -161
- package/dist/compiler/plugins/agent.plugin.js.map +0 -1
- package/dist/compiler/plugins/base.d.ts +0 -334
- package/dist/compiler/plugins/base.d.ts.map +0 -1
- package/dist/compiler/plugins/base.js +0 -353
- package/dist/compiler/plugins/base.js.map +0 -1
- package/dist/compiler/plugins/device-trigger.plugin.d.ts +0 -38
- package/dist/compiler/plugins/device-trigger.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/device-trigger.plugin.js +0 -107
- package/dist/compiler/plugins/device-trigger.plugin.js.map +0 -1
- package/dist/compiler/plugins/device.plugin.d.ts +0 -39
- package/dist/compiler/plugins/device.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/device.plugin.js +0 -77
- package/dist/compiler/plugins/device.plugin.js.map +0 -1
- package/dist/compiler/plugins/job.plugin.d.ts +0 -34
- package/dist/compiler/plugins/job.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/job.plugin.js +0 -108
- package/dist/compiler/plugins/job.plugin.js.map +0 -1
- package/dist/compiler/plugins/mcp-server.plugin.d.ts +0 -38
- package/dist/compiler/plugins/mcp-server.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/mcp-server.plugin.js +0 -107
- package/dist/compiler/plugins/mcp-server.plugin.js.map +0 -1
- package/dist/compiler/plugins/postprocessor.plugin.d.ts +0 -21
- package/dist/compiler/plugins/postprocessor.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/postprocessor.plugin.js +0 -36
- package/dist/compiler/plugins/postprocessor.plugin.js.map +0 -1
- package/dist/compiler/plugins/preprocessor.plugin.d.ts +0 -21
- package/dist/compiler/plugins/preprocessor.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/preprocessor.plugin.js +0 -38
- package/dist/compiler/plugins/preprocessor.plugin.js.map +0 -1
- package/dist/compiler/plugins/processor-base.d.ts +0 -17
- package/dist/compiler/plugins/processor-base.d.ts.map +0 -1
- package/dist/compiler/plugins/processor-base.js +0 -27
- package/dist/compiler/plugins/processor-base.js.map +0 -1
- package/dist/compiler/plugins/registry.d.ts +0 -62
- package/dist/compiler/plugins/registry.d.ts.map +0 -1
- package/dist/compiler/plugins/registry.js +0 -113
- package/dist/compiler/plugins/registry.js.map +0 -1
- package/dist/compiler/plugins/skill.plugin.d.ts +0 -106
- package/dist/compiler/plugins/skill.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/skill.plugin.js +0 -316
- package/dist/compiler/plugins/skill.plugin.js.map +0 -1
- package/dist/compiler/plugins/tool.plugin.d.ts +0 -69
- package/dist/compiler/plugins/tool.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/tool.plugin.js +0 -262
- package/dist/compiler/plugins/tool.plugin.js.map +0 -1
- package/dist/compiler/plugins/webhook.plugin.d.ts +0 -38
- package/dist/compiler/plugins/webhook.plugin.d.ts.map +0 -1
- package/dist/compiler/plugins/webhook.plugin.js +0 -117
- package/dist/compiler/plugins/webhook.plugin.js.map +0 -1
- package/dist/compiler/source-writer.d.ts +0 -129
- package/dist/compiler/source-writer.d.ts.map +0 -1
- package/dist/compiler/source-writer.js +0 -329
- package/dist/compiler/source-writer.js.map +0 -1
- package/dist/compiler/types.d.ts +0 -391
- package/dist/compiler/types.d.ts.map +0 -1
- package/dist/compiler/types.js +0 -30
- package/dist/compiler/types.js.map +0 -1
- package/dist/compiler/utils/ast-helpers.d.ts +0 -106
- package/dist/compiler/utils/ast-helpers.d.ts.map +0 -1
- package/dist/compiler/utils/ast-helpers.js +0 -356
- package/dist/compiler/utils/ast-helpers.js.map +0 -1
- package/dist/compiler/utils/common.d.ts +0 -22
- package/dist/compiler/utils/common.d.ts.map +0 -1
- package/dist/compiler/utils/common.js +0 -55
- package/dist/compiler/utils/common.js.map +0 -1
- package/dist/compiler/utils/file-discovery.d.ts +0 -35
- package/dist/compiler/utils/file-discovery.d.ts.map +0 -1
- package/dist/compiler/utils/file-discovery.js +0 -60
- package/dist/compiler/utils/file-discovery.js.map +0 -1
- package/dist/compiler/utils/path-resolver.d.ts +0 -83
- package/dist/compiler/utils/path-resolver.d.ts.map +0 -1
- package/dist/compiler/utils/path-resolver.js +0 -162
- package/dist/compiler/utils/path-resolver.js.map +0 -1
- package/dist/compiler/utils/reference-resolver.d.ts +0 -196
- package/dist/compiler/utils/reference-resolver.d.ts.map +0 -1
- package/dist/compiler/utils/reference-resolver.js +0 -1026
- package/dist/compiler/utils/reference-resolver.js.map +0 -1
- package/dist/compiler/utils/schema-converter.d.ts +0 -52
- package/dist/compiler/utils/schema-converter.d.ts.map +0 -1
- package/dist/compiler/utils/schema-converter.js +0 -170
- package/dist/compiler/utils/schema-converter.js.map +0 -1
- package/dist/compiler/utils/workspace.d.ts +0 -35
- package/dist/compiler/utils/workspace.d.ts.map +0 -1
- package/dist/compiler/utils/workspace.js +0 -121
- package/dist/compiler/utils/workspace.js.map +0 -1
- package/dist/config/compile.constants.d.ts +0 -75
- package/dist/config/compile.constants.d.ts.map +0 -1
- package/dist/config/compile.constants.js +0 -95
- package/dist/config/compile.constants.js.map +0 -1
- package/dist/config/constants.d.ts +0 -49
- package/dist/config/constants.d.ts.map +0 -1
- package/dist/config/constants.js +0 -69
- package/dist/config/constants.js.map +0 -1
- package/dist/errors/auth.error.d.ts +0 -34
- package/dist/errors/auth.error.d.ts.map +0 -1
- package/dist/errors/auth.error.js +0 -29
- package/dist/errors/auth.error.js.map +0 -1
- package/dist/errors/index.d.ts +0 -5
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -5
- package/dist/errors/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/instances/basket.instance.d.ts +0 -82
- package/dist/instances/basket.instance.d.ts.map +0 -1
- package/dist/instances/basket.instance.js +0 -245
- package/dist/instances/basket.instance.js.map +0 -1
- package/dist/instances/data.entry.instance.d.ts +0 -50
- package/dist/instances/data.entry.instance.d.ts.map +0 -1
- package/dist/instances/data.entry.instance.js +0 -163
- package/dist/instances/data.entry.instance.js.map +0 -1
- package/dist/instances/job.instance.d.ts +0 -133
- package/dist/instances/job.instance.d.ts.map +0 -1
- package/dist/instances/job.instance.js +0 -180
- package/dist/instances/job.instance.js.map +0 -1
- package/dist/instances/order.instance.d.ts +0 -50
- package/dist/instances/order.instance.d.ts.map +0 -1
- package/dist/instances/order.instance.js +0 -199
- package/dist/instances/order.instance.js.map +0 -1
- package/dist/instances/product.instance.d.ts +0 -43
- package/dist/instances/product.instance.d.ts.map +0 -1
- package/dist/instances/product.instance.js +0 -145
- package/dist/instances/product.instance.js.map +0 -1
- package/dist/instances/product.pagination.instance.d.ts +0 -102
- package/dist/instances/product.pagination.instance.d.ts.map +0 -1
- package/dist/instances/product.pagination.instance.js +0 -156
- package/dist/instances/product.pagination.instance.js.map +0 -1
- package/dist/instances/product.search.instance.d.ts +0 -81
- package/dist/instances/product.search.instance.d.ts.map +0 -1
- package/dist/instances/product.search.instance.js +0 -121
- package/dist/instances/product.search.instance.js.map +0 -1
- package/dist/instances/user.instance.d.ts +0 -56
- package/dist/instances/user.instance.d.ts.map +0 -1
- package/dist/instances/user.instance.js +0 -188
- package/dist/instances/user.instance.js.map +0 -1
- package/dist/interfaces/admin.d.ts +0 -64
- package/dist/interfaces/admin.d.ts.map +0 -1
- package/dist/interfaces/admin.js +0 -6
- package/dist/interfaces/admin.js.map +0 -1
- package/dist/interfaces/agent.d.ts +0 -399
- package/dist/interfaces/agent.d.ts.map +0 -1
- package/dist/interfaces/agent.js +0 -6
- package/dist/interfaces/agent.js.map +0 -1
- package/dist/interfaces/backup.d.ts +0 -17
- package/dist/interfaces/backup.d.ts.map +0 -1
- package/dist/interfaces/backup.js +0 -7
- package/dist/interfaces/backup.js.map +0 -1
- package/dist/interfaces/baskets.d.ts +0 -80
- package/dist/interfaces/baskets.d.ts.map +0 -1
- package/dist/interfaces/baskets.js +0 -20
- package/dist/interfaces/baskets.js.map +0 -1
- package/dist/interfaces/cdn.d.ts +0 -25
- package/dist/interfaces/cdn.d.ts.map +0 -1
- package/dist/interfaces/cdn.js +0 -6
- package/dist/interfaces/cdn.js.map +0 -1
- package/dist/interfaces/chat.d.ts +0 -98
- package/dist/interfaces/chat.d.ts.map +0 -1
- package/dist/interfaces/chat.js +0 -6
- package/dist/interfaces/chat.js.map +0 -1
- package/dist/interfaces/common.d.ts +0 -64
- package/dist/interfaces/common.d.ts.map +0 -1
- package/dist/interfaces/common.js +0 -9
- package/dist/interfaces/common.js.map +0 -1
- package/dist/interfaces/custom.data.d.ts +0 -83
- package/dist/interfaces/custom.data.d.ts.map +0 -1
- package/dist/interfaces/custom.data.js +0 -6
- package/dist/interfaces/custom.data.js.map +0 -1
- package/dist/interfaces/deploy.d.ts +0 -15
- package/dist/interfaces/deploy.d.ts.map +0 -1
- package/dist/interfaces/deploy.js +0 -5
- package/dist/interfaces/deploy.js.map +0 -1
- package/dist/interfaces/dev.d.ts +0 -54
- package/dist/interfaces/dev.d.ts.map +0 -1
- package/dist/interfaces/dev.js +0 -6
- package/dist/interfaces/dev.js.map +0 -1
- package/dist/interfaces/device-triggers.d.ts +0 -80
- package/dist/interfaces/device-triggers.d.ts.map +0 -1
- package/dist/interfaces/device-triggers.js +0 -6
- package/dist/interfaces/device-triggers.js.map +0 -1
- package/dist/interfaces/devices.d.ts +0 -74
- package/dist/interfaces/devices.d.ts.map +0 -1
- package/dist/interfaces/devices.js +0 -5
- package/dist/interfaces/devices.js.map +0 -1
- package/dist/interfaces/index.d.ts +0 -15
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/index.js +0 -8
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/init.d.ts +0 -42
- package/dist/interfaces/init.d.ts.map +0 -1
- package/dist/interfaces/init.js +0 -5
- package/dist/interfaces/init.js.map +0 -1
- package/dist/interfaces/jobs.d.ts +0 -149
- package/dist/interfaces/jobs.d.ts.map +0 -1
- package/dist/interfaces/jobs.js +0 -6
- package/dist/interfaces/jobs.js.map +0 -1
- package/dist/interfaces/logs.d.ts +0 -44
- package/dist/interfaces/logs.d.ts.map +0 -1
- package/dist/interfaces/logs.js +0 -6
- package/dist/interfaces/logs.js.map +0 -1
- package/dist/interfaces/lua.d.ts +0 -37
- package/dist/interfaces/lua.d.ts.map +0 -1
- package/dist/interfaces/lua.js +0 -6
- package/dist/interfaces/lua.js.map +0 -1
- package/dist/interfaces/marketplace.d.ts +0 -171
- package/dist/interfaces/marketplace.d.ts.map +0 -1
- package/dist/interfaces/marketplace.js +0 -3
- package/dist/interfaces/marketplace.js.map +0 -1
- package/dist/interfaces/mcp.d.ts +0 -96
- package/dist/interfaces/mcp.d.ts.map +0 -1
- package/dist/interfaces/mcp.js +0 -9
- package/dist/interfaces/mcp.js.map +0 -1
- package/dist/interfaces/message.d.ts +0 -16
- package/dist/interfaces/message.d.ts.map +0 -1
- package/dist/interfaces/message.js +0 -2
- package/dist/interfaces/message.js.map +0 -1
- package/dist/interfaces/orders.d.ts +0 -68
- package/dist/interfaces/orders.d.ts.map +0 -1
- package/dist/interfaces/orders.js +0 -20
- package/dist/interfaces/orders.js.map +0 -1
- package/dist/interfaces/persona.d.ts +0 -44
- package/dist/interfaces/persona.d.ts.map +0 -1
- package/dist/interfaces/persona.js +0 -6
- package/dist/interfaces/persona.js.map +0 -1
- package/dist/interfaces/postprocessors.d.ts +0 -15
- package/dist/interfaces/postprocessors.d.ts.map +0 -1
- package/dist/interfaces/postprocessors.js +0 -5
- package/dist/interfaces/postprocessors.js.map +0 -1
- package/dist/interfaces/preprocessors.d.ts +0 -15
- package/dist/interfaces/preprocessors.d.ts.map +0 -1
- package/dist/interfaces/preprocessors.js +0 -5
- package/dist/interfaces/preprocessors.js.map +0 -1
- package/dist/interfaces/product.d.ts +0 -92
- package/dist/interfaces/product.d.ts.map +0 -1
- package/dist/interfaces/product.js +0 -6
- package/dist/interfaces/product.js.map +0 -1
- package/dist/interfaces/push.d.ts +0 -27
- package/dist/interfaces/push.d.ts.map +0 -1
- package/dist/interfaces/push.js +0 -5
- package/dist/interfaces/push.js.map +0 -1
- package/dist/interfaces/skills.d.ts +0 -137
- package/dist/interfaces/skills.d.ts.map +0 -1
- package/dist/interfaces/skills.js +0 -6
- package/dist/interfaces/skills.js.map +0 -1
- package/dist/interfaces/test.d.ts +0 -37
- package/dist/interfaces/test.d.ts.map +0 -1
- package/dist/interfaces/test.js +0 -5
- package/dist/interfaces/test.js.map +0 -1
- package/dist/interfaces/unifiedto.d.ts +0 -141
- package/dist/interfaces/unifiedto.d.ts.map +0 -1
- package/dist/interfaces/unifiedto.js +0 -6
- package/dist/interfaces/unifiedto.js.map +0 -1
- package/dist/interfaces/user.d.ts +0 -75
- package/dist/interfaces/user.d.ts.map +0 -1
- package/dist/interfaces/user.js +0 -2
- package/dist/interfaces/user.js.map +0 -1
- package/dist/interfaces/webhooks.d.ts +0 -97
- package/dist/interfaces/webhooks.d.ts.map +0 -1
- package/dist/interfaces/webhooks.js +0 -6
- package/dist/interfaces/webhooks.js.map +0 -1
- package/dist/interfaces/whatsapp-templates.d.ts +0 -105
- package/dist/interfaces/whatsapp-templates.d.ts.map +0 -1
- package/dist/interfaces/whatsapp-templates.js +0 -6
- package/dist/interfaces/whatsapp-templates.js.map +0 -1
- package/dist/primitives/agent.handler.d.ts +0 -71
- package/dist/primitives/agent.handler.d.ts.map +0 -1
- package/dist/primitives/agent.handler.js +0 -226
- package/dist/primitives/agent.handler.js.map +0 -1
- package/dist/primitives/base.handler.d.ts +0 -229
- package/dist/primitives/base.handler.d.ts.map +0 -1
- package/dist/primitives/base.handler.js +0 -620
- package/dist/primitives/base.handler.js.map +0 -1
- package/dist/primitives/device-trigger.handler.d.ts +0 -56
- package/dist/primitives/device-trigger.handler.d.ts.map +0 -1
- package/dist/primitives/device-trigger.handler.js +0 -99
- package/dist/primitives/device-trigger.handler.js.map +0 -1
- package/dist/primitives/device.handler.d.ts +0 -57
- package/dist/primitives/device.handler.d.ts.map +0 -1
- package/dist/primitives/device.handler.js +0 -103
- package/dist/primitives/device.handler.js.map +0 -1
- package/dist/primitives/index.d.ts +0 -51
- package/dist/primitives/index.d.ts.map +0 -1
- package/dist/primitives/index.js +0 -75
- package/dist/primitives/index.js.map +0 -1
- package/dist/primitives/job.handler.d.ts +0 -53
- package/dist/primitives/job.handler.d.ts.map +0 -1
- package/dist/primitives/job.handler.js +0 -110
- package/dist/primitives/job.handler.js.map +0 -1
- package/dist/primitives/mcp-server.handler.d.ts +0 -93
- package/dist/primitives/mcp-server.handler.d.ts.map +0 -1
- package/dist/primitives/mcp-server.handler.js +0 -216
- package/dist/primitives/mcp-server.handler.js.map +0 -1
- package/dist/primitives/postprocessor.handler.d.ts +0 -44
- package/dist/primitives/postprocessor.handler.d.ts.map +0 -1
- package/dist/primitives/postprocessor.handler.js +0 -71
- package/dist/primitives/postprocessor.handler.js.map +0 -1
- package/dist/primitives/preprocessor.handler.d.ts +0 -44
- package/dist/primitives/preprocessor.handler.d.ts.map +0 -1
- package/dist/primitives/preprocessor.handler.js +0 -72
- package/dist/primitives/preprocessor.handler.js.map +0 -1
- package/dist/primitives/skill.handler.d.ts +0 -47
- package/dist/primitives/skill.handler.d.ts.map +0 -1
- package/dist/primitives/skill.handler.js +0 -229
- package/dist/primitives/skill.handler.js.map +0 -1
- package/dist/primitives/types.d.ts +0 -91
- package/dist/primitives/types.d.ts.map +0 -1
- package/dist/primitives/types.js +0 -17
- package/dist/primitives/types.js.map +0 -1
- package/dist/primitives/webhook.handler.d.ts +0 -47
- package/dist/primitives/webhook.handler.d.ts.map +0 -1
- package/dist/primitives/webhook.handler.js +0 -87
- package/dist/primitives/webhook.handler.js.map +0 -1
- package/dist/services/analytics.d.ts +0 -57
- package/dist/services/analytics.d.ts.map +0 -1
- package/dist/services/analytics.js +0 -317
- package/dist/services/analytics.js.map +0 -1
- package/dist/services/auth.d.ts +0 -72
- package/dist/services/auth.d.ts.map +0 -1
- package/dist/services/auth.js +0 -173
- package/dist/services/auth.js.map +0 -1
- package/dist/services/sandbox.service.d.ts +0 -105
- package/dist/services/sandbox.service.d.ts.map +0 -1
- package/dist/services/sandbox.service.js +0 -531
- package/dist/services/sandbox.service.js.map +0 -1
- package/dist/types/api-contracts.d.ts +0 -287
- package/dist/types/api-contracts.d.ts.map +0 -1
- package/dist/types/api-contracts.js +0 -2
- package/dist/types/api-contracts.js.map +0 -1
- package/dist/types/index.d.ts +0 -28
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -30
- package/dist/types/index.js.map +0 -1
- package/dist/types/skill.d.ts +0 -1079
- package/dist/types/skill.d.ts.map +0 -1
- package/dist/types/skill.js +0 -688
- package/dist/types/skill.js.map +0 -1
- package/dist/types/tool-validation.d.ts +0 -35
- package/dist/types/tool-validation.d.ts.map +0 -1
- package/dist/types/tool-validation.js +0 -43
- package/dist/types/tool-validation.js.map +0 -1
- package/dist/types/yaml.types.d.ts +0 -91
- package/dist/types/yaml.types.d.ts.map +0 -1
- package/dist/types/yaml.types.js +0 -5
- package/dist/types/yaml.types.js.map +0 -1
- package/dist/utils/aliases.d.ts +0 -7
- package/dist/utils/aliases.d.ts.map +0 -1
- package/dist/utils/aliases.js +0 -492
- package/dist/utils/aliases.js.map +0 -1
- package/dist/utils/artifact-loader.d.ts +0 -152
- package/dist/utils/artifact-loader.d.ts.map +0 -1
- package/dist/utils/artifact-loader.js +0 -284
- package/dist/utils/artifact-loader.js.map +0 -1
- package/dist/utils/auth-flows.d.ts +0 -55
- package/dist/utils/auth-flows.d.ts.map +0 -1
- package/dist/utils/auth-flows.js +0 -246
- package/dist/utils/auth-flows.js.map +0 -1
- package/dist/utils/backup-helpers.d.ts +0 -238
- package/dist/utils/backup-helpers.d.ts.map +0 -1
- package/dist/utils/backup-helpers.js +0 -704
- package/dist/utils/backup-helpers.js.map +0 -1
- package/dist/utils/build-manifest-from-disk.d.ts +0 -8
- package/dist/utils/build-manifest-from-disk.d.ts.map +0 -1
- package/dist/utils/build-manifest-from-disk.js +0 -21
- package/dist/utils/build-manifest-from-disk.js.map +0 -1
- package/dist/utils/bundle-upload.d.ts +0 -42
- package/dist/utils/bundle-upload.d.ts.map +0 -1
- package/dist/utils/bundle-upload.js +0 -90
- package/dist/utils/bundle-upload.js.map +0 -1
- package/dist/utils/chat-attachments.d.ts +0 -15
- package/dist/utils/chat-attachments.d.ts.map +0 -1
- package/dist/utils/chat-attachments.js +0 -116
- package/dist/utils/chat-attachments.js.map +0 -1
- package/dist/utils/cli.d.ts +0 -62
- package/dist/utils/cli.d.ts.map +0 -1
- package/dist/utils/cli.js +0 -198
- package/dist/utils/cli.js.map +0 -1
- package/dist/utils/command-utils.d.ts +0 -46
- package/dist/utils/command-utils.d.ts.map +0 -1
- package/dist/utils/command-utils.js +0 -74
- package/dist/utils/command-utils.js.map +0 -1
- package/dist/utils/deploy-helpers.d.ts +0 -40
- package/dist/utils/deploy-helpers.d.ts.map +0 -1
- package/dist/utils/deploy-helpers.js +0 -76
- package/dist/utils/deploy-helpers.js.map +0 -1
- package/dist/utils/env-loader.utils.d.ts +0 -19
- package/dist/utils/env-loader.utils.d.ts.map +0 -1
- package/dist/utils/env-loader.utils.js +0 -90
- package/dist/utils/env-loader.utils.js.map +0 -1
- package/dist/utils/files.d.ts +0 -65
- package/dist/utils/files.d.ts.map +0 -1
- package/dist/utils/files.js +0 -193
- package/dist/utils/files.js.map +0 -1
- package/dist/utils/hints.d.ts +0 -81
- package/dist/utils/hints.d.ts.map +0 -1
- package/dist/utils/hints.js +0 -81
- package/dist/utils/hints.js.map +0 -1
- package/dist/utils/init-agent.d.ts +0 -86
- package/dist/utils/init-agent.d.ts.map +0 -1
- package/dist/utils/init-agent.js +0 -201
- package/dist/utils/init-agent.js.map +0 -1
- package/dist/utils/init-helpers.d.ts +0 -37
- package/dist/utils/init-helpers.d.ts.map +0 -1
- package/dist/utils/init-helpers.js +0 -78
- package/dist/utils/init-helpers.js.map +0 -1
- package/dist/utils/init-prompts.d.ts +0 -74
- package/dist/utils/init-prompts.d.ts.map +0 -1
- package/dist/utils/init-prompts.js +0 -256
- package/dist/utils/init-prompts.js.map +0 -1
- package/dist/utils/prompt-handler.d.ts +0 -17
- package/dist/utils/prompt-handler.d.ts.map +0 -1
- package/dist/utils/prompt-handler.js +0 -49
- package/dist/utils/prompt-handler.js.map +0 -1
- package/dist/utils/sandbox-storage.d.ts +0 -83
- package/dist/utils/sandbox-storage.d.ts.map +0 -1
- package/dist/utils/sandbox-storage.js +0 -211
- package/dist/utils/sandbox-storage.js.map +0 -1
- package/dist/utils/sandbox.d.ts +0 -76
- package/dist/utils/sandbox.d.ts.map +0 -1
- package/dist/utils/sandbox.js +0 -664
- package/dist/utils/sandbox.js.map +0 -1
- package/dist/utils/semver.d.ts +0 -40
- package/dist/utils/semver.d.ts.map +0 -1
- package/dist/utils/semver.js +0 -99
- package/dist/utils/semver.js.map +0 -1
- package/dist/utils/suggest.d.ts +0 -3
- package/dist/utils/suggest.d.ts.map +0 -1
- package/dist/utils/suggest.js +0 -32
- package/dist/utils/suggest.js.map +0 -1
- package/dist/utils/sync-display.d.ts +0 -28
- package/dist/utils/sync-display.d.ts.map +0 -1
- package/dist/utils/sync-display.js +0 -168
- package/dist/utils/sync-display.js.map +0 -1
- package/dist/utils/sync-fetch.d.ts +0 -108
- package/dist/utils/sync-fetch.d.ts.map +0 -1
- package/dist/utils/sync-fetch.js +0 -294
- package/dist/utils/sync-fetch.js.map +0 -1
- package/dist/utils/sync-helpers.d.ts +0 -7
- package/dist/utils/sync-helpers.d.ts.map +0 -1
- package/dist/utils/sync-helpers.js +0 -7
- package/dist/utils/sync-helpers.js.map +0 -1
- package/dist/utils/version-check.d.ts +0 -37
- package/dist/utils/version-check.d.ts.map +0 -1
- package/dist/utils/version-check.js +0 -117
- package/dist/utils/version-check.js.map +0 -1
- package/dist/utils/write-info.d.ts +0 -9
- package/dist/utils/write-info.d.ts.map +0 -1
- package/dist/utils/write-info.js +0 -11
- package/dist/utils/write-info.js.map +0 -1
- package/node_modules/@lua/shared-source-sync/dist/index.d.mts +0 -424
- package/node_modules/@lua/shared-source-sync/dist/index.d.ts +0 -424
- package/node_modules/@lua/shared-source-sync/dist/index.js +0 -536
- package/node_modules/@lua/shared-source-sync/dist/index.mjs +0 -491
- package/node_modules/@lua/shared-source-sync/package.json +0 -26
- package/node_modules/@lua/shared-source-sync/src/archive.ts +0 -98
- package/node_modules/@lua/shared-source-sync/src/filter.ts +0 -72
- package/node_modules/@lua/shared-source-sync/src/hash.ts +0 -40
- package/node_modules/@lua/shared-source-sync/src/http.ts +0 -132
- package/node_modules/@lua/shared-source-sync/src/index.ts +0 -56
- package/node_modules/@lua/shared-source-sync/src/pull.ts +0 -50
- package/node_modules/@lua/shared-source-sync/src/push.ts +0 -94
- package/node_modules/@lua/shared-source-sync/src/restore.ts +0 -83
- package/node_modules/@lua/shared-source-sync/src/skill-source.ts +0 -55
- package/node_modules/@lua/shared-source-sync/src/transfer.ts +0 -92
- package/node_modules/@lua/shared-source-sync/src/types.ts +0 -88
- package/node_modules/@lua/shared-source-sync/src/walk.ts +0 -91
- package/node_modules/@lua/shared-source-sync/tests/archive.test.ts +0 -108
- package/node_modules/@lua/shared-source-sync/tests/hash.test.ts +0 -40
- package/node_modules/@lua/shared-source-sync/tests/http.test.ts +0 -77
- package/node_modules/@lua/shared-source-sync/tests/push.test.ts +0 -162
- package/node_modules/@lua/shared-source-sync/tests/walk.test.ts +0 -84
- package/node_modules/@lua/shared-source-sync/tsconfig.json +0 -12
- package/node_modules/@lua/shared-source-sync/tsup.config.ts +0 -9
- package/node_modules/@lua/shared-source-sync/vitest.config.ts +0 -8
- package/node_modules/@lua/shared-types/dist/index.d.mts +0 -619
- package/node_modules/@lua/shared-types/dist/index.d.ts +0 -619
- package/node_modules/@lua/shared-types/dist/index.js +0 -435
- package/node_modules/@lua/shared-types/dist/index.mjs +0 -394
- package/node_modules/@lua/shared-types/package.json +0 -26
- package/node_modules/@lua/shared-types/src/agent-config.types.ts +0 -45
- package/node_modules/@lua/shared-types/src/agent-invocation.types.ts +0 -73
- package/node_modules/@lua/shared-types/src/ai-generate.types.ts +0 -74
- package/node_modules/@lua/shared-types/src/ai-generate.utils.ts +0 -16
- package/node_modules/@lua/shared-types/src/channel.type.ts +0 -23
- package/node_modules/@lua/shared-types/src/chat-history.types.ts +0 -112
- package/node_modules/@lua/shared-types/src/chat-stream.types.ts +0 -18
- package/node_modules/@lua/shared-types/src/client-tools.types.ts +0 -47
- package/node_modules/@lua/shared-types/src/device.types.ts +0 -190
- package/node_modules/@lua/shared-types/src/index.ts +0 -15
- package/node_modules/@lua/shared-types/src/model-registry.ts +0 -26
- package/node_modules/@lua/shared-types/src/persona-defaults.ts +0 -59
- package/node_modules/@lua/shared-types/src/persona-text.type.ts +0 -92
- package/node_modules/@lua/shared-types/src/sandbox-contract.ts +0 -63
- package/node_modules/@lua/shared-types/src/unstructured-types.ts +0 -58
- package/node_modules/@lua/shared-types/src/vm-execution-log.types.ts +0 -41
- package/node_modules/@lua/shared-types/tsconfig.json +0 -12
- package/node_modules/@lua/shared-types/tsup.config.ts +0 -9
- package/scripts/resolve-workspace-deps.cjs +0 -61
- /package/dist/{compiler/utils/zod-runtime.mjs → zod-runtime.mjs} +0 -0
|
@@ -1,2666 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integrations Command
|
|
3
|
-
* Manages third-party integrations via Unified.to
|
|
4
|
-
*
|
|
5
|
-
* Core concepts:
|
|
6
|
-
* - Integration: A supported third-party service (e.g., Linear, Google Calendar)
|
|
7
|
-
* - Connection: An authenticated link between your agent and a specific integration
|
|
8
|
-
* - MCP Server: Technical implementation that exposes connection tools to the agent (auto-managed)
|
|
9
|
-
*
|
|
10
|
-
* Flow:
|
|
11
|
-
* 1. User runs `lua integrations connect`
|
|
12
|
-
* 2. CLI fetches available integrations from Lua API
|
|
13
|
-
* 3. User authorizes via OAuth or provides API credentials
|
|
14
|
-
* 4. Connection is established and stored
|
|
15
|
-
* 5. MCP server is automatically created to expose tools to the agent
|
|
16
|
-
*/
|
|
17
|
-
import http from 'http';
|
|
18
|
-
import { URL } from 'url';
|
|
19
|
-
import open from 'open';
|
|
20
|
-
import { withErrorHandling, writeProgress, writeSuccess, writeInfo, writeError } from '../utils/cli.js';
|
|
21
|
-
import { BASE_URLS } from '../config/constants.js';
|
|
22
|
-
import { safePrompt } from '../utils/prompt-handler.js';
|
|
23
|
-
import { initializeCommand } from '../utils/command-utils.js';
|
|
24
|
-
import DeveloperApi from '../api/developer.api.service.js';
|
|
25
|
-
import UnifiedToApi from '../api/unifiedto.api.service.js';
|
|
26
|
-
import { fetchServersCore, activateServerCore, deactivateServerCore } from './mcp.js';
|
|
27
|
-
import { trackEvent } from '../services/analytics.js';
|
|
28
|
-
import { validateOrSuggest } from '../utils/aliases.js';
|
|
29
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
30
|
-
// Configuration
|
|
31
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
32
|
-
const CALLBACK_PORT = 19837; // Random high port for OAuth callback
|
|
33
|
-
const CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`;
|
|
34
|
-
// Webhook trigger configuration (AGENT_WEBHOOK_URL still used for display/info commands)
|
|
35
|
-
const AGENT_WEBHOOK_URL = `${BASE_URLS.API}/webhook/unifiedto/data`;
|
|
36
|
-
const DEFAULT_VIRTUAL_WEBHOOK_INTERVAL = 1; // minutes (paid Unified.to plan)
|
|
37
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
38
|
-
// Integration API Functions (via Lua API)
|
|
39
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
40
|
-
/**
|
|
41
|
-
* Fetches available (activated) integrations via Lua API
|
|
42
|
-
*/
|
|
43
|
-
async function fetchAvailableIntegrations(unifiedToApi, agentId) {
|
|
44
|
-
const result = await unifiedToApi.getAvailableIntegrations(agentId);
|
|
45
|
-
if (!result.success || !result.data) {
|
|
46
|
-
throw new Error(`Failed to fetch integrations: ${result.error?.message || 'Unknown error'}`);
|
|
47
|
-
}
|
|
48
|
-
return result.data.map((integration) => ({
|
|
49
|
-
name: integration.name,
|
|
50
|
-
value: integration.type,
|
|
51
|
-
categories: integration.categories || [],
|
|
52
|
-
authSupport: integration.authSupport,
|
|
53
|
-
oauthConfigured: integration.oauthConfigured,
|
|
54
|
-
oauthScopes: integration.oauthScopes,
|
|
55
|
-
tokenFields: integration.tokenFields,
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Starts a local HTTP server to receive the OAuth callback
|
|
60
|
-
* Returns a promise that resolves when the callback is received
|
|
61
|
-
*/
|
|
62
|
-
function startCallbackServer(timeoutMs = 300000) {
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
let resolved = false;
|
|
65
|
-
const server = http.createServer((req, res) => {
|
|
66
|
-
if (resolved)
|
|
67
|
-
return;
|
|
68
|
-
const reqUrl = new URL(req.url || '/', `http://localhost:${CALLBACK_PORT}`);
|
|
69
|
-
if (reqUrl.pathname === '/callback') {
|
|
70
|
-
const connectionId = reqUrl.searchParams.get('id');
|
|
71
|
-
const error = reqUrl.searchParams.get('error');
|
|
72
|
-
const logId = reqUrl.searchParams.get('log_id');
|
|
73
|
-
const integrationType = reqUrl.searchParams.get('type');
|
|
74
|
-
resolved = true;
|
|
75
|
-
if (error) {
|
|
76
|
-
// Unified.to redirects to failure_redirect with ?error=<oauth_error>&log_id=<trace_id>
|
|
77
|
-
const logIdHtml = logId ? `<p style="color: #888; font-size: 0.85em;">Log ID: <code>${logId}</code></p>` : '';
|
|
78
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
79
|
-
res.end(`
|
|
80
|
-
<!DOCTYPE html>
|
|
81
|
-
<html>
|
|
82
|
-
<head><title>Connection Failed</title></head>
|
|
83
|
-
<body style="font-family: system-ui; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #1a1a2e;">
|
|
84
|
-
<div style="text-align: center; color: white; max-width: 500px; padding: 0 20px;">
|
|
85
|
-
<h1 style="color: #ff6b6b;">Connection Failed</h1>
|
|
86
|
-
<p style="color: #ccc;">Error: ${error}</p>
|
|
87
|
-
${logIdHtml}
|
|
88
|
-
<p style="color: #888;">You can close this window and try again.</p>
|
|
89
|
-
</div>
|
|
90
|
-
</body>
|
|
91
|
-
</html>
|
|
92
|
-
`);
|
|
93
|
-
server.close();
|
|
94
|
-
resolve({ success: false, error, logId: logId || undefined });
|
|
95
|
-
}
|
|
96
|
-
else if (connectionId) {
|
|
97
|
-
// Send success page
|
|
98
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
99
|
-
res.end(`
|
|
100
|
-
<!DOCTYPE html>
|
|
101
|
-
<html>
|
|
102
|
-
<head><title>Connection Successful</title></head>
|
|
103
|
-
<body style="font-family: system-ui; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #1a1a2e;">
|
|
104
|
-
<div style="text-align: center; color: white;">
|
|
105
|
-
<h1 style="color: #4ade80;">✅ Connection Successful!</h1>
|
|
106
|
-
<p style="color: #ccc;">Your integration has been connected.</p>
|
|
107
|
-
<p style="color: #888;">You can close this window and return to the terminal.</p>
|
|
108
|
-
</div>
|
|
109
|
-
</body>
|
|
110
|
-
</html>
|
|
111
|
-
`);
|
|
112
|
-
server.close();
|
|
113
|
-
resolve({ success: true, connectionId, integrationType: integrationType || undefined });
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
res.writeHead(400, { 'Content-Type': 'text/plain' });
|
|
117
|
-
res.end('Missing connection ID');
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
122
|
-
res.end('Not found');
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
server.listen(CALLBACK_PORT, () => {
|
|
126
|
-
// Server started
|
|
127
|
-
});
|
|
128
|
-
// Timeout after specified time
|
|
129
|
-
setTimeout(() => {
|
|
130
|
-
if (!resolved) {
|
|
131
|
-
resolved = true;
|
|
132
|
-
server.close();
|
|
133
|
-
resolve({ success: false, error: 'Timeout waiting for OAuth callback' });
|
|
134
|
-
}
|
|
135
|
-
}, timeoutMs);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
139
|
-
// Main Command Entry
|
|
140
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
141
|
-
export async function integrationsCommand(action, subaction, cmdObj) {
|
|
142
|
-
return withErrorHandling(async () => {
|
|
143
|
-
// Initialize command (validates config + auth)
|
|
144
|
-
const { agentId, apiKey, userData } = await initializeCommand({ showProgress: false, validateAuth: true });
|
|
145
|
-
const userId = userData?.admin?.userId;
|
|
146
|
-
if (!userId) {
|
|
147
|
-
console.error('❌ Failed to get user ID from authentication.');
|
|
148
|
-
throw new Error('Failed to get user ID from authentication.');
|
|
149
|
-
}
|
|
150
|
-
const developerApi = new DeveloperApi(BASE_URLS.API, apiKey, agentId);
|
|
151
|
-
const unifiedToApi = new UnifiedToApi(BASE_URLS.API, apiKey);
|
|
152
|
-
const context = {
|
|
153
|
-
agentId,
|
|
154
|
-
userId,
|
|
155
|
-
apiKey,
|
|
156
|
-
developerApi,
|
|
157
|
-
unifiedToApi,
|
|
158
|
-
};
|
|
159
|
-
if (action) {
|
|
160
|
-
// Pass subaction via cmdObj for webhooks command
|
|
161
|
-
const enhancedCmdObj = { ...cmdObj, _: subaction ? [subaction] : [] };
|
|
162
|
-
await executeNonInteractive(context, action, enhancedCmdObj);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
await interactiveIntegrationsManagement(context);
|
|
166
|
-
}
|
|
167
|
-
trackEvent('cli_integration_action', {
|
|
168
|
-
action: action || 'interactive',
|
|
169
|
-
sub_action: subaction || null,
|
|
170
|
-
integration_type: cmdObj?.integration || null,
|
|
171
|
-
non_interactive: !!action,
|
|
172
|
-
});
|
|
173
|
-
}, 'integrations');
|
|
174
|
-
}
|
|
175
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
176
|
-
// Non-Interactive Mode
|
|
177
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
178
|
-
async function executeNonInteractive(context, action, cmdOptions) {
|
|
179
|
-
const normalizedAction = validateOrSuggest('integrations.action', action);
|
|
180
|
-
// Extract typed options
|
|
181
|
-
const options = {
|
|
182
|
-
integration: cmdOptions?.integration,
|
|
183
|
-
connectionId: cmdOptions?.connectionId,
|
|
184
|
-
authMethod: cmdOptions?.authMethod,
|
|
185
|
-
scopes: cmdOptions?.scopes,
|
|
186
|
-
hideSensitive: cmdOptions?.hideSensitive === 'true', // Default false, only true if explicitly set
|
|
187
|
-
// Trigger options
|
|
188
|
-
triggers: cmdOptions?.triggers,
|
|
189
|
-
customWebhook: cmdOptions?.customWebhook === true,
|
|
190
|
-
hookUrl: cmdOptions?.hookUrl,
|
|
191
|
-
};
|
|
192
|
-
// Check for JSON output flag
|
|
193
|
-
const jsonOutput = cmdOptions?.json === true;
|
|
194
|
-
switch (normalizedAction) {
|
|
195
|
-
case 'connect':
|
|
196
|
-
await connectIntegrationFlow(context, options);
|
|
197
|
-
break;
|
|
198
|
-
case 'update':
|
|
199
|
-
if (!options.integration) {
|
|
200
|
-
console.error('❌ --integration is required for update');
|
|
201
|
-
console.log("\n💡 Run 'lua integrations list' to see connected integrations");
|
|
202
|
-
throw new Error('--integration is required for update');
|
|
203
|
-
}
|
|
204
|
-
await updateConnectionFlow(context, options);
|
|
205
|
-
break;
|
|
206
|
-
case 'list':
|
|
207
|
-
await listConnections(context);
|
|
208
|
-
break;
|
|
209
|
-
case 'available':
|
|
210
|
-
await listAvailableIntegrations(context);
|
|
211
|
-
break;
|
|
212
|
-
case 'info':
|
|
213
|
-
// New command: Show detailed info about an integration type
|
|
214
|
-
// Integration type can be passed as positional arg (info <type>) or as --integration flag
|
|
215
|
-
const infoIntegrationType = options.integration || cmdOptions?._?.[0];
|
|
216
|
-
if (!infoIntegrationType) {
|
|
217
|
-
console.error('❌ Integration type is required');
|
|
218
|
-
console.log('\nUsage: lua integrations info <type>');
|
|
219
|
-
console.log(' lua integrations info <type> --json');
|
|
220
|
-
throw new Error('Integration type is required');
|
|
221
|
-
}
|
|
222
|
-
await showIntegrationInfo(context, infoIntegrationType, jsonOutput);
|
|
223
|
-
break;
|
|
224
|
-
case 'disconnect':
|
|
225
|
-
if (!options.connectionId) {
|
|
226
|
-
console.error('❌ --connection-id is required for disconnect');
|
|
227
|
-
console.log("\n💡 Run 'lua integrations list' to see connection IDs");
|
|
228
|
-
throw new Error('--connection-id is required for disconnect');
|
|
229
|
-
}
|
|
230
|
-
await disconnectIntegration(context, options.connectionId);
|
|
231
|
-
break;
|
|
232
|
-
case 'webhooks':
|
|
233
|
-
await webhooksSubcommand(context, cmdOptions);
|
|
234
|
-
break;
|
|
235
|
-
case 'mcp':
|
|
236
|
-
await mcpSubcommand(context, cmdOptions);
|
|
237
|
-
break;
|
|
238
|
-
default:
|
|
239
|
-
console.error(`❌ Invalid action: "${action}"`);
|
|
240
|
-
showUsage();
|
|
241
|
-
throw new Error('Invalid action:');
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
245
|
-
// Interactive Mode
|
|
246
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
247
|
-
async function interactiveIntegrationsManagement(context) {
|
|
248
|
-
let continueManaging = true;
|
|
249
|
-
while (continueManaging) {
|
|
250
|
-
console.log('\n' + '='.repeat(60));
|
|
251
|
-
console.log('🔗 Integrations');
|
|
252
|
-
console.log('='.repeat(60) + '\n');
|
|
253
|
-
const actionAnswer = await safePrompt([
|
|
254
|
-
{
|
|
255
|
-
type: 'list',
|
|
256
|
-
name: 'action',
|
|
257
|
-
message: 'What would you like to do?',
|
|
258
|
-
choices: [
|
|
259
|
-
{ name: '➕ Connect a new integration', value: 'connect' },
|
|
260
|
-
{ name: '🔄 Update connection scopes', value: 'update' },
|
|
261
|
-
{ name: '📋 List connected integrations', value: 'list' },
|
|
262
|
-
{ name: '🔍 View available integrations', value: 'available' },
|
|
263
|
-
{ name: '🔔 Manage triggers', value: 'webhooks' },
|
|
264
|
-
{ name: '🔌 Manage MCP servers', value: 'mcp' },
|
|
265
|
-
{ name: '🗑️ Disconnect an integration', value: 'disconnect' },
|
|
266
|
-
{ name: '❌ Exit', value: 'exit' },
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
]);
|
|
270
|
-
if (!actionAnswer)
|
|
271
|
-
return;
|
|
272
|
-
const { action } = actionAnswer;
|
|
273
|
-
switch (action) {
|
|
274
|
-
case 'connect':
|
|
275
|
-
await connectIntegrationFlow(context);
|
|
276
|
-
break;
|
|
277
|
-
case 'update':
|
|
278
|
-
await updateConnectionFlow(context);
|
|
279
|
-
break;
|
|
280
|
-
case 'list':
|
|
281
|
-
await listConnections(context);
|
|
282
|
-
break;
|
|
283
|
-
case 'available':
|
|
284
|
-
await listAvailableIntegrations(context);
|
|
285
|
-
break;
|
|
286
|
-
case 'webhooks':
|
|
287
|
-
await webhooksInteractiveMenu(context);
|
|
288
|
-
break;
|
|
289
|
-
case 'mcp':
|
|
290
|
-
await mcpManagementFlow(context, {});
|
|
291
|
-
break;
|
|
292
|
-
case 'disconnect':
|
|
293
|
-
await disconnectIntegrationInteractive(context);
|
|
294
|
-
break;
|
|
295
|
-
case 'exit':
|
|
296
|
-
continueManaging = false;
|
|
297
|
-
console.log('\n👋 Goodbye!\n');
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
303
|
-
// List Available Integrations
|
|
304
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
305
|
-
async function listAvailableIntegrations(context) {
|
|
306
|
-
writeProgress('🔄 Fetching available integrations...');
|
|
307
|
-
try {
|
|
308
|
-
const integrations = await fetchAvailableIntegrations(context.unifiedToApi);
|
|
309
|
-
console.log('\n' + '='.repeat(60));
|
|
310
|
-
console.log('🔌 Available Integrations');
|
|
311
|
-
console.log('='.repeat(60) + '\n');
|
|
312
|
-
if (integrations.length === 0) {
|
|
313
|
-
console.log('ℹ️ No integrations available.');
|
|
314
|
-
console.log('💡 Contact support to enable integrations for your workspace.\n');
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
// Group by category
|
|
318
|
-
const byCategory = {};
|
|
319
|
-
for (const integration of integrations) {
|
|
320
|
-
const category = integration.categories[0] || 'other';
|
|
321
|
-
if (!byCategory[category])
|
|
322
|
-
byCategory[category] = [];
|
|
323
|
-
byCategory[category].push(integration);
|
|
324
|
-
}
|
|
325
|
-
for (const [category, items] of Object.entries(byCategory)) {
|
|
326
|
-
console.log(`📁 ${category.toUpperCase()}`);
|
|
327
|
-
items.forEach((i) => {
|
|
328
|
-
const authBadge = i.authSupport === 'oauth' ? '🔐' : i.authSupport === 'token' ? '🔑' : '🔐🔑';
|
|
329
|
-
console.log(` ${authBadge} ${i.name} (${i.value})`);
|
|
330
|
-
});
|
|
331
|
-
console.log();
|
|
332
|
-
}
|
|
333
|
-
console.log('='.repeat(60));
|
|
334
|
-
console.log(`Total: ${integrations.length} integration(s) available`);
|
|
335
|
-
console.log('🔐 = OAuth 🔑 = API Key/Token 🔐🔑 = Both\n');
|
|
336
|
-
}
|
|
337
|
-
catch (error) {
|
|
338
|
-
writeError(`❌ Failed to fetch integrations: ${error.message}`);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
342
|
-
// Integration Info (Non-Interactive Discovery)
|
|
343
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
344
|
-
/**
|
|
345
|
-
* Show detailed information about an integration type
|
|
346
|
-
* Used for non-interactive discovery of OAuth scopes and webhook events
|
|
347
|
-
*/
|
|
348
|
-
async function showIntegrationInfo(context, integrationType, jsonOutput = false) {
|
|
349
|
-
try {
|
|
350
|
-
// Fetch integration details
|
|
351
|
-
const integrations = await fetchAvailableIntegrations(context.unifiedToApi);
|
|
352
|
-
const integration = integrations.find((i) => i.value === integrationType);
|
|
353
|
-
if (!integration) {
|
|
354
|
-
if (jsonOutput) {
|
|
355
|
-
console.log(JSON.stringify({ error: `Integration not found: ${integrationType}` }));
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
console.error(`❌ Integration not found: ${integrationType}`);
|
|
359
|
-
console.log('\nAvailable integrations:');
|
|
360
|
-
integrations.forEach((i) => console.log(` - ${i.value} (${i.name})`));
|
|
361
|
-
}
|
|
362
|
-
throw new Error('Operation failed');
|
|
363
|
-
}
|
|
364
|
-
// Fetch available webhook events for this integration
|
|
365
|
-
let webhookEvents = [];
|
|
366
|
-
try {
|
|
367
|
-
const eventsResult = await context.unifiedToApi.getAvailableWebhookEventsByType(integrationType);
|
|
368
|
-
if (eventsResult.success && eventsResult.data) {
|
|
369
|
-
webhookEvents = eventsResult.data;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
catch {
|
|
373
|
-
// Silently ignore if webhook events can't be fetched
|
|
374
|
-
}
|
|
375
|
-
if (jsonOutput) {
|
|
376
|
-
// Output as JSON for scripting
|
|
377
|
-
const output = {
|
|
378
|
-
type: integration.value,
|
|
379
|
-
name: integration.name,
|
|
380
|
-
categories: integration.categories,
|
|
381
|
-
authSupport: integration.authSupport,
|
|
382
|
-
oauthConfigured: integration.oauthConfigured,
|
|
383
|
-
oauthScopes: integration.oauthScopes || [],
|
|
384
|
-
tokenFields: integration.tokenFields || [],
|
|
385
|
-
webhookEvents: webhookEvents.map((e) => ({
|
|
386
|
-
trigger: `${e.objectType}.${e.event}`,
|
|
387
|
-
objectType: e.objectType,
|
|
388
|
-
event: e.event,
|
|
389
|
-
webhookType: e.webhookType,
|
|
390
|
-
friendlyLabel: e.friendlyLabel,
|
|
391
|
-
friendlyDescription: e.friendlyDescription,
|
|
392
|
-
availableFilters: e.availableFilters,
|
|
393
|
-
})),
|
|
394
|
-
webhookDefaults: {
|
|
395
|
-
agentWebhookUrl: AGENT_WEBHOOK_URL,
|
|
396
|
-
defaultVirtualInterval: DEFAULT_VIRTUAL_WEBHOOK_INTERVAL,
|
|
397
|
-
},
|
|
398
|
-
};
|
|
399
|
-
console.log(JSON.stringify(output, null, 2));
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
// Human-readable output
|
|
403
|
-
console.log('\n' + '='.repeat(60));
|
|
404
|
-
console.log(`📋 Integration: ${integration.name}`);
|
|
405
|
-
console.log('='.repeat(60));
|
|
406
|
-
console.log(`\n Type: ${integration.value}`);
|
|
407
|
-
console.log(` Categories: ${integration.categories.join(', ')}`);
|
|
408
|
-
console.log(` Auth Support: ${integration.authSupport}`);
|
|
409
|
-
console.log(` OAuth Configured: ${integration.oauthConfigured ? 'Yes' : 'No'}`);
|
|
410
|
-
// OAuth Scopes
|
|
411
|
-
if (integration.oauthScopes && integration.oauthScopes.length > 0) {
|
|
412
|
-
console.log('\n OAuth Scopes:');
|
|
413
|
-
integration.oauthScopes.forEach((s) => {
|
|
414
|
-
if (s.friendlyLabel) {
|
|
415
|
-
console.log(` - ${s.friendlyLabel} (${s.unifiedScope})`);
|
|
416
|
-
if (s.friendlyDescription) {
|
|
417
|
-
console.log(` ${s.friendlyDescription}`);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
console.log(` - ${s.unifiedScope} → [${s.originalScopes.join(', ')}]`);
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
// Token Fields
|
|
426
|
-
if (integration.tokenFields && integration.tokenFields.length > 0) {
|
|
427
|
-
console.log('\n Token Fields:');
|
|
428
|
-
integration.tokenFields.forEach((f) => {
|
|
429
|
-
console.log(` - ${f.name}`);
|
|
430
|
-
if (f.instructions) {
|
|
431
|
-
console.log(` 💡 ${f.instructions}`);
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
// Webhook Events/Triggers
|
|
436
|
-
if (webhookEvents.length > 0) {
|
|
437
|
-
console.log('\n Available Triggers:');
|
|
438
|
-
webhookEvents.forEach((e) => {
|
|
439
|
-
console.log(` - ${e.objectType}.${e.event} [${e.webhookType}] - ${e.friendlyDescription}`);
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
console.log('\n Available Triggers: None');
|
|
444
|
-
}
|
|
445
|
-
console.log('\n' + '='.repeat(60));
|
|
446
|
-
console.log('\n💡 Use with non-interactive commands:');
|
|
447
|
-
console.log(` lua integrations connect --integration ${integrationType} --auth-method oauth --scopes all`);
|
|
448
|
-
if (webhookEvents.length > 0) {
|
|
449
|
-
const exampleTrigger = `${webhookEvents[0].objectType}.${webhookEvents[0].event}`;
|
|
450
|
-
console.log(` lua integrations connect --integration ${integrationType} --triggers ${exampleTrigger}`);
|
|
451
|
-
}
|
|
452
|
-
console.log();
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
catch (error) {
|
|
456
|
-
if (jsonOutput) {
|
|
457
|
-
console.log(JSON.stringify({ error: error.message }));
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
writeError(`❌ Failed to get integration info: ${error.message}`);
|
|
461
|
-
}
|
|
462
|
-
throw new Error('Operation failed');
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
466
|
-
// Connect Flow
|
|
467
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
468
|
-
async function connectIntegrationFlow(context, options = {}) {
|
|
469
|
-
// Step 1: Fetch available integrations (API excludes already-connected types)
|
|
470
|
-
writeProgress('🔄 Fetching integrations...');
|
|
471
|
-
let availableIntegrations;
|
|
472
|
-
try {
|
|
473
|
-
availableIntegrations = await fetchAvailableIntegrations(context.unifiedToApi, context.agentId);
|
|
474
|
-
}
|
|
475
|
-
catch (error) {
|
|
476
|
-
writeError(`❌ Failed to fetch integrations: ${error.message}`);
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
if (availableIntegrations.length === 0) {
|
|
480
|
-
writeInfo('All available integrations are already connected (or none are enabled).');
|
|
481
|
-
console.log("💡 Use 'lua integrations update' to change scopes on an existing connection.\n");
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
writeSuccess(`Found ${availableIntegrations.length} integration(s) available to connect`);
|
|
485
|
-
// Step 2: Select integration (with search/filter support)
|
|
486
|
-
let selectedIntegration;
|
|
487
|
-
if (options.integration) {
|
|
488
|
-
selectedIntegration = availableIntegrations.find((i) => i.value === options.integration);
|
|
489
|
-
if (!selectedIntegration) {
|
|
490
|
-
// Not in available list — either already connected or doesn't exist
|
|
491
|
-
console.error(`❌ Integration "${options.integration}" not found or already connected.`);
|
|
492
|
-
console.log("💡 If already connected, use 'lua integrations update --integration " +
|
|
493
|
-
options.integration +
|
|
494
|
-
"' to change scopes.");
|
|
495
|
-
if (availableIntegrations.length > 0) {
|
|
496
|
-
console.log('\nAvailable integrations to connect:');
|
|
497
|
-
availableIntegrations.forEach((i) => console.log(` - ${i.value} (${i.name})`));
|
|
498
|
-
}
|
|
499
|
-
throw new Error('Integration');
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
// Ask if user wants to search or browse all
|
|
504
|
-
const searchAnswer = await safePrompt([
|
|
505
|
-
{
|
|
506
|
-
type: 'input',
|
|
507
|
-
name: 'searchTerm',
|
|
508
|
-
message: 'Search integrations (or press Enter to browse all):',
|
|
509
|
-
},
|
|
510
|
-
]);
|
|
511
|
-
if (!searchAnswer)
|
|
512
|
-
return;
|
|
513
|
-
// Filter integrations based on search term
|
|
514
|
-
let filteredIntegrations = availableIntegrations;
|
|
515
|
-
if (searchAnswer.searchTerm.trim()) {
|
|
516
|
-
const searchLower = searchAnswer.searchTerm.toLowerCase().trim();
|
|
517
|
-
filteredIntegrations = availableIntegrations.filter((i) => i.name.toLowerCase().includes(searchLower) ||
|
|
518
|
-
i.value.toLowerCase().includes(searchLower) ||
|
|
519
|
-
i.categories.some((c) => c.toLowerCase().includes(searchLower)));
|
|
520
|
-
if (filteredIntegrations.length === 0) {
|
|
521
|
-
writeInfo(`No available integrations found matching "${searchAnswer.searchTerm}"`);
|
|
522
|
-
console.log(`💡 If the integration is already connected, use 'lua integrations update' to change scopes.`);
|
|
523
|
-
// Offer to browse all
|
|
524
|
-
const browseAnswer = await safePrompt([
|
|
525
|
-
{
|
|
526
|
-
type: 'confirm',
|
|
527
|
-
name: 'browseAll',
|
|
528
|
-
message: 'Would you like to browse all available integrations?',
|
|
529
|
-
default: true,
|
|
530
|
-
},
|
|
531
|
-
]);
|
|
532
|
-
if (!browseAnswer?.browseAll)
|
|
533
|
-
return;
|
|
534
|
-
filteredIntegrations = availableIntegrations;
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
writeInfo(`Found ${filteredIntegrations.length} integration(s) matching "${searchAnswer.searchTerm}"`);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
const integrationAnswer = await safePrompt([
|
|
541
|
-
{
|
|
542
|
-
type: 'list',
|
|
543
|
-
name: 'integration',
|
|
544
|
-
message: 'Select an integration to connect:',
|
|
545
|
-
pageSize: 15,
|
|
546
|
-
choices: filteredIntegrations.map((i) => {
|
|
547
|
-
const authBadge = i.authSupport === 'oauth' ? '🔐' : i.authSupport === 'token' ? '🔑' : '🔐🔑';
|
|
548
|
-
return {
|
|
549
|
-
name: `${authBadge} ${i.name} (${i.categories.join(', ')})`,
|
|
550
|
-
value: i,
|
|
551
|
-
};
|
|
552
|
-
}),
|
|
553
|
-
},
|
|
554
|
-
]);
|
|
555
|
-
if (!integrationAnswer)
|
|
556
|
-
return;
|
|
557
|
-
selectedIntegration = integrationAnswer.integration;
|
|
558
|
-
}
|
|
559
|
-
console.log(`\n📌 Selected: ${selectedIntegration.name}`);
|
|
560
|
-
console.log(` Categories: ${selectedIntegration.categories.join(', ')}`);
|
|
561
|
-
console.log(` Auth Support: ${selectedIntegration.authSupport}`);
|
|
562
|
-
console.log(` OAuth Configured: ${selectedIntegration.oauthConfigured ? 'Yes' : 'No'}`);
|
|
563
|
-
// Step 3: Determine auth method and get scopes
|
|
564
|
-
const canUseOAuth = selectedIntegration.oauthConfigured && ['oauth', 'both'].includes(selectedIntegration.authSupport);
|
|
565
|
-
const canUseToken = ['token', 'both'].includes(selectedIntegration.authSupport);
|
|
566
|
-
let authMethod;
|
|
567
|
-
let selectedScopes = [];
|
|
568
|
-
// Validate --auth-method if provided
|
|
569
|
-
if (options.authMethod) {
|
|
570
|
-
if (!['oauth', 'token'].includes(options.authMethod)) {
|
|
571
|
-
console.error(`❌ Invalid --auth-method: "${options.authMethod}". Use 'oauth' or 'token'`);
|
|
572
|
-
throw new Error('Invalid --auth-method:');
|
|
573
|
-
}
|
|
574
|
-
if (options.authMethod === 'oauth' && !canUseOAuth) {
|
|
575
|
-
console.error(`❌ OAuth is not available for ${selectedIntegration.name}.`);
|
|
576
|
-
if (canUseToken) {
|
|
577
|
-
console.log(`💡 Use --auth-method token instead.`);
|
|
578
|
-
}
|
|
579
|
-
throw new Error('Operation failed');
|
|
580
|
-
}
|
|
581
|
-
if (options.authMethod === 'token' && !canUseToken) {
|
|
582
|
-
console.error(`❌ Token authentication is not available for ${selectedIntegration.name}.`);
|
|
583
|
-
if (canUseOAuth) {
|
|
584
|
-
console.log(`💡 Use --auth-method oauth instead.`);
|
|
585
|
-
}
|
|
586
|
-
throw new Error('Operation failed');
|
|
587
|
-
}
|
|
588
|
-
authMethod = options.authMethod;
|
|
589
|
-
writeInfo(`Using ${authMethod === 'oauth' ? 'OAuth 2.0' : 'API Token'} authentication`);
|
|
590
|
-
}
|
|
591
|
-
else if (canUseOAuth && canUseToken) {
|
|
592
|
-
// Both available - let user choose interactively
|
|
593
|
-
const authAnswer = await safePrompt([
|
|
594
|
-
{
|
|
595
|
-
type: 'list',
|
|
596
|
-
name: 'method',
|
|
597
|
-
message: 'Choose authentication method:',
|
|
598
|
-
choices: [
|
|
599
|
-
{ name: '🔐 OAuth 2.0 (recommended)', value: 'oauth' },
|
|
600
|
-
{ name: '🔑 API Token / Personal Access Token', value: 'token' },
|
|
601
|
-
],
|
|
602
|
-
},
|
|
603
|
-
]);
|
|
604
|
-
if (!authAnswer)
|
|
605
|
-
return;
|
|
606
|
-
authMethod = authAnswer.method;
|
|
607
|
-
}
|
|
608
|
-
else if (canUseOAuth) {
|
|
609
|
-
authMethod = 'oauth';
|
|
610
|
-
writeInfo('Using OAuth 2.0 authentication');
|
|
611
|
-
}
|
|
612
|
-
else if (canUseToken) {
|
|
613
|
-
authMethod = 'token';
|
|
614
|
-
if (selectedIntegration.authSupport === 'both' && !selectedIntegration.oauthConfigured) {
|
|
615
|
-
writeInfo('OAuth is not configured - using API Token authentication');
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
else {
|
|
619
|
-
writeError('This integration requires OAuth but it is not configured. Please configure OAuth credentials in the Unified.to dashboard.');
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
// Handle OAuth scope selection
|
|
623
|
-
if (authMethod === 'oauth' && selectedIntegration.oauthScopes?.length) {
|
|
624
|
-
const availableScopes = selectedIntegration.oauthScopes.map((s) => s.unifiedScope);
|
|
625
|
-
if (options.scopes) {
|
|
626
|
-
// Non-interactive: use provided scopes
|
|
627
|
-
if (options.scopes.toLowerCase() === 'all') {
|
|
628
|
-
selectedScopes = availableScopes;
|
|
629
|
-
writeInfo(`Using all ${selectedScopes.length} available scope(s)`);
|
|
630
|
-
}
|
|
631
|
-
else {
|
|
632
|
-
// Parse comma-separated scopes
|
|
633
|
-
const requestedScopes = options.scopes.split(',').map((s) => s.trim());
|
|
634
|
-
const invalidScopes = requestedScopes.filter((s) => !availableScopes.includes(s));
|
|
635
|
-
if (invalidScopes.length > 0) {
|
|
636
|
-
console.error(`❌ Invalid scopes: ${invalidScopes.join(', ')}`);
|
|
637
|
-
console.log(`\nAvailable scopes for ${selectedIntegration.name}:`);
|
|
638
|
-
availableScopes.forEach((s) => console.log(` - ${s}`));
|
|
639
|
-
throw new Error('Invalid scopes: ${invalidScopes.join(');
|
|
640
|
-
}
|
|
641
|
-
selectedScopes = requestedScopes;
|
|
642
|
-
writeInfo(`Using ${selectedScopes.length} specified scope(s)`);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
else {
|
|
646
|
-
// Interactive: prompt for scope selection
|
|
647
|
-
const scopeAnswer = await safePrompt([
|
|
648
|
-
{
|
|
649
|
-
type: 'checkbox',
|
|
650
|
-
name: 'scopes',
|
|
651
|
-
message: 'Select OAuth scopes (Space to toggle, Enter to confirm, leave empty for all):',
|
|
652
|
-
pageSize: 15,
|
|
653
|
-
loop: false,
|
|
654
|
-
choices: selectedIntegration.oauthScopes.map((s) => {
|
|
655
|
-
// Use friendly label if available, otherwise fall back to technical name
|
|
656
|
-
const displayName = s.friendlyLabel || s.unifiedScope;
|
|
657
|
-
const description = s.friendlyDescription
|
|
658
|
-
? ` (${s.friendlyDescription})`
|
|
659
|
-
: ` → [${s.originalScopes.join(', ')}]`;
|
|
660
|
-
return {
|
|
661
|
-
name: `${displayName}${description}`,
|
|
662
|
-
value: s.unifiedScope,
|
|
663
|
-
checked: false,
|
|
664
|
-
};
|
|
665
|
-
}),
|
|
666
|
-
},
|
|
667
|
-
]);
|
|
668
|
-
if (!scopeAnswer)
|
|
669
|
-
return;
|
|
670
|
-
// If none selected, request all scopes
|
|
671
|
-
selectedScopes = scopeAnswer.scopes.length > 0 ? scopeAnswer.scopes : availableScopes;
|
|
672
|
-
console.log(`\n✓ Will request ${selectedScopes.length} scope(s)`);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
else if (authMethod === 'oauth') {
|
|
676
|
-
// OAuth without configurable scopes - Unified.to handles defaults internally
|
|
677
|
-
if (options.scopes) {
|
|
678
|
-
writeInfo('Note: This integration does not have configurable scopes');
|
|
679
|
-
}
|
|
680
|
-
// selectedScopes stays empty - MCP URL will omit permissions param
|
|
681
|
-
}
|
|
682
|
-
// Handle token field display
|
|
683
|
-
if (authMethod === 'token' && selectedIntegration.tokenFields?.length) {
|
|
684
|
-
console.log('\n🔑 You will need to provide the following credentials:\n');
|
|
685
|
-
selectedIntegration.tokenFields.forEach((field, i) => {
|
|
686
|
-
console.log(` ${i + 1}. ${field.name}`);
|
|
687
|
-
if (field.instructions) {
|
|
688
|
-
console.log(` 💡 ${field.instructions}`);
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
console.log('\nYou will enter these on the Unified.to authorization page.\n');
|
|
692
|
-
}
|
|
693
|
-
// Determine hide_sensitive setting
|
|
694
|
-
let hideSensitive = false; // Default to false (expose all fields for better agent comprehension)
|
|
695
|
-
if (options.hideSensitive !== undefined) {
|
|
696
|
-
hideSensitive = options.hideSensitive;
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
// Interactive: ask user
|
|
700
|
-
const sensitiveAnswer = await safePrompt([
|
|
701
|
-
{
|
|
702
|
-
type: 'confirm',
|
|
703
|
-
name: 'hide',
|
|
704
|
-
message: 'Hide sensitive data (PII) from MCP tools?',
|
|
705
|
-
default: false,
|
|
706
|
-
},
|
|
707
|
-
]);
|
|
708
|
-
if (sensitiveAnswer) {
|
|
709
|
-
hideSensitive = sensitiveAnswer.hide;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
// Step 4: Select webhook triggers (agent wake-up events)
|
|
713
|
-
let selectedTriggers = [];
|
|
714
|
-
let webhookUrl = AGENT_WEBHOOK_URL; // Default: agent trigger mode
|
|
715
|
-
let isCustomWebhook = false;
|
|
716
|
-
try {
|
|
717
|
-
const eventsResult = await context.unifiedToApi.getAvailableWebhookEventsByType(selectedIntegration.value);
|
|
718
|
-
if (eventsResult.success && eventsResult.data && eventsResult.data.length > 0) {
|
|
719
|
-
const availableEvents = eventsResult.data;
|
|
720
|
-
// Determine webhook mode
|
|
721
|
-
if (options.customWebhook || options.hookUrl) {
|
|
722
|
-
isCustomWebhook = true;
|
|
723
|
-
if (options.hookUrl) {
|
|
724
|
-
webhookUrl = options.hookUrl;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
if (options.triggers) {
|
|
728
|
-
// Non-interactive: parse comma-separated triggers (e.g., 'task_task.created,task_task.updated')
|
|
729
|
-
const requestedTriggers = options.triggers.split(',').map((t) => t.trim());
|
|
730
|
-
for (const trigger of requestedTriggers) {
|
|
731
|
-
const [objectType, event] = trigger.split('.');
|
|
732
|
-
const matchingEvent = availableEvents.find((e) => e.objectType === objectType && e.event === event);
|
|
733
|
-
if (!matchingEvent) {
|
|
734
|
-
console.error(`❌ Invalid trigger: ${trigger}`);
|
|
735
|
-
console.log(`\nAvailable triggers for ${selectedIntegration.name}:`);
|
|
736
|
-
availableEvents.forEach((e) => {
|
|
737
|
-
console.log(` - ${e.objectType}.${e.event} [${e.webhookType}] - ${e.friendlyDescription}`);
|
|
738
|
-
});
|
|
739
|
-
throw new Error('Invalid trigger: ${trigger}');
|
|
740
|
-
}
|
|
741
|
-
selectedTriggers.push(matchingEvent);
|
|
742
|
-
}
|
|
743
|
-
writeInfo(`Selected ${selectedTriggers.length} trigger(s)`);
|
|
744
|
-
// If custom webhook mode, prompt for URL if not provided
|
|
745
|
-
if (isCustomWebhook && !options.hookUrl) {
|
|
746
|
-
const urlAnswer = await safePrompt([
|
|
747
|
-
{
|
|
748
|
-
type: 'input',
|
|
749
|
-
name: 'url',
|
|
750
|
-
message: 'Enter your webhook URL:',
|
|
751
|
-
validate: (input) => {
|
|
752
|
-
try {
|
|
753
|
-
new URL(input);
|
|
754
|
-
return true;
|
|
755
|
-
}
|
|
756
|
-
catch {
|
|
757
|
-
return 'Please enter a valid URL';
|
|
758
|
-
}
|
|
759
|
-
},
|
|
760
|
-
},
|
|
761
|
-
]);
|
|
762
|
-
if (!urlAnswer)
|
|
763
|
-
return;
|
|
764
|
-
webhookUrl = urlAnswer.url;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
else {
|
|
768
|
-
// Interactive: opt-in gate — ask before showing trigger selector
|
|
769
|
-
console.log('\n' + '─'.repeat(60));
|
|
770
|
-
console.log('📡 Webhook Triggers (Optional)');
|
|
771
|
-
console.log('─'.repeat(60));
|
|
772
|
-
console.log('\nTriggers wake your agent when something happens in the integration.');
|
|
773
|
-
console.log('We recommend adding only what you actually need — you can always add them later.');
|
|
774
|
-
const wantTriggersAnswer = await safePrompt([
|
|
775
|
-
{
|
|
776
|
-
type: 'confirm',
|
|
777
|
-
name: 'want',
|
|
778
|
-
message: 'Do you want to configure triggers now?',
|
|
779
|
-
default: false,
|
|
780
|
-
},
|
|
781
|
-
]);
|
|
782
|
-
if (!wantTriggersAnswer)
|
|
783
|
-
return;
|
|
784
|
-
if (wantTriggersAnswer.want) {
|
|
785
|
-
console.log('\nSelect the events you actually need:');
|
|
786
|
-
console.log('(Space to toggle, Enter to confirm. Nothing pre-selected.)');
|
|
787
|
-
const triggerAnswer = await safePrompt([
|
|
788
|
-
{
|
|
789
|
-
type: 'checkbox',
|
|
790
|
-
name: 'triggers',
|
|
791
|
-
message: 'Select triggers:',
|
|
792
|
-
pageSize: 15,
|
|
793
|
-
loop: false,
|
|
794
|
-
choices: availableEvents.map((e) => ({
|
|
795
|
-
name: `${e.friendlyDescription} [${e.webhookType}]`,
|
|
796
|
-
value: e,
|
|
797
|
-
checked: false, // None pre-selected — user chooses what they need
|
|
798
|
-
})),
|
|
799
|
-
},
|
|
800
|
-
]);
|
|
801
|
-
if (triggerAnswer && triggerAnswer.triggers.length > 0) {
|
|
802
|
-
selectedTriggers = triggerAnswer.triggers;
|
|
803
|
-
// Ask about webhook mode only if triggers are selected
|
|
804
|
-
const modeAnswer = await safePrompt([
|
|
805
|
-
{
|
|
806
|
-
type: 'list',
|
|
807
|
-
name: 'mode',
|
|
808
|
-
message: 'How should these events be handled?',
|
|
809
|
-
choices: [
|
|
810
|
-
{ name: '🤖 Agent Trigger (recommended) - Events wake up your agent', value: 'agent' },
|
|
811
|
-
{ name: '🔗 Custom URL - Send events to your own webhook URL', value: 'custom' },
|
|
812
|
-
],
|
|
813
|
-
},
|
|
814
|
-
]);
|
|
815
|
-
if (!modeAnswer)
|
|
816
|
-
return;
|
|
817
|
-
if (modeAnswer.mode === 'custom') {
|
|
818
|
-
isCustomWebhook = true;
|
|
819
|
-
const urlAnswer = await safePrompt([
|
|
820
|
-
{
|
|
821
|
-
type: 'input',
|
|
822
|
-
name: 'url',
|
|
823
|
-
message: 'Enter your webhook URL:',
|
|
824
|
-
validate: (input) => {
|
|
825
|
-
try {
|
|
826
|
-
new URL(input);
|
|
827
|
-
return true;
|
|
828
|
-
}
|
|
829
|
-
catch {
|
|
830
|
-
return 'Please enter a valid URL';
|
|
831
|
-
}
|
|
832
|
-
},
|
|
833
|
-
},
|
|
834
|
-
]);
|
|
835
|
-
if (!urlAnswer)
|
|
836
|
-
return;
|
|
837
|
-
webhookUrl = urlAnswer.url;
|
|
838
|
-
}
|
|
839
|
-
console.log(`\n✓ ${selectedTriggers.length} trigger(s) selected`);
|
|
840
|
-
if (isCustomWebhook) {
|
|
841
|
-
console.log(` → Events will be sent to: ${webhookUrl}`);
|
|
842
|
-
}
|
|
843
|
-
else {
|
|
844
|
-
console.log(` → Events will wake up your agent`);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
else {
|
|
848
|
-
console.log(`\n⏭️ No triggers selected`);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
else {
|
|
852
|
-
console.log(`\n⏭️ Skipping triggers — your agent will use manual invocation only`);
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
catch (error) {
|
|
858
|
-
// Non-fatal: continue without triggers if we can't fetch events
|
|
859
|
-
writeInfo(`Note: Could not fetch available triggers (${error.message})`);
|
|
860
|
-
}
|
|
861
|
-
// Step 5: Get authorization URL from Lua API
|
|
862
|
-
writeProgress('🔄 Preparing authorization...');
|
|
863
|
-
const state = Buffer.from(JSON.stringify({
|
|
864
|
-
agentId: context.agentId,
|
|
865
|
-
integration: selectedIntegration.value,
|
|
866
|
-
authMethod,
|
|
867
|
-
timestamp: Date.now(),
|
|
868
|
-
})).toString('base64');
|
|
869
|
-
// Encode both agentId and userId in externalXref for the connection
|
|
870
|
-
const externalXref = JSON.stringify({
|
|
871
|
-
agentId: context.agentId,
|
|
872
|
-
userId: context.userId,
|
|
873
|
-
});
|
|
874
|
-
const authUrlResult = await context.unifiedToApi.getAuthUrl(selectedIntegration.value, {
|
|
875
|
-
successRedirect: CALLBACK_URL,
|
|
876
|
-
failureRedirect: CALLBACK_URL,
|
|
877
|
-
scopes: authMethod === 'oauth' ? selectedScopes : undefined,
|
|
878
|
-
state,
|
|
879
|
-
externalXref, // Contains both agentId and userId as JSON
|
|
880
|
-
});
|
|
881
|
-
if (!authUrlResult.success || !authUrlResult.data) {
|
|
882
|
-
writeError(`❌ Failed to get authorization URL: ${authUrlResult.error?.message || 'Unknown error'}`);
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
885
|
-
// Auth URL is already resolved by the API (redirect wrappers followed server-side)
|
|
886
|
-
const authUrl = authUrlResult.data.authUrl;
|
|
887
|
-
// Step 4: Start callback server and open browser
|
|
888
|
-
console.log('\n' + '─'.repeat(60));
|
|
889
|
-
console.log('🌐 Starting OAuth authorization flow...');
|
|
890
|
-
console.log('─'.repeat(60));
|
|
891
|
-
console.log(`\nIntegration: ${selectedIntegration.name}`);
|
|
892
|
-
console.log(`\n📋 Authorization URL (copy if browser doesn't open):\n ${authUrl}\n`);
|
|
893
|
-
// Start the callback server
|
|
894
|
-
const callbackPromise = startCallbackServer(300000); // 5 minute timeout
|
|
895
|
-
// Auto-open browser
|
|
896
|
-
try {
|
|
897
|
-
await open(authUrl);
|
|
898
|
-
writeInfo('🌐 Browser opened - please complete the authorization');
|
|
899
|
-
}
|
|
900
|
-
catch (error) {
|
|
901
|
-
writeInfo('💡 Could not open browser automatically. Please open the URL above manually.');
|
|
902
|
-
}
|
|
903
|
-
console.log('\n⏳ Waiting for authorization (5 minute timeout)...');
|
|
904
|
-
console.log('💡 Complete the authorization in your browser.\n');
|
|
905
|
-
// Wait for callback
|
|
906
|
-
const result = await callbackPromise;
|
|
907
|
-
if (result.success && result.connectionId) {
|
|
908
|
-
writeSuccess('\n✅ Authorization successful!');
|
|
909
|
-
// Finalize the connection (sets up MCP server internally and creates webhooks)
|
|
910
|
-
await finalizeConnection(context, selectedIntegration, result.connectionId, selectedScopes, hideSensitive, {
|
|
911
|
-
triggers: selectedTriggers,
|
|
912
|
-
webhookUrl,
|
|
913
|
-
isCustomWebhook,
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
else {
|
|
917
|
-
writeError(`\n❌ Authorization failed: ${result.error || 'Unknown error'}`);
|
|
918
|
-
if (result.logId) {
|
|
919
|
-
console.log(` Log ID: ${result.logId}`);
|
|
920
|
-
}
|
|
921
|
-
// Report auth failure for observability (fire and forget)
|
|
922
|
-
context.unifiedToApi
|
|
923
|
-
.reportAuthFailure({
|
|
924
|
-
integrationType: selectedIntegration.value,
|
|
925
|
-
error: result.error || 'Unknown OAuth failure',
|
|
926
|
-
logId: result.logId,
|
|
927
|
-
agentId: context.agentId,
|
|
928
|
-
source: 'cli',
|
|
929
|
-
})
|
|
930
|
-
.catch(() => { });
|
|
931
|
-
console.log("💡 Please try again with 'lua integrations connect'\n");
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
/**
|
|
935
|
-
* Finalizes a new connection by calling the API to atomically set up MCP server and webhooks
|
|
936
|
-
* The API handles: MCP URL construction, upsert, activation, and webhook creation
|
|
937
|
-
*/
|
|
938
|
-
async function finalizeConnection(context, integration, connectionId, scopes, hideSensitive = false, webhookConfig = { triggers: [], webhookUrl: '', isCustomWebhook: false }) {
|
|
939
|
-
writeProgress(`🔄 Setting up ${integration.name} connection...`);
|
|
940
|
-
// Build trigger params for the API (include per-trigger hookUrl/interval if set)
|
|
941
|
-
const triggers = webhookConfig.triggers.map((t) => ({
|
|
942
|
-
objectType: t.objectType,
|
|
943
|
-
event: t.event,
|
|
944
|
-
hookUrl: t.hookUrl || (webhookConfig.isCustomWebhook ? webhookConfig.webhookUrl : undefined),
|
|
945
|
-
interval: t.interval,
|
|
946
|
-
}));
|
|
947
|
-
// Single API call replaces: MCP URL build + upsert + activate + N webhook creates
|
|
948
|
-
const result = await context.unifiedToApi.finalizeConnection(context.agentId, {
|
|
949
|
-
connectionId,
|
|
950
|
-
integrationType: integration.value,
|
|
951
|
-
scopes: scopes.length > 0 ? scopes : undefined,
|
|
952
|
-
hideSensitive,
|
|
953
|
-
triggers: triggers.length > 0 ? triggers : undefined,
|
|
954
|
-
});
|
|
955
|
-
if (!result.success || !result.data) {
|
|
956
|
-
writeError(`❌ Failed to finalize connection: ${result.error?.message || 'Unknown error'}`);
|
|
957
|
-
return;
|
|
958
|
-
}
|
|
959
|
-
const { mcpServer, webhooks, failedWebhooks } = result.data;
|
|
960
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
961
|
-
// Display Results
|
|
962
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
963
|
-
console.log('\n' + '─'.repeat(60));
|
|
964
|
-
console.log('🎉 Connection Established!');
|
|
965
|
-
console.log('─'.repeat(60));
|
|
966
|
-
console.log(`\n Integration: ${integration.name}`);
|
|
967
|
-
console.log(` Connection ID: ${connectionId}`);
|
|
968
|
-
// MCP Server status
|
|
969
|
-
console.log(`\n 📦 MCP Server (Tools):`);
|
|
970
|
-
console.log(` Status: ${mcpServer.active ? '🟢 Active' : '🟡 Pending activation'}`);
|
|
971
|
-
console.log(` Name: ${mcpServer.name}`);
|
|
972
|
-
console.log(` Hide Sensitive: ${hideSensitive ? '✅ Yes' : '❌ No'}`);
|
|
973
|
-
// Show requested scopes with friendly labels
|
|
974
|
-
if (scopes.length > 0) {
|
|
975
|
-
console.log(`\n 🔑 Permissions (${scopes.length}):`);
|
|
976
|
-
scopes.forEach((scopeName) => {
|
|
977
|
-
const scopeInfo = integration.oauthScopes?.find((s) => s.unifiedScope === scopeName);
|
|
978
|
-
if (scopeInfo?.friendlyLabel) {
|
|
979
|
-
console.log(` • ${scopeInfo.friendlyLabel}`);
|
|
980
|
-
}
|
|
981
|
-
else {
|
|
982
|
-
console.log(` • ${scopeName}`);
|
|
983
|
-
}
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
else {
|
|
987
|
-
console.log(`\n 🔑 Permissions: Default`);
|
|
988
|
-
}
|
|
989
|
-
// Webhook/Triggers status
|
|
990
|
-
if (triggers.length > 0) {
|
|
991
|
-
console.log(`\n ⚡ Triggers (${webhooks.length}/${triggers.length}):`);
|
|
992
|
-
if (webhookConfig.isCustomWebhook) {
|
|
993
|
-
console.log(` Mode: Custom webhook`);
|
|
994
|
-
}
|
|
995
|
-
else {
|
|
996
|
-
console.log(` Mode: Agent wake-up`);
|
|
997
|
-
}
|
|
998
|
-
webhooks.forEach((wh) => {
|
|
999
|
-
const trigger = webhookConfig.triggers.find((t) => t.objectType === wh.objectType && t.event === wh.event);
|
|
1000
|
-
const desc = trigger?.friendlyDescription || `${wh.objectType}.${wh.event}`;
|
|
1001
|
-
console.log(` ✓ ${desc}`);
|
|
1002
|
-
});
|
|
1003
|
-
if (failedWebhooks && failedWebhooks.length > 0) {
|
|
1004
|
-
failedWebhooks.forEach((t) => console.log(` ✗ ${t.objectType}.${t.event}: ${t.error}`));
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
else {
|
|
1008
|
-
console.log(`\n ⚡ Triggers: none (add later with: lua triggers create --connection ${connectionId})`);
|
|
1009
|
-
}
|
|
1010
|
-
// Summary message
|
|
1011
|
-
console.log('\n' + '─'.repeat(60));
|
|
1012
|
-
const capabilities = [];
|
|
1013
|
-
if (mcpServer.active) {
|
|
1014
|
-
capabilities.push('tools via MCP');
|
|
1015
|
-
}
|
|
1016
|
-
if (webhooks.length > 0) {
|
|
1017
|
-
capabilities.push(webhookConfig.isCustomWebhook ? 'webhooks to custom URL' : 'event-driven triggers');
|
|
1018
|
-
}
|
|
1019
|
-
if (capabilities.length > 0) {
|
|
1020
|
-
console.log(`✅ ${integration.name} connected! Your agent now has: ${capabilities.join(', ')}`);
|
|
1021
|
-
}
|
|
1022
|
-
else if (!mcpServer.active) {
|
|
1023
|
-
console.log(`⚠️ Connection created but MCP server pending activation.`);
|
|
1024
|
-
console.log(` Run: lua mcp activate --server-name ${mcpServer.name}`);
|
|
1025
|
-
}
|
|
1026
|
-
else {
|
|
1027
|
-
console.log(`⚠️ Connection created but setup incomplete. Check errors above.`);
|
|
1028
|
-
}
|
|
1029
|
-
console.log();
|
|
1030
|
-
trackEvent('cli_integration_connected', {
|
|
1031
|
-
integration_type: integration.value,
|
|
1032
|
-
integration_name: integration.name,
|
|
1033
|
-
mcp_server_active: mcpServer.active,
|
|
1034
|
-
webhooks_count: webhooks.length,
|
|
1035
|
-
triggers_skipped_at_connect: webhooks.length === 0,
|
|
1036
|
-
});
|
|
1037
|
-
}
|
|
1038
|
-
async function listConnections(context) {
|
|
1039
|
-
writeProgress('🔄 Loading connections...');
|
|
1040
|
-
try {
|
|
1041
|
-
// API now returns connections enriched with MCP server info
|
|
1042
|
-
const connectionsResult = await context.unifiedToApi.getConnections(context.agentId);
|
|
1043
|
-
const connections = connectionsResult.success ? connectionsResult.data || [] : [];
|
|
1044
|
-
console.log('\n' + '='.repeat(60));
|
|
1045
|
-
console.log('🔗 Connected Integrations');
|
|
1046
|
-
console.log('='.repeat(60) + '\n');
|
|
1047
|
-
if (connections.length === 0) {
|
|
1048
|
-
console.log('ℹ️ No integrations connected yet.');
|
|
1049
|
-
console.log("💡 Run 'lua integrations connect' to connect an integration.\n");
|
|
1050
|
-
return;
|
|
1051
|
-
}
|
|
1052
|
-
for (const connection of connections) {
|
|
1053
|
-
const toolsAvailable = connection.mcpServer?.active === true;
|
|
1054
|
-
// Status based on connection health + tool availability
|
|
1055
|
-
let statusIcon = '⚪';
|
|
1056
|
-
let statusText = 'Inactive';
|
|
1057
|
-
if (connection.status === 'unhealthy') {
|
|
1058
|
-
statusIcon = '🔴';
|
|
1059
|
-
statusText = 'Unhealthy - run "lua integrations update" to re-authorize';
|
|
1060
|
-
}
|
|
1061
|
-
else if (connection.status === 'paused') {
|
|
1062
|
-
statusIcon = '⏸️';
|
|
1063
|
-
statusText = 'Paused';
|
|
1064
|
-
}
|
|
1065
|
-
else if (connection.status === 'active' && toolsAvailable) {
|
|
1066
|
-
statusIcon = '🟢';
|
|
1067
|
-
statusText = 'Active';
|
|
1068
|
-
}
|
|
1069
|
-
else if (connection.status === 'active') {
|
|
1070
|
-
statusIcon = '🟡';
|
|
1071
|
-
statusText = 'Connected (MCP pending)';
|
|
1072
|
-
}
|
|
1073
|
-
console.log(`${statusIcon} ${connection.integrationName || connection.integrationType}`);
|
|
1074
|
-
console.log(` Connection: ${connection.id}`);
|
|
1075
|
-
console.log(` Status: ${statusText}`);
|
|
1076
|
-
if (connection.mcpServer) {
|
|
1077
|
-
console.log(` MCP Server: ${connection.mcpServer.name} (${connection.mcpServer.active ? 'active' : 'inactive'})`);
|
|
1078
|
-
}
|
|
1079
|
-
console.log(` Connected: ${new Date(connection.createdAt).toLocaleDateString()}`);
|
|
1080
|
-
console.log();
|
|
1081
|
-
}
|
|
1082
|
-
console.log('='.repeat(60));
|
|
1083
|
-
console.log(`Total: ${connections.length} integration(s)\n`);
|
|
1084
|
-
}
|
|
1085
|
-
catch (error) {
|
|
1086
|
-
writeError(`❌ Error loading connections: ${error.message}`);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
async function disconnectIntegration(context, connectionId) {
|
|
1090
|
-
writeProgress(`🔄 Disconnecting... (please wait, do not close this window)`);
|
|
1091
|
-
try {
|
|
1092
|
-
// Delete the connection (API handles MCP server + webhook cleanup)
|
|
1093
|
-
const deleteResult = await context.unifiedToApi.deleteConnection(connectionId, context.agentId);
|
|
1094
|
-
if (deleteResult.success) {
|
|
1095
|
-
writeSuccess(`✅ Integration disconnected successfully!`);
|
|
1096
|
-
if (deleteResult.data?.deletedWebhooksCount && deleteResult.data.deletedWebhooksCount > 0) {
|
|
1097
|
-
console.log(` ✓ Deleted ${deleteResult.data.deletedWebhooksCount} trigger(s)`);
|
|
1098
|
-
}
|
|
1099
|
-
console.log();
|
|
1100
|
-
trackEvent('cli_integration_disconnected', {
|
|
1101
|
-
webhooks_deleted: deleteResult.data?.deletedWebhooksCount || 0,
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
else {
|
|
1105
|
-
writeError(`❌ Failed to disconnect: ${deleteResult.error?.message}`);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
catch (error) {
|
|
1109
|
-
writeError(`❌ Error disconnecting: ${error.message}`);
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
async function disconnectIntegrationInteractive(context) {
|
|
1113
|
-
try {
|
|
1114
|
-
const connectionsResult = await context.unifiedToApi.getConnections(context.agentId);
|
|
1115
|
-
if (!connectionsResult.success) {
|
|
1116
|
-
writeError(`❌ Failed to load connections: ${connectionsResult.error?.message}`);
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
const connections = connectionsResult.data || [];
|
|
1120
|
-
if (connections.length === 0) {
|
|
1121
|
-
console.log('\nℹ️ No integrations to disconnect.\n');
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
const connectionAnswer = await safePrompt([
|
|
1125
|
-
{
|
|
1126
|
-
type: 'list',
|
|
1127
|
-
name: 'connection',
|
|
1128
|
-
message: 'Select an integration to disconnect:',
|
|
1129
|
-
choices: connections.map((c) => ({
|
|
1130
|
-
name: `${c.integrationName || c.integrationType} (${c.id.substring(0, 8)}...)`,
|
|
1131
|
-
value: c.id,
|
|
1132
|
-
})),
|
|
1133
|
-
},
|
|
1134
|
-
]);
|
|
1135
|
-
if (!connectionAnswer?.connection)
|
|
1136
|
-
return;
|
|
1137
|
-
const selectedConnection = connections.find((c) => c.id === connectionAnswer.connection);
|
|
1138
|
-
const confirmAnswer = await safePrompt([
|
|
1139
|
-
{
|
|
1140
|
-
type: 'confirm',
|
|
1141
|
-
name: 'confirm',
|
|
1142
|
-
message: `Disconnect ${selectedConnection?.integrationName || selectedConnection?.integrationType}? Your agent will lose access to this integration.`,
|
|
1143
|
-
default: false,
|
|
1144
|
-
},
|
|
1145
|
-
]);
|
|
1146
|
-
if (!confirmAnswer?.confirm) {
|
|
1147
|
-
console.log('\n❌ Cancelled.\n');
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
await disconnectIntegration(context, connectionAnswer.connection);
|
|
1151
|
-
}
|
|
1152
|
-
catch (error) {
|
|
1153
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1157
|
-
// Update Connection Flow
|
|
1158
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1159
|
-
async function updateConnectionFlow(context, options = {}) {
|
|
1160
|
-
// Step 1: Fetch existing connections and available integrations
|
|
1161
|
-
writeProgress('🔄 Loading connections...');
|
|
1162
|
-
let connections = [];
|
|
1163
|
-
let integrations = [];
|
|
1164
|
-
try {
|
|
1165
|
-
const [connectionsResult, integrationsResult] = await Promise.all([
|
|
1166
|
-
context.unifiedToApi.getConnections(context.agentId),
|
|
1167
|
-
fetchAvailableIntegrations(context.unifiedToApi),
|
|
1168
|
-
]);
|
|
1169
|
-
connections = connectionsResult.success ? connectionsResult.data || [] : [];
|
|
1170
|
-
integrations = integrationsResult;
|
|
1171
|
-
}
|
|
1172
|
-
catch (error) {
|
|
1173
|
-
writeError(`❌ Failed to load connections: ${error.message}`);
|
|
1174
|
-
return;
|
|
1175
|
-
}
|
|
1176
|
-
if (connections.length === 0) {
|
|
1177
|
-
writeInfo('No integrations to update.');
|
|
1178
|
-
console.log("💡 Run 'lua integrations connect' to connect an integration.\n");
|
|
1179
|
-
return;
|
|
1180
|
-
}
|
|
1181
|
-
// Step 2: Select connection to update
|
|
1182
|
-
let selectedConnection;
|
|
1183
|
-
let selectedIntegration;
|
|
1184
|
-
if (options.integration) {
|
|
1185
|
-
// Find connection by integration type
|
|
1186
|
-
selectedConnection = connections.find((c) => c.integrationType === options.integration);
|
|
1187
|
-
if (!selectedConnection) {
|
|
1188
|
-
console.error(`❌ No connection found for integration "${options.integration}".`);
|
|
1189
|
-
console.log('\nConnected integrations:');
|
|
1190
|
-
connections.forEach((c) => console.log(` - ${c.integrationType} (${c.integrationName || c.integrationType})`));
|
|
1191
|
-
throw new Error('No connection found for integration');
|
|
1192
|
-
}
|
|
1193
|
-
selectedIntegration = integrations.find((i) => i.value === options.integration);
|
|
1194
|
-
}
|
|
1195
|
-
else {
|
|
1196
|
-
// Interactive selection
|
|
1197
|
-
const connectionAnswer = await safePrompt([
|
|
1198
|
-
{
|
|
1199
|
-
type: 'list',
|
|
1200
|
-
name: 'connection',
|
|
1201
|
-
message: 'Select a connection to update:',
|
|
1202
|
-
choices: connections.map((c) => ({
|
|
1203
|
-
name: `${c.integrationName || c.integrationType} (${c.id.substring(0, 8)}...)`,
|
|
1204
|
-
value: c,
|
|
1205
|
-
})),
|
|
1206
|
-
},
|
|
1207
|
-
]);
|
|
1208
|
-
if (!connectionAnswer?.connection)
|
|
1209
|
-
return;
|
|
1210
|
-
selectedConnection = connectionAnswer.connection;
|
|
1211
|
-
selectedIntegration = integrations.find((i) => i.value === selectedConnection.integrationType);
|
|
1212
|
-
}
|
|
1213
|
-
if (!selectedIntegration) {
|
|
1214
|
-
writeError(`❌ Integration details not found for ${selectedConnection.integrationType}`);
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
|
-
console.log(`\n📌 Updating: ${selectedIntegration.name}`);
|
|
1218
|
-
console.log(` Current Connection ID: ${selectedConnection.id}`);
|
|
1219
|
-
// Step 3: Check if OAuth with configurable scopes
|
|
1220
|
-
const canUseOAuth = selectedIntegration.oauthConfigured && ['oauth', 'both'].includes(selectedIntegration.authSupport);
|
|
1221
|
-
if (!canUseOAuth || !selectedIntegration.oauthScopes?.length) {
|
|
1222
|
-
writeInfo('This integration does not have configurable scopes.');
|
|
1223
|
-
console.log('💡 To reconnect with different credentials, disconnect and connect again.\n');
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
// Step 4: Select new scopes
|
|
1227
|
-
const availableScopes = selectedIntegration.oauthScopes.map((s) => s.unifiedScope);
|
|
1228
|
-
let selectedScopes = [];
|
|
1229
|
-
if (options.scopes) {
|
|
1230
|
-
// Non-interactive: use provided scopes
|
|
1231
|
-
if (options.scopes.toLowerCase() === 'all') {
|
|
1232
|
-
selectedScopes = availableScopes;
|
|
1233
|
-
writeInfo(`Using all ${selectedScopes.length} available scope(s)`);
|
|
1234
|
-
}
|
|
1235
|
-
else {
|
|
1236
|
-
const requestedScopes = options.scopes.split(',').map((s) => s.trim());
|
|
1237
|
-
const invalidScopes = requestedScopes.filter((s) => !availableScopes.includes(s));
|
|
1238
|
-
if (invalidScopes.length > 0) {
|
|
1239
|
-
console.error(`❌ Invalid scopes: ${invalidScopes.join(', ')}`);
|
|
1240
|
-
console.log(`\nAvailable scopes for ${selectedIntegration.name}:`);
|
|
1241
|
-
availableScopes.forEach((s) => console.log(` - ${s}`));
|
|
1242
|
-
throw new Error('Invalid scopes: ${invalidScopes.join(');
|
|
1243
|
-
}
|
|
1244
|
-
selectedScopes = requestedScopes;
|
|
1245
|
-
writeInfo(`Using ${selectedScopes.length} specified scope(s)`);
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
else {
|
|
1249
|
-
// Interactive: prompt for scope selection
|
|
1250
|
-
const scopeAnswer = await safePrompt([
|
|
1251
|
-
{
|
|
1252
|
-
type: 'checkbox',
|
|
1253
|
-
name: 'scopes',
|
|
1254
|
-
message: 'Select new OAuth scopes (Space to toggle, Enter to confirm, leave empty for all):',
|
|
1255
|
-
pageSize: 15,
|
|
1256
|
-
loop: false,
|
|
1257
|
-
choices: selectedIntegration.oauthScopes.map((s) => {
|
|
1258
|
-
// Use friendly label if available, otherwise fall back to technical name
|
|
1259
|
-
const displayName = s.friendlyLabel || s.unifiedScope;
|
|
1260
|
-
const description = s.friendlyDescription
|
|
1261
|
-
? ` (${s.friendlyDescription})`
|
|
1262
|
-
: ` → [${s.originalScopes.join(', ')}]`;
|
|
1263
|
-
return {
|
|
1264
|
-
name: `${displayName}${description}`,
|
|
1265
|
-
value: s.unifiedScope,
|
|
1266
|
-
checked: false,
|
|
1267
|
-
};
|
|
1268
|
-
}),
|
|
1269
|
-
},
|
|
1270
|
-
]);
|
|
1271
|
-
if (!scopeAnswer)
|
|
1272
|
-
return;
|
|
1273
|
-
selectedScopes = scopeAnswer.scopes.length > 0 ? scopeAnswer.scopes : availableScopes;
|
|
1274
|
-
console.log(`\n✓ Will request ${selectedScopes.length} scope(s)`);
|
|
1275
|
-
}
|
|
1276
|
-
// Determine hide_sensitive setting
|
|
1277
|
-
let hideSensitive = false; // Default to false (expose all fields for better agent comprehension)
|
|
1278
|
-
if (options.hideSensitive !== undefined) {
|
|
1279
|
-
hideSensitive = options.hideSensitive;
|
|
1280
|
-
}
|
|
1281
|
-
else {
|
|
1282
|
-
// Interactive: ask user
|
|
1283
|
-
const sensitiveAnswer = await safePrompt([
|
|
1284
|
-
{
|
|
1285
|
-
type: 'confirm',
|
|
1286
|
-
name: 'hide',
|
|
1287
|
-
message: 'Hide sensitive data (PII) from MCP tools?',
|
|
1288
|
-
default: false,
|
|
1289
|
-
},
|
|
1290
|
-
]);
|
|
1291
|
-
if (sensitiveAnswer) {
|
|
1292
|
-
hideSensitive = sensitiveAnswer.hide;
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
// Step 5: Fetch existing triggers before deletion (so we can re-create them)
|
|
1296
|
-
let existingTriggers = [];
|
|
1297
|
-
try {
|
|
1298
|
-
const webhooksResult = await context.unifiedToApi.getWebhookSubscriptions(context.agentId);
|
|
1299
|
-
if (webhooksResult.success && webhooksResult.data && webhooksResult.data.length > 0) {
|
|
1300
|
-
// Filter webhooks to only those belonging to this connection
|
|
1301
|
-
const connectionWebhooks = webhooksResult.data.filter((w) => w.connectionId === selectedConnection.id);
|
|
1302
|
-
existingTriggers = connectionWebhooks.map((w) => ({
|
|
1303
|
-
objectType: w.objectType,
|
|
1304
|
-
event: w.event,
|
|
1305
|
-
hookUrl: w.hookUrl,
|
|
1306
|
-
interval: w.interval,
|
|
1307
|
-
}));
|
|
1308
|
-
if (existingTriggers.length > 0) {
|
|
1309
|
-
writeInfo(`Found ${existingTriggers.length} existing trigger(s) - will restore after update`);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
catch (error) {
|
|
1314
|
-
// If we can't fetch existing triggers, continue without them
|
|
1315
|
-
}
|
|
1316
|
-
// Step 6: Confirm the update
|
|
1317
|
-
if (!options.integration) {
|
|
1318
|
-
const confirmAnswer = await safePrompt([
|
|
1319
|
-
{
|
|
1320
|
-
type: 'confirm',
|
|
1321
|
-
name: 'confirm',
|
|
1322
|
-
message: `Update ${selectedIntegration.name}? This will re-authorize with new scopes.`,
|
|
1323
|
-
default: true,
|
|
1324
|
-
},
|
|
1325
|
-
]);
|
|
1326
|
-
if (!confirmAnswer?.confirm) {
|
|
1327
|
-
console.log('\n❌ Cancelled.\n');
|
|
1328
|
-
return;
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
// Step 7: Delete the old connection (silently)
|
|
1332
|
-
writeProgress(`🔄 Updating ${selectedIntegration.name}...`);
|
|
1333
|
-
try {
|
|
1334
|
-
// Delete old connection (API handles MCP server + webhook cleanup)
|
|
1335
|
-
await context.unifiedToApi.deleteConnection(selectedConnection.id, context.agentId);
|
|
1336
|
-
}
|
|
1337
|
-
catch (error) {
|
|
1338
|
-
writeError(`❌ Failed to remove old connection: ${error.message}`);
|
|
1339
|
-
return;
|
|
1340
|
-
}
|
|
1341
|
-
// Step 8: Create new connection with new scopes
|
|
1342
|
-
const state = Buffer.from(JSON.stringify({
|
|
1343
|
-
agentId: context.agentId,
|
|
1344
|
-
integration: selectedIntegration.value,
|
|
1345
|
-
authMethod: 'oauth',
|
|
1346
|
-
timestamp: Date.now(),
|
|
1347
|
-
})).toString('base64');
|
|
1348
|
-
const externalXref = JSON.stringify({
|
|
1349
|
-
agentId: context.agentId,
|
|
1350
|
-
userId: context.userId,
|
|
1351
|
-
});
|
|
1352
|
-
const authUrlResult = await context.unifiedToApi.getAuthUrl(selectedIntegration.value, {
|
|
1353
|
-
successRedirect: CALLBACK_URL,
|
|
1354
|
-
failureRedirect: CALLBACK_URL,
|
|
1355
|
-
scopes: selectedScopes,
|
|
1356
|
-
state,
|
|
1357
|
-
externalXref,
|
|
1358
|
-
});
|
|
1359
|
-
if (!authUrlResult.success || !authUrlResult.data) {
|
|
1360
|
-
writeError(`❌ Failed to get authorization URL: ${authUrlResult.error?.message || 'Unknown error'}`);
|
|
1361
|
-
return;
|
|
1362
|
-
}
|
|
1363
|
-
// Auth URL is already resolved by the API (redirect wrappers followed server-side)
|
|
1364
|
-
const authUrl = authUrlResult.data.authUrl;
|
|
1365
|
-
// Step 9: Open browser and wait for callback
|
|
1366
|
-
console.log('\n' + '─'.repeat(60));
|
|
1367
|
-
console.log('🌐 Re-authorizing with new scopes...');
|
|
1368
|
-
console.log('─'.repeat(60));
|
|
1369
|
-
console.log(`\n📋 Authorization URL (copy if browser doesn't open):\n ${authUrl}\n`);
|
|
1370
|
-
const callbackPromise = startCallbackServer(300000);
|
|
1371
|
-
try {
|
|
1372
|
-
await open(authUrl);
|
|
1373
|
-
writeInfo('🌐 Browser opened - please complete the authorization');
|
|
1374
|
-
}
|
|
1375
|
-
catch (error) {
|
|
1376
|
-
writeInfo('💡 Could not open browser automatically. Please open the URL above manually.');
|
|
1377
|
-
}
|
|
1378
|
-
console.log('\n⏳ Waiting for authorization (5 minute timeout)...');
|
|
1379
|
-
console.log('💡 Complete the authorization in your browser.\n');
|
|
1380
|
-
const result = await callbackPromise;
|
|
1381
|
-
if (result.success && result.connectionId) {
|
|
1382
|
-
writeSuccess('\n✅ Authorization successful!');
|
|
1383
|
-
// Check if any triggers use custom webhooks
|
|
1384
|
-
const hasCustomWebhook = existingTriggers.some((t) => t.hookUrl !== AGENT_WEBHOOK_URL);
|
|
1385
|
-
// Convert existing triggers to TriggerWithSettings format, preserving per-trigger hookUrl and interval
|
|
1386
|
-
let triggersToRestore = [];
|
|
1387
|
-
if (existingTriggers.length > 0) {
|
|
1388
|
-
try {
|
|
1389
|
-
const eventsResult = await context.unifiedToApi.getAvailableWebhookEventsByType(selectedIntegration.value);
|
|
1390
|
-
if (eventsResult.success && eventsResult.data) {
|
|
1391
|
-
for (const trigger of existingTriggers) {
|
|
1392
|
-
const matchingEvent = eventsResult.data.find((e) => e.objectType === trigger.objectType && e.event === trigger.event);
|
|
1393
|
-
if (matchingEvent) {
|
|
1394
|
-
// Preserve per-trigger hookUrl and interval from original webhook
|
|
1395
|
-
triggersToRestore.push({
|
|
1396
|
-
...matchingEvent,
|
|
1397
|
-
hookUrl: trigger.hookUrl,
|
|
1398
|
-
interval: trigger.interval,
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
catch (error) {
|
|
1405
|
-
// If we can't match triggers, continue without them
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
await finalizeConnection(context, selectedIntegration, result.connectionId, selectedScopes, hideSensitive, {
|
|
1409
|
-
triggers: triggersToRestore,
|
|
1410
|
-
webhookUrl: AGENT_WEBHOOK_URL, // Default, but per-trigger hookUrl will override if set
|
|
1411
|
-
isCustomWebhook: hasCustomWebhook,
|
|
1412
|
-
});
|
|
1413
|
-
if (triggersToRestore.length > 0) {
|
|
1414
|
-
writeSuccess(`Restored ${triggersToRestore.length} trigger(s) from previous connection`);
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
else {
|
|
1418
|
-
writeError(`\n❌ Authorization failed: ${result.error || 'Unknown error'}`);
|
|
1419
|
-
if (result.logId) {
|
|
1420
|
-
console.log(` Log ID: ${result.logId}`);
|
|
1421
|
-
}
|
|
1422
|
-
// Report auth failure for observability (fire and forget)
|
|
1423
|
-
context.unifiedToApi
|
|
1424
|
-
.reportAuthFailure({
|
|
1425
|
-
integrationType: selectedIntegration.value,
|
|
1426
|
-
error: result.error || 'Unknown OAuth failure',
|
|
1427
|
-
logId: result.logId,
|
|
1428
|
-
agentId: context.agentId,
|
|
1429
|
-
source: 'cli',
|
|
1430
|
-
})
|
|
1431
|
-
.catch(() => { });
|
|
1432
|
-
console.log("💡 The old connection was removed. Please reconnect with 'lua integrations connect'\n");
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1436
|
-
// Webhook Subscription Flows
|
|
1437
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
1438
|
-
/**
|
|
1439
|
-
* Handle webhooks subcommand (non-interactive)
|
|
1440
|
-
*/
|
|
1441
|
-
async function webhooksSubcommand(context, cmdOptions) {
|
|
1442
|
-
const rawSubAction = cmdOptions?._?.[0] || '';
|
|
1443
|
-
const subAction = rawSubAction ? validateOrSuggest('triggers.action', rawSubAction) : '';
|
|
1444
|
-
const options = {
|
|
1445
|
-
connectionId: cmdOptions?.connection || cmdOptions?.connectionId,
|
|
1446
|
-
webhookId: cmdOptions?.webhookId,
|
|
1447
|
-
objectType: cmdOptions?.object,
|
|
1448
|
-
event: cmdOptions?.event,
|
|
1449
|
-
hookUrl: cmdOptions?.hookUrl,
|
|
1450
|
-
interval: cmdOptions?.interval ? parseInt(cmdOptions.interval, 10) : undefined,
|
|
1451
|
-
integration: cmdOptions?.integration,
|
|
1452
|
-
reason: cmdOptions?.reason,
|
|
1453
|
-
};
|
|
1454
|
-
const jsonOutput = cmdOptions?.json === true;
|
|
1455
|
-
switch (subAction) {
|
|
1456
|
-
case 'list':
|
|
1457
|
-
await webhooksListFlow(context, jsonOutput);
|
|
1458
|
-
break;
|
|
1459
|
-
case 'create':
|
|
1460
|
-
await webhooksCreateFlow(context, options);
|
|
1461
|
-
break;
|
|
1462
|
-
case 'delete':
|
|
1463
|
-
if (!options.webhookId) {
|
|
1464
|
-
console.error('❌ --webhook-id is required for delete');
|
|
1465
|
-
console.log("\n💡 Run 'lua integrations webhooks list' to see trigger IDs");
|
|
1466
|
-
throw new Error('--webhook-id is required for delete');
|
|
1467
|
-
}
|
|
1468
|
-
await webhooksDeleteFlow(context, options.webhookId);
|
|
1469
|
-
break;
|
|
1470
|
-
case 'pause':
|
|
1471
|
-
if (options.webhookId) {
|
|
1472
|
-
await webhooksPauseFlow(context, options.webhookId, options.reason);
|
|
1473
|
-
}
|
|
1474
|
-
else if (options.connectionId) {
|
|
1475
|
-
await connectionPauseFlow(context, options.connectionId);
|
|
1476
|
-
}
|
|
1477
|
-
else {
|
|
1478
|
-
console.error('❌ --webhook-id or --connection-id is required for pause');
|
|
1479
|
-
console.log("\n💡 Run 'lua integrations webhooks list' to see trigger IDs");
|
|
1480
|
-
throw new Error('--webhook-id or --connection-id is required for pause');
|
|
1481
|
-
}
|
|
1482
|
-
break;
|
|
1483
|
-
case 'resume':
|
|
1484
|
-
if (options.webhookId) {
|
|
1485
|
-
await webhooksResumeFlow(context, options.webhookId);
|
|
1486
|
-
}
|
|
1487
|
-
else if (options.connectionId) {
|
|
1488
|
-
await connectionResumeFlow(context, options.connectionId);
|
|
1489
|
-
}
|
|
1490
|
-
else {
|
|
1491
|
-
console.error('❌ --webhook-id or --connection-id is required for resume');
|
|
1492
|
-
console.log("\n💡 Run 'lua integrations webhooks list' to see trigger IDs");
|
|
1493
|
-
throw new Error('--webhook-id or --connection-id is required for resume');
|
|
1494
|
-
}
|
|
1495
|
-
break;
|
|
1496
|
-
case 'events':
|
|
1497
|
-
// New: List available webhook events for a connection or integration type
|
|
1498
|
-
await webhooksEventsFlow(context, options, jsonOutput);
|
|
1499
|
-
break;
|
|
1500
|
-
case '':
|
|
1501
|
-
// No sub-action: open interactive trigger management menu
|
|
1502
|
-
// (covers `lua triggers` and `lua integrations webhooks` run bare)
|
|
1503
|
-
await webhooksInteractiveMenu(context);
|
|
1504
|
-
break;
|
|
1505
|
-
default:
|
|
1506
|
-
console.error(`❌ Invalid webhooks action: "${subAction}"`);
|
|
1507
|
-
console.log('\nUsage:');
|
|
1508
|
-
console.log(' lua integrations webhooks list List triggers');
|
|
1509
|
-
console.log(' lua integrations webhooks events --connection <id> List available events for a connection');
|
|
1510
|
-
console.log(' lua integrations webhooks events --integration <type> List available events for an integration');
|
|
1511
|
-
console.log(' lua integrations webhooks create Create trigger (interactive)');
|
|
1512
|
-
console.log(' lua integrations webhooks create --connection <id> --object <type> --event <event> --hook-url <url>');
|
|
1513
|
-
console.log(' lua integrations webhooks delete --webhook-id <id> Delete trigger');
|
|
1514
|
-
console.log(' lua integrations webhooks pause --webhook-id <id> Pause a trigger');
|
|
1515
|
-
console.log(' lua integrations webhooks pause --connection-id <id> Pause all triggers for a connection');
|
|
1516
|
-
console.log(' lua integrations webhooks resume --webhook-id <id> Resume a trigger');
|
|
1517
|
-
console.log(' lua integrations webhooks resume --connection-id <id> Resume all triggers for a connection');
|
|
1518
|
-
throw new Error(`Invalid webhooks action: ${subAction}`);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Show available webhook events for a connection or integration type
|
|
1523
|
-
* Used for non-interactive discovery
|
|
1524
|
-
*/
|
|
1525
|
-
async function webhooksEventsFlow(context, options, jsonOutput = false) {
|
|
1526
|
-
try {
|
|
1527
|
-
let webhookEvents = [];
|
|
1528
|
-
let sourceName = '';
|
|
1529
|
-
if (options.connectionId) {
|
|
1530
|
-
// Get events by connection ID
|
|
1531
|
-
const eventsResult = await context.unifiedToApi.getAvailableWebhookEvents(context.agentId, options.connectionId);
|
|
1532
|
-
if (eventsResult.success && eventsResult.data) {
|
|
1533
|
-
webhookEvents = eventsResult.data;
|
|
1534
|
-
}
|
|
1535
|
-
sourceName = `connection ${options.connectionId}`;
|
|
1536
|
-
}
|
|
1537
|
-
else if (options.integration) {
|
|
1538
|
-
// Get events by integration type
|
|
1539
|
-
const eventsResult = await context.unifiedToApi.getAvailableWebhookEventsByType(options.integration);
|
|
1540
|
-
if (eventsResult.success && eventsResult.data) {
|
|
1541
|
-
webhookEvents = eventsResult.data;
|
|
1542
|
-
}
|
|
1543
|
-
sourceName = `integration ${options.integration}`;
|
|
1544
|
-
}
|
|
1545
|
-
else {
|
|
1546
|
-
if (jsonOutput) {
|
|
1547
|
-
console.log(JSON.stringify({ error: 'Either --connection or --integration is required' }));
|
|
1548
|
-
}
|
|
1549
|
-
else {
|
|
1550
|
-
console.error('❌ Either --connection <id> or --integration <type> is required');
|
|
1551
|
-
console.log('\nUsage:');
|
|
1552
|
-
console.log(' lua integrations webhooks events --connection <id>');
|
|
1553
|
-
console.log(' lua integrations webhooks events --integration <type>');
|
|
1554
|
-
}
|
|
1555
|
-
throw new Error('Operation failed');
|
|
1556
|
-
}
|
|
1557
|
-
if (jsonOutput) {
|
|
1558
|
-
const output = {
|
|
1559
|
-
source: sourceName,
|
|
1560
|
-
events: webhookEvents.map((e) => ({
|
|
1561
|
-
trigger: `${e.objectType}.${e.event}`,
|
|
1562
|
-
objectType: e.objectType,
|
|
1563
|
-
event: e.event,
|
|
1564
|
-
webhookType: e.webhookType,
|
|
1565
|
-
friendlyLabel: e.friendlyLabel,
|
|
1566
|
-
friendlyDescription: e.friendlyDescription,
|
|
1567
|
-
availableFilters: e.availableFilters,
|
|
1568
|
-
})),
|
|
1569
|
-
defaults: {
|
|
1570
|
-
agentWebhookUrl: AGENT_WEBHOOK_URL,
|
|
1571
|
-
defaultVirtualInterval: DEFAULT_VIRTUAL_WEBHOOK_INTERVAL,
|
|
1572
|
-
},
|
|
1573
|
-
};
|
|
1574
|
-
console.log(JSON.stringify(output, null, 2));
|
|
1575
|
-
}
|
|
1576
|
-
else {
|
|
1577
|
-
console.log('\n' + '='.repeat(60));
|
|
1578
|
-
console.log(`📡 Available Trigger Events for ${sourceName}`);
|
|
1579
|
-
console.log('='.repeat(60) + '\n');
|
|
1580
|
-
if (webhookEvents.length === 0) {
|
|
1581
|
-
console.log('ℹ️ No trigger events available for this integration.\n');
|
|
1582
|
-
}
|
|
1583
|
-
else {
|
|
1584
|
-
webhookEvents.forEach((e) => {
|
|
1585
|
-
console.log(` ${e.objectType}.${e.event} [${e.webhookType}]`);
|
|
1586
|
-
console.log(` ${e.friendlyDescription}`);
|
|
1587
|
-
if (e.availableFilters.length > 0) {
|
|
1588
|
-
console.log(` Filters: ${e.availableFilters.join(', ')}`);
|
|
1589
|
-
}
|
|
1590
|
-
console.log();
|
|
1591
|
-
});
|
|
1592
|
-
console.log('─'.repeat(60));
|
|
1593
|
-
console.log(`Total: ${webhookEvents.length} event(s) available`);
|
|
1594
|
-
console.log('\n💡 Use with --triggers flag:');
|
|
1595
|
-
const exampleTriggers = webhookEvents
|
|
1596
|
-
.slice(0, 2)
|
|
1597
|
-
.map((e) => `${e.objectType}.${e.event}`)
|
|
1598
|
-
.join(',');
|
|
1599
|
-
console.log(` lua integrations connect --integration <type> --triggers ${exampleTriggers}\n`);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
catch (error) {
|
|
1604
|
-
if (jsonOutput) {
|
|
1605
|
-
console.log(JSON.stringify({ error: error.message }));
|
|
1606
|
-
}
|
|
1607
|
-
else {
|
|
1608
|
-
writeError(`❌ Failed to get trigger events: ${error.message}`);
|
|
1609
|
-
}
|
|
1610
|
-
throw new Error('Operation failed');
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
/**
|
|
1614
|
-
* Interactive webhooks menu
|
|
1615
|
-
*/
|
|
1616
|
-
async function webhooksInteractiveMenu(context) {
|
|
1617
|
-
console.log('\n' + '─'.repeat(60));
|
|
1618
|
-
console.log('🔔 Triggers');
|
|
1619
|
-
console.log('─'.repeat(60) + '\n');
|
|
1620
|
-
const actionAnswer = await safePrompt([
|
|
1621
|
-
{
|
|
1622
|
-
type: 'list',
|
|
1623
|
-
name: 'action',
|
|
1624
|
-
message: 'What would you like to do?',
|
|
1625
|
-
choices: [
|
|
1626
|
-
{ name: '📋 List triggers', value: 'list' },
|
|
1627
|
-
{ name: '➕ Create new trigger', value: 'create' },
|
|
1628
|
-
{ name: '⏸️ Pause a trigger', value: 'pause' },
|
|
1629
|
-
{ name: '▶️ Resume a trigger', value: 'resume' },
|
|
1630
|
-
{ name: '⏸️ Pause all triggers for a connection', value: 'pauseConn' },
|
|
1631
|
-
{ name: '▶️ Resume all triggers for a connection', value: 'resumeConn' },
|
|
1632
|
-
{ name: '🗑️ Delete a trigger', value: 'delete' },
|
|
1633
|
-
{ name: '← Back', value: 'back' },
|
|
1634
|
-
],
|
|
1635
|
-
},
|
|
1636
|
-
]);
|
|
1637
|
-
if (!actionAnswer || actionAnswer.action === 'back')
|
|
1638
|
-
return;
|
|
1639
|
-
switch (actionAnswer.action) {
|
|
1640
|
-
case 'list':
|
|
1641
|
-
await webhooksListFlow(context);
|
|
1642
|
-
break;
|
|
1643
|
-
case 'create':
|
|
1644
|
-
await webhooksCreateFlow(context, {});
|
|
1645
|
-
break;
|
|
1646
|
-
case 'pause':
|
|
1647
|
-
await webhooksPauseInteractive(context);
|
|
1648
|
-
break;
|
|
1649
|
-
case 'resume':
|
|
1650
|
-
await webhooksResumeInteractive(context);
|
|
1651
|
-
break;
|
|
1652
|
-
case 'pauseConn':
|
|
1653
|
-
await connectionPauseInteractive(context);
|
|
1654
|
-
break;
|
|
1655
|
-
case 'resumeConn':
|
|
1656
|
-
await connectionResumeInteractive(context);
|
|
1657
|
-
break;
|
|
1658
|
-
case 'delete':
|
|
1659
|
-
await webhooksDeleteInteractive(context);
|
|
1660
|
-
break;
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
/**
|
|
1664
|
-
* List all webhook subscriptions
|
|
1665
|
-
*/
|
|
1666
|
-
async function webhooksListFlow(context, jsonOutput = false) {
|
|
1667
|
-
writeProgress('🔄 Loading triggers...');
|
|
1668
|
-
try {
|
|
1669
|
-
const result = await context.unifiedToApi.getWebhookSubscriptions(context.agentId);
|
|
1670
|
-
if (!result.success) {
|
|
1671
|
-
if (jsonOutput) {
|
|
1672
|
-
console.log(JSON.stringify({ error: result.error?.message || 'Failed to load triggers' }));
|
|
1673
|
-
}
|
|
1674
|
-
else {
|
|
1675
|
-
writeError(`❌ Failed to load triggers: ${result.error?.message}`);
|
|
1676
|
-
}
|
|
1677
|
-
return;
|
|
1678
|
-
}
|
|
1679
|
-
const webhooks = result.data || [];
|
|
1680
|
-
if (jsonOutput) {
|
|
1681
|
-
// Output as JSON for scripting
|
|
1682
|
-
console.log(JSON.stringify({
|
|
1683
|
-
triggers: webhooks.map((wh) => ({
|
|
1684
|
-
id: wh.id,
|
|
1685
|
-
integrationType: wh.integrationType,
|
|
1686
|
-
objectType: wh.objectType,
|
|
1687
|
-
event: wh.event,
|
|
1688
|
-
webhookType: wh.webhookType,
|
|
1689
|
-
hookUrl: wh.hookUrl,
|
|
1690
|
-
status: wh.status,
|
|
1691
|
-
userPaused: wh.userPaused ?? false,
|
|
1692
|
-
creditSuspended: wh.creditSuspended ?? false,
|
|
1693
|
-
interval: wh.interval,
|
|
1694
|
-
connectionId: wh.connectionId,
|
|
1695
|
-
})),
|
|
1696
|
-
total: webhooks.length,
|
|
1697
|
-
}, null, 2));
|
|
1698
|
-
return;
|
|
1699
|
-
}
|
|
1700
|
-
console.log('\n' + '─'.repeat(60));
|
|
1701
|
-
console.log('⚡ Triggers / Webhook Subscriptions');
|
|
1702
|
-
console.log('─'.repeat(60) + '\n');
|
|
1703
|
-
if (webhooks.length === 0) {
|
|
1704
|
-
console.log('ℹ️ No triggers configured yet.\n');
|
|
1705
|
-
console.log('💡 Add triggers when connecting: lua integrations connect');
|
|
1706
|
-
console.log(' Or add one now: lua integrations webhooks create\n');
|
|
1707
|
-
return;
|
|
1708
|
-
}
|
|
1709
|
-
// Group by integration
|
|
1710
|
-
const byIntegration = new Map();
|
|
1711
|
-
for (const wh of webhooks) {
|
|
1712
|
-
const key = wh.integrationType;
|
|
1713
|
-
if (!byIntegration.has(key))
|
|
1714
|
-
byIntegration.set(key, []);
|
|
1715
|
-
byIntegration.get(key).push(wh);
|
|
1716
|
-
}
|
|
1717
|
-
for (const [integration, integrationWebhooks] of byIntegration) {
|
|
1718
|
-
console.log(`📦 ${integration}`);
|
|
1719
|
-
for (const wh of integrationWebhooks) {
|
|
1720
|
-
const isAgentTrigger = wh.hookUrl.includes('webhook/unifiedto');
|
|
1721
|
-
const mode = isAgentTrigger ? 'agent trigger' : 'custom URL';
|
|
1722
|
-
const typeLabel = wh.webhookType === 'native' ? 'push' : 'poll';
|
|
1723
|
-
// Determine display icon + status badge
|
|
1724
|
-
let statusIcon;
|
|
1725
|
-
let statusBadge = '';
|
|
1726
|
-
if (wh.creditSuspended) {
|
|
1727
|
-
statusIcon = '💳';
|
|
1728
|
-
statusBadge = ' (credit-suspended)';
|
|
1729
|
-
}
|
|
1730
|
-
else if (wh.userPaused) {
|
|
1731
|
-
statusIcon = '⏸️';
|
|
1732
|
-
statusBadge = ' (paused by you)';
|
|
1733
|
-
}
|
|
1734
|
-
else if (wh.status === 'active') {
|
|
1735
|
-
statusIcon = '✅';
|
|
1736
|
-
}
|
|
1737
|
-
else if (wh.status === 'unhealthy') {
|
|
1738
|
-
statusIcon = '🔴';
|
|
1739
|
-
statusBadge = ' (unhealthy)';
|
|
1740
|
-
}
|
|
1741
|
-
else {
|
|
1742
|
-
statusIcon = '⚪';
|
|
1743
|
-
}
|
|
1744
|
-
console.log(` ${statusIcon} ${wh.objectType}.${wh.event}${statusBadge} (${typeLabel}, ${mode})`);
|
|
1745
|
-
console.log(` ID: ${wh.id}`);
|
|
1746
|
-
if (!isAgentTrigger) {
|
|
1747
|
-
console.log(` URL: ${wh.hookUrl}`);
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
console.log();
|
|
1751
|
-
}
|
|
1752
|
-
console.log('─'.repeat(60));
|
|
1753
|
-
console.log(`Total: ${webhooks.length} trigger(s)\n`);
|
|
1754
|
-
}
|
|
1755
|
-
catch (error) {
|
|
1756
|
-
if (jsonOutput) {
|
|
1757
|
-
console.log(JSON.stringify({ error: error.message }));
|
|
1758
|
-
}
|
|
1759
|
-
else {
|
|
1760
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
/**
|
|
1765
|
-
* Pause a single webhook subscription (non-interactive)
|
|
1766
|
-
*/
|
|
1767
|
-
async function webhooksPauseFlow(context, webhookId, reason) {
|
|
1768
|
-
writeProgress('🔄 Pausing trigger...');
|
|
1769
|
-
try {
|
|
1770
|
-
const result = await context.unifiedToApi.pauseWebhookSubscription(context.agentId, webhookId, reason);
|
|
1771
|
-
if (result.success) {
|
|
1772
|
-
writeSuccess(`⏸️ Trigger paused: ${webhookId}\n`);
|
|
1773
|
-
if (reason)
|
|
1774
|
-
console.log(` Reason: ${reason}`);
|
|
1775
|
-
console.log(`\n💡 Resume later with: lua integrations webhooks resume --webhook-id ${webhookId}\n`);
|
|
1776
|
-
trackEvent('cli_trigger_paused', { webhook_id: webhookId });
|
|
1777
|
-
}
|
|
1778
|
-
else {
|
|
1779
|
-
writeError(`❌ Failed to pause trigger: ${result.error?.message}`);
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
catch (error) {
|
|
1783
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
/**
|
|
1787
|
-
* Resume a single webhook subscription (non-interactive)
|
|
1788
|
-
*/
|
|
1789
|
-
async function webhooksResumeFlow(context, webhookId) {
|
|
1790
|
-
writeProgress('🔄 Resuming trigger...');
|
|
1791
|
-
try {
|
|
1792
|
-
const result = await context.unifiedToApi.resumeWebhookSubscription(context.agentId, webhookId);
|
|
1793
|
-
if (result.success) {
|
|
1794
|
-
writeSuccess(`▶️ Trigger resumed: ${webhookId}\n`);
|
|
1795
|
-
trackEvent('cli_trigger_resumed', { webhook_id: webhookId });
|
|
1796
|
-
}
|
|
1797
|
-
else {
|
|
1798
|
-
const code = result.error?.code;
|
|
1799
|
-
if (code === 'CREDIT_SUSPENDED') {
|
|
1800
|
-
writeError(`❌ Cannot resume: this trigger is suspended due to credit depletion.`);
|
|
1801
|
-
console.log(` Add credits to your account to re-enable webhook triggers.\n`);
|
|
1802
|
-
}
|
|
1803
|
-
else {
|
|
1804
|
-
writeError(`❌ Failed to resume trigger: ${result.error?.message}`);
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
catch (error) {
|
|
1809
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
/**
|
|
1813
|
-
* Pause all triggers for a connection (non-interactive)
|
|
1814
|
-
*/
|
|
1815
|
-
async function connectionPauseFlow(context, connectionId) {
|
|
1816
|
-
writeProgress('🔄 Pausing all triggers for connection...');
|
|
1817
|
-
try {
|
|
1818
|
-
const result = await context.unifiedToApi.pauseConnection(context.agentId, connectionId);
|
|
1819
|
-
if (result.success && result.data) {
|
|
1820
|
-
writeSuccess(`⏸️ Paused ${result.data.affectedWebhooks} trigger(s) for connection ${connectionId}\n`);
|
|
1821
|
-
if (result.data.failedWebhooks > 0) {
|
|
1822
|
-
console.log(` ⚠️ ${result.data.failedWebhooks} trigger(s) failed to pause at Unified.to — check logs.\n`);
|
|
1823
|
-
}
|
|
1824
|
-
console.log(`\n💡 Resume later with: lua integrations webhooks resume --connection-id ${connectionId}\n`);
|
|
1825
|
-
trackEvent('cli_connection_paused', {
|
|
1826
|
-
connection_id: connectionId,
|
|
1827
|
-
affected: result.data.affectedWebhooks,
|
|
1828
|
-
failed: result.data.failedWebhooks,
|
|
1829
|
-
});
|
|
1830
|
-
}
|
|
1831
|
-
else {
|
|
1832
|
-
writeError(`❌ Failed to pause connection triggers: ${result.error?.message}`);
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
catch (error) {
|
|
1836
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
/**
|
|
1840
|
-
* Resume all triggers for a connection (non-interactive)
|
|
1841
|
-
*/
|
|
1842
|
-
async function connectionResumeFlow(context, connectionId) {
|
|
1843
|
-
writeProgress('🔄 Resuming triggers for connection...');
|
|
1844
|
-
try {
|
|
1845
|
-
const result = await context.unifiedToApi.resumeConnection(context.agentId, connectionId);
|
|
1846
|
-
if (result.success && result.data) {
|
|
1847
|
-
writeSuccess(`▶️ Resumed ${result.data.affectedWebhooks} trigger(s) for connection ${connectionId}\n`);
|
|
1848
|
-
if (result.data.skippedCreditSuspended > 0) {
|
|
1849
|
-
console.log(` ⚠️ ${result.data.skippedCreditSuspended} trigger(s) skipped — suspended due to credit depletion.`);
|
|
1850
|
-
console.log(` Add credits to your account to re-enable them.\n`);
|
|
1851
|
-
}
|
|
1852
|
-
if (result.data.failedWebhooks > 0) {
|
|
1853
|
-
console.log(` ⚠️ ${result.data.failedWebhooks} trigger(s) failed to resume at Unified.to — check logs.\n`);
|
|
1854
|
-
}
|
|
1855
|
-
trackEvent('cli_connection_resumed', {
|
|
1856
|
-
connection_id: connectionId,
|
|
1857
|
-
affected: result.data.affectedWebhooks,
|
|
1858
|
-
skipped_credit: result.data.skippedCreditSuspended,
|
|
1859
|
-
failed: result.data.failedWebhooks,
|
|
1860
|
-
});
|
|
1861
|
-
}
|
|
1862
|
-
else {
|
|
1863
|
-
writeError(`❌ Failed to resume connection triggers: ${result.error?.message}`);
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
catch (error) {
|
|
1867
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
/**
|
|
1871
|
-
* Interactive: pause a single trigger
|
|
1872
|
-
*/
|
|
1873
|
-
async function webhooksPauseInteractive(context) {
|
|
1874
|
-
writeProgress('🔄 Loading triggers...');
|
|
1875
|
-
try {
|
|
1876
|
-
const result = await context.unifiedToApi.getWebhookSubscriptions(context.agentId);
|
|
1877
|
-
if (!result.success) {
|
|
1878
|
-
writeError(`❌ Failed to load triggers: ${result.error?.message}`);
|
|
1879
|
-
return;
|
|
1880
|
-
}
|
|
1881
|
-
const webhooks = (result.data || []).filter((wh) => !wh.userPaused && wh.status !== 'unhealthy');
|
|
1882
|
-
if (webhooks.length === 0) {
|
|
1883
|
-
console.log('\nℹ️ No active triggers to pause.\n');
|
|
1884
|
-
return;
|
|
1885
|
-
}
|
|
1886
|
-
const webhookAnswer = await safePrompt([
|
|
1887
|
-
{
|
|
1888
|
-
type: 'list',
|
|
1889
|
-
name: 'webhook',
|
|
1890
|
-
message: 'Select a trigger to pause:',
|
|
1891
|
-
choices: webhooks.map((wh) => ({
|
|
1892
|
-
name: `${wh.integrationType} — ${wh.objectType}.${wh.event} (${wh.id.substring(0, 8)}...)`,
|
|
1893
|
-
value: wh.id,
|
|
1894
|
-
})),
|
|
1895
|
-
},
|
|
1896
|
-
]);
|
|
1897
|
-
if (!webhookAnswer?.webhook)
|
|
1898
|
-
return;
|
|
1899
|
-
const confirmAnswer = await safePrompt([
|
|
1900
|
-
{
|
|
1901
|
-
type: 'confirm',
|
|
1902
|
-
name: 'confirm',
|
|
1903
|
-
message: `Pause this trigger?`,
|
|
1904
|
-
default: true,
|
|
1905
|
-
},
|
|
1906
|
-
]);
|
|
1907
|
-
if (!confirmAnswer?.confirm) {
|
|
1908
|
-
console.log('\n❌ Cancelled.\n');
|
|
1909
|
-
return;
|
|
1910
|
-
}
|
|
1911
|
-
await webhooksPauseFlow(context, webhookAnswer.webhook);
|
|
1912
|
-
}
|
|
1913
|
-
catch (error) {
|
|
1914
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Interactive: resume a single trigger
|
|
1919
|
-
*/
|
|
1920
|
-
async function webhooksResumeInteractive(context) {
|
|
1921
|
-
writeProgress('🔄 Loading triggers...');
|
|
1922
|
-
try {
|
|
1923
|
-
const result = await context.unifiedToApi.getWebhookSubscriptions(context.agentId);
|
|
1924
|
-
if (!result.success) {
|
|
1925
|
-
writeError(`❌ Failed to load triggers: ${result.error?.message}`);
|
|
1926
|
-
return;
|
|
1927
|
-
}
|
|
1928
|
-
const webhooks = (result.data || []).filter((wh) => wh.userPaused && !wh.creditSuspended);
|
|
1929
|
-
if (webhooks.length === 0) {
|
|
1930
|
-
console.log('\nℹ️ No user-paused triggers to resume.\n');
|
|
1931
|
-
return;
|
|
1932
|
-
}
|
|
1933
|
-
const webhookAnswer = await safePrompt([
|
|
1934
|
-
{
|
|
1935
|
-
type: 'list',
|
|
1936
|
-
name: 'webhook',
|
|
1937
|
-
message: 'Select a trigger to resume:',
|
|
1938
|
-
choices: webhooks.map((wh) => ({
|
|
1939
|
-
name: `${wh.integrationType} — ${wh.objectType}.${wh.event} (${wh.id.substring(0, 8)}...)`,
|
|
1940
|
-
value: wh.id,
|
|
1941
|
-
})),
|
|
1942
|
-
},
|
|
1943
|
-
]);
|
|
1944
|
-
if (!webhookAnswer?.webhook)
|
|
1945
|
-
return;
|
|
1946
|
-
await webhooksResumeFlow(context, webhookAnswer.webhook);
|
|
1947
|
-
}
|
|
1948
|
-
catch (error) {
|
|
1949
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
/**
|
|
1953
|
-
* Interactive: pause all triggers for a connection
|
|
1954
|
-
*/
|
|
1955
|
-
async function connectionPauseInteractive(context) {
|
|
1956
|
-
try {
|
|
1957
|
-
const connectionsResult = await context.unifiedToApi.getConnections(context.agentId);
|
|
1958
|
-
const connections = connectionsResult.success ? connectionsResult.data || [] : [];
|
|
1959
|
-
if (connections.length === 0) {
|
|
1960
|
-
console.log('\nℹ️ No connected integrations.\n');
|
|
1961
|
-
return;
|
|
1962
|
-
}
|
|
1963
|
-
const connectionAnswer = await safePrompt([
|
|
1964
|
-
{
|
|
1965
|
-
type: 'list',
|
|
1966
|
-
name: 'connection',
|
|
1967
|
-
message: 'Select a connection to pause all triggers:',
|
|
1968
|
-
choices: connections.map((c) => ({
|
|
1969
|
-
name: `${c.integrationName || c.integrationType} (${c.id.substring(0, 8)}...)${c.allTriggersPaused ? ' [all triggers paused]' : ''}`,
|
|
1970
|
-
value: c.id,
|
|
1971
|
-
})),
|
|
1972
|
-
},
|
|
1973
|
-
]);
|
|
1974
|
-
if (!connectionAnswer?.connection)
|
|
1975
|
-
return;
|
|
1976
|
-
const confirmAnswer = await safePrompt([
|
|
1977
|
-
{
|
|
1978
|
-
type: 'confirm',
|
|
1979
|
-
name: 'confirm',
|
|
1980
|
-
message: `Pause all triggers for this connection?`,
|
|
1981
|
-
default: true,
|
|
1982
|
-
},
|
|
1983
|
-
]);
|
|
1984
|
-
if (!confirmAnswer?.confirm) {
|
|
1985
|
-
console.log('\n❌ Cancelled.\n');
|
|
1986
|
-
return;
|
|
1987
|
-
}
|
|
1988
|
-
await connectionPauseFlow(context, connectionAnswer.connection);
|
|
1989
|
-
}
|
|
1990
|
-
catch (error) {
|
|
1991
|
-
writeError(`❌ Error: ${error.message}`);
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
/**
|
|
1995
|
-
* Interactive: resume all triggers for a connection
|
|
1996
|
-
*/
|
|
1997
|
-
async function connectionResumeInteractive(context) {
|
|
1998
|
-
try {
|
|
1999
|
-
const connectionsResult = await context.unifiedToApi.getConnections(context.agentId);
|
|
2000
|
-
const connections = connectionsResult.success ? connectionsResult.data || [] : [];
|
|
2001
|
-
if (connections.length === 0) {
|
|
2002
|
-
console.log('\nℹ️ No connected integrations.\n');
|
|
2003
|
-
return;
|
|
2004
|
-
}
|
|
2005
|
-
const connectionAnswer = await safePrompt([
|
|
2006
|
-
{
|
|
2007
|
-
type: 'list',
|
|
2008
|
-
name: 'connection',
|
|
2009
|
-
message: 'Select a connection to resume triggers:',
|
|
2010
|
-
choices: connections.map((c) => ({
|
|
2011
|
-
name: `${c.integrationName || c.integrationType} (${c.id.substring(0, 8)}...)`,
|
|
2012
|
-
value: c.id,
|
|
2013
|
-
})),
|
|
2014
|
-
},
|
|
2015
|
-
]);
|
|
2016
|
-
if (!connectionAnswer?.connection)
|
|
2017
|
-
return;
|
|
2018
|
-
await connectionResumeFlow(context, connectionAnswer.connection);
|
|
2019
|
-
}
|
|
2020
|
-
catch (error) {
|
|
2021
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
/**
|
|
2025
|
-
* Create a webhook subscription
|
|
2026
|
-
*/
|
|
2027
|
-
async function webhooksCreateFlow(context, options) {
|
|
2028
|
-
// Step 1: Fetch connections
|
|
2029
|
-
writeProgress('🔄 Loading connections...');
|
|
2030
|
-
let connections = [];
|
|
2031
|
-
try {
|
|
2032
|
-
const connectionsResult = await context.unifiedToApi.getConnections(context.agentId);
|
|
2033
|
-
if (!connectionsResult.success) {
|
|
2034
|
-
writeError(`❌ Failed to load connections: ${connectionsResult.error?.message}`);
|
|
2035
|
-
return;
|
|
2036
|
-
}
|
|
2037
|
-
connections = connectionsResult.data || [];
|
|
2038
|
-
}
|
|
2039
|
-
catch (error) {
|
|
2040
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2041
|
-
return;
|
|
2042
|
-
}
|
|
2043
|
-
if (connections.length === 0) {
|
|
2044
|
-
writeInfo('No connections available.');
|
|
2045
|
-
console.log("💡 Run 'lua integrations connect' to connect an integration first.\n");
|
|
2046
|
-
return;
|
|
2047
|
-
}
|
|
2048
|
-
// Step 2: Select connection
|
|
2049
|
-
let selectedConnection;
|
|
2050
|
-
if (options.connectionId) {
|
|
2051
|
-
selectedConnection = connections.find((c) => c.id === options.connectionId);
|
|
2052
|
-
if (!selectedConnection) {
|
|
2053
|
-
console.error(`❌ Connection "${options.connectionId}" not found.`);
|
|
2054
|
-
console.log('\nAvailable connections:');
|
|
2055
|
-
connections.forEach((c) => console.log(` - ${c.id} (${c.integrationName || c.integrationType})`));
|
|
2056
|
-
throw new Error('Connection');
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
else {
|
|
2060
|
-
const connectionAnswer = await safePrompt([
|
|
2061
|
-
{
|
|
2062
|
-
type: 'list',
|
|
2063
|
-
name: 'connection',
|
|
2064
|
-
message: 'Select a connection:',
|
|
2065
|
-
choices: connections.map((c) => ({
|
|
2066
|
-
name: `${c.integrationName || c.integrationType} (${c.id.substring(0, 8)}...)`,
|
|
2067
|
-
value: c,
|
|
2068
|
-
})),
|
|
2069
|
-
},
|
|
2070
|
-
]);
|
|
2071
|
-
if (!connectionAnswer)
|
|
2072
|
-
return;
|
|
2073
|
-
selectedConnection = connectionAnswer.connection;
|
|
2074
|
-
}
|
|
2075
|
-
// Step 3: Get available events for this connection
|
|
2076
|
-
writeProgress('🔄 Loading available events...');
|
|
2077
|
-
let availableEvents = [];
|
|
2078
|
-
try {
|
|
2079
|
-
const eventsResult = await context.unifiedToApi.getAvailableWebhookEvents(context.agentId, selectedConnection.id);
|
|
2080
|
-
if (!eventsResult.success) {
|
|
2081
|
-
writeError(`❌ Failed to load events: ${eventsResult.error?.message}`);
|
|
2082
|
-
return;
|
|
2083
|
-
}
|
|
2084
|
-
availableEvents = eventsResult.data || [];
|
|
2085
|
-
}
|
|
2086
|
-
catch (error) {
|
|
2087
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2088
|
-
return;
|
|
2089
|
-
}
|
|
2090
|
-
if (availableEvents.length === 0) {
|
|
2091
|
-
writeInfo(`No trigger events available for ${selectedConnection.integrationName || selectedConnection.integrationType}.`);
|
|
2092
|
-
console.log('💡 This integration may not support triggers.\n');
|
|
2093
|
-
return;
|
|
2094
|
-
}
|
|
2095
|
-
// Step 4: Select event
|
|
2096
|
-
let selectedEvent;
|
|
2097
|
-
if (options.objectType && options.event) {
|
|
2098
|
-
selectedEvent = availableEvents.find((e) => e.objectType === options.objectType && e.event === options.event);
|
|
2099
|
-
if (!selectedEvent) {
|
|
2100
|
-
console.error(`❌ Event '${options.objectType}.${options.event}' is not supported.`);
|
|
2101
|
-
console.log(`\nAvailable events for ${selectedConnection.integrationName || selectedConnection.integrationType}:`);
|
|
2102
|
-
availableEvents.forEach((e) => console.log(` - ${e.objectType}.${e.event} [${e.webhookType}]`));
|
|
2103
|
-
throw new Error('Event');
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
else {
|
|
2107
|
-
console.log(`\nAvailable trigger events for ${selectedConnection.integrationName || selectedConnection.integrationType}:\n`);
|
|
2108
|
-
const eventAnswer = await safePrompt([
|
|
2109
|
-
{
|
|
2110
|
-
type: 'list',
|
|
2111
|
-
name: 'event',
|
|
2112
|
-
message: 'Select an event to subscribe to:',
|
|
2113
|
-
pageSize: 15,
|
|
2114
|
-
choices: availableEvents.map((e) => ({
|
|
2115
|
-
name: `${e.objectTypeDisplay} - ${e.event.charAt(0).toUpperCase() + e.event.slice(1)} [${e.webhookType}]`,
|
|
2116
|
-
value: e,
|
|
2117
|
-
})),
|
|
2118
|
-
},
|
|
2119
|
-
]);
|
|
2120
|
-
if (!eventAnswer)
|
|
2121
|
-
return;
|
|
2122
|
-
selectedEvent = eventAnswer.event;
|
|
2123
|
-
}
|
|
2124
|
-
// Step 5: Get webhook URL
|
|
2125
|
-
let hookUrl;
|
|
2126
|
-
if (options.hookUrl) {
|
|
2127
|
-
hookUrl = options.hookUrl;
|
|
2128
|
-
}
|
|
2129
|
-
else {
|
|
2130
|
-
// Ask the user whether to use the built-in agent URL or a custom endpoint.
|
|
2131
|
-
const urlModeAnswer = await safePrompt([
|
|
2132
|
-
{
|
|
2133
|
-
type: 'list',
|
|
2134
|
-
name: 'urlMode',
|
|
2135
|
-
message: 'Where should events be sent?',
|
|
2136
|
-
choices: [
|
|
2137
|
-
{
|
|
2138
|
-
name: '🤖 Wake up my Lua agent (recommended)',
|
|
2139
|
-
value: 'agent',
|
|
2140
|
-
},
|
|
2141
|
-
{
|
|
2142
|
-
name: '🔗 Custom webhook URL',
|
|
2143
|
-
value: 'custom',
|
|
2144
|
-
},
|
|
2145
|
-
],
|
|
2146
|
-
default: 'agent',
|
|
2147
|
-
},
|
|
2148
|
-
]);
|
|
2149
|
-
if (!urlModeAnswer)
|
|
2150
|
-
return;
|
|
2151
|
-
if (urlModeAnswer.urlMode === 'agent') {
|
|
2152
|
-
hookUrl = AGENT_WEBHOOK_URL;
|
|
2153
|
-
}
|
|
2154
|
-
else {
|
|
2155
|
-
const webhookAnswer = await safePrompt([
|
|
2156
|
-
{
|
|
2157
|
-
type: 'input',
|
|
2158
|
-
name: 'hookUrl',
|
|
2159
|
-
message: 'Enter the full webhook URL to receive events:',
|
|
2160
|
-
validate: (input) => {
|
|
2161
|
-
if (!input.trim())
|
|
2162
|
-
return 'Webhook URL is required';
|
|
2163
|
-
try {
|
|
2164
|
-
new URL(input);
|
|
2165
|
-
return true;
|
|
2166
|
-
}
|
|
2167
|
-
catch {
|
|
2168
|
-
return 'Enter a valid URL (e.g., https://webhook.heylua.ai/myagent/handler)';
|
|
2169
|
-
}
|
|
2170
|
-
},
|
|
2171
|
-
},
|
|
2172
|
-
]);
|
|
2173
|
-
if (!webhookAnswer)
|
|
2174
|
-
return;
|
|
2175
|
-
hookUrl = webhookAnswer.hookUrl.trim();
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
// Step 6: Get interval for virtual webhooks
|
|
2179
|
-
let interval;
|
|
2180
|
-
const intervalOptions = [
|
|
2181
|
-
{ name: '1 minute', value: 1 },
|
|
2182
|
-
{ name: '5 minutes', value: 5 },
|
|
2183
|
-
{ name: '10 minutes', value: 10 },
|
|
2184
|
-
{ name: '15 minutes', value: 15 },
|
|
2185
|
-
{ name: '30 minutes', value: 30 },
|
|
2186
|
-
{ name: '1 hour', value: 60 },
|
|
2187
|
-
{ name: '2 hours', value: 120 },
|
|
2188
|
-
{ name: '4 hours', value: 240 },
|
|
2189
|
-
{ name: '8 hours', value: 480 },
|
|
2190
|
-
{ name: '12 hours', value: 720 },
|
|
2191
|
-
{ name: '24 hours (1 day)', value: 1440 },
|
|
2192
|
-
{ name: '48 hours (2 days)', value: 2880 },
|
|
2193
|
-
];
|
|
2194
|
-
if (selectedEvent.webhookType === 'virtual') {
|
|
2195
|
-
if (options.interval !== undefined) {
|
|
2196
|
-
interval = options.interval;
|
|
2197
|
-
}
|
|
2198
|
-
else {
|
|
2199
|
-
const intervalAnswer = await safePrompt([
|
|
2200
|
-
{
|
|
2201
|
-
type: 'list',
|
|
2202
|
-
name: 'interval',
|
|
2203
|
-
message: 'Select polling interval:',
|
|
2204
|
-
choices: intervalOptions,
|
|
2205
|
-
default: 1,
|
|
2206
|
-
},
|
|
2207
|
-
]);
|
|
2208
|
-
if (!intervalAnswer)
|
|
2209
|
-
return;
|
|
2210
|
-
interval = intervalAnswer.interval;
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
// Helper to format interval display
|
|
2214
|
-
const formatInterval = (minutes) => {
|
|
2215
|
-
const option = intervalOptions.find((o) => o.value === minutes);
|
|
2216
|
-
return option ? option.name : `${minutes} minutes`;
|
|
2217
|
-
};
|
|
2218
|
-
// Step 7: Confirmation (interactive only)
|
|
2219
|
-
if (!options.connectionId) {
|
|
2220
|
-
console.log('\n' + '─'.repeat(60));
|
|
2221
|
-
console.log('📋 Trigger Summary');
|
|
2222
|
-
console.log('─'.repeat(60));
|
|
2223
|
-
console.log(` Connection: ${selectedConnection.integrationName || selectedConnection.integrationType}`);
|
|
2224
|
-
console.log(` Event: ${selectedEvent.objectType}.${selectedEvent.event} [${selectedEvent.webhookType}]`);
|
|
2225
|
-
console.log(` Webhook URL: ${hookUrl}`);
|
|
2226
|
-
if (interval)
|
|
2227
|
-
console.log(` Interval: ${formatInterval(interval)}`);
|
|
2228
|
-
console.log('─'.repeat(60) + '\n');
|
|
2229
|
-
const confirmAnswer = await safePrompt([
|
|
2230
|
-
{
|
|
2231
|
-
type: 'confirm',
|
|
2232
|
-
name: 'confirm',
|
|
2233
|
-
message: 'Create this trigger?',
|
|
2234
|
-
default: true,
|
|
2235
|
-
},
|
|
2236
|
-
]);
|
|
2237
|
-
if (!confirmAnswer?.confirm) {
|
|
2238
|
-
console.log('\n❌ Cancelled.\n');
|
|
2239
|
-
return;
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
// Step 8: Create the webhook
|
|
2243
|
-
writeProgress('🔄 Creating trigger...');
|
|
2244
|
-
try {
|
|
2245
|
-
const createResult = await context.unifiedToApi.createWebhookSubscription(context.agentId, {
|
|
2246
|
-
connectionId: selectedConnection.id,
|
|
2247
|
-
objectType: selectedEvent.objectType,
|
|
2248
|
-
event: selectedEvent.event,
|
|
2249
|
-
hookUrl,
|
|
2250
|
-
interval,
|
|
2251
|
-
});
|
|
2252
|
-
if (!createResult.success || !createResult.data) {
|
|
2253
|
-
writeError(`❌ Failed to create trigger: ${createResult.error?.message}`);
|
|
2254
|
-
return;
|
|
2255
|
-
}
|
|
2256
|
-
const webhook = createResult.data;
|
|
2257
|
-
const isAgentTrigger = webhook.hookUrl.includes('webhook/unifiedto');
|
|
2258
|
-
const typeLabel = webhook.webhookType === 'native' ? 'push' : 'polling';
|
|
2259
|
-
console.log('\n' + '─'.repeat(60));
|
|
2260
|
-
writeSuccess('✅ Trigger created!');
|
|
2261
|
-
console.log('─'.repeat(60));
|
|
2262
|
-
console.log(` Integration: ${webhook.integrationType}`);
|
|
2263
|
-
console.log(` Event: ${webhook.objectType}.${webhook.event}`);
|
|
2264
|
-
console.log(` Type: ${typeLabel}`);
|
|
2265
|
-
console.log(` Mode: ${isAgentTrigger ? 'Agent wake-up' : 'Custom URL'}`);
|
|
2266
|
-
if (!isAgentTrigger) {
|
|
2267
|
-
console.log(` URL: ${webhook.hookUrl}`);
|
|
2268
|
-
}
|
|
2269
|
-
if (webhook.interval)
|
|
2270
|
-
console.log(` Poll interval: ${formatInterval(webhook.interval)}`);
|
|
2271
|
-
console.log(` Status: ${webhook.status}`);
|
|
2272
|
-
console.log('─'.repeat(60) + '\n');
|
|
2273
|
-
if (isAgentTrigger) {
|
|
2274
|
-
console.log('💡 Your agent will now wake up when this event occurs.\n');
|
|
2275
|
-
}
|
|
2276
|
-
else {
|
|
2277
|
-
console.log('💡 Ensure your webhook endpoint is ready to receive events.\n');
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
catch (error) {
|
|
2281
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2282
|
-
}
|
|
2283
|
-
}
|
|
2284
|
-
/**
|
|
2285
|
-
* Delete a webhook subscription (interactive)
|
|
2286
|
-
*/
|
|
2287
|
-
async function webhooksDeleteInteractive(context) {
|
|
2288
|
-
writeProgress('🔄 Loading triggers...');
|
|
2289
|
-
try {
|
|
2290
|
-
const result = await context.unifiedToApi.getWebhookSubscriptions(context.agentId);
|
|
2291
|
-
if (!result.success) {
|
|
2292
|
-
writeError(`❌ Failed to load triggers: ${result.error?.message}`);
|
|
2293
|
-
return;
|
|
2294
|
-
}
|
|
2295
|
-
const webhooks = result.data || [];
|
|
2296
|
-
if (webhooks.length === 0) {
|
|
2297
|
-
console.log('\nℹ️ No triggers to delete.\n');
|
|
2298
|
-
return;
|
|
2299
|
-
}
|
|
2300
|
-
const webhookAnswer = await safePrompt([
|
|
2301
|
-
{
|
|
2302
|
-
type: 'list',
|
|
2303
|
-
name: 'webhook',
|
|
2304
|
-
message: 'Select a trigger to delete:',
|
|
2305
|
-
choices: webhooks.map((wh) => {
|
|
2306
|
-
// Show last part of URL for readability
|
|
2307
|
-
const urlParts = (wh.hookUrl || '').split('/');
|
|
2308
|
-
const shortUrl = urlParts.length > 3 ? '.../' + urlParts.slice(-2).join('/') : wh.hookUrl || '';
|
|
2309
|
-
return {
|
|
2310
|
-
name: `${wh.id.substring(0, 8)}... - ${wh.integrationType} ${wh.objectType}.${wh.event} → ${shortUrl}`,
|
|
2311
|
-
value: wh.id,
|
|
2312
|
-
};
|
|
2313
|
-
}),
|
|
2314
|
-
},
|
|
2315
|
-
]);
|
|
2316
|
-
if (!webhookAnswer?.webhook)
|
|
2317
|
-
return;
|
|
2318
|
-
const selectedWebhook = webhooks.find((wh) => wh.id === webhookAnswer.webhook);
|
|
2319
|
-
const confirmAnswer = await safePrompt([
|
|
2320
|
-
{
|
|
2321
|
-
type: 'confirm',
|
|
2322
|
-
name: 'confirm',
|
|
2323
|
-
message: `Delete trigger for ${selectedWebhook?.objectType}.${selectedWebhook?.event}?`,
|
|
2324
|
-
default: false,
|
|
2325
|
-
},
|
|
2326
|
-
]);
|
|
2327
|
-
if (!confirmAnswer?.confirm) {
|
|
2328
|
-
console.log('\n❌ Cancelled.\n');
|
|
2329
|
-
return;
|
|
2330
|
-
}
|
|
2331
|
-
await webhooksDeleteFlow(context, webhookAnswer.webhook);
|
|
2332
|
-
}
|
|
2333
|
-
catch (error) {
|
|
2334
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2335
|
-
}
|
|
2336
|
-
}
|
|
2337
|
-
/**
|
|
2338
|
-
* Delete a webhook subscription (non-interactive)
|
|
2339
|
-
*/
|
|
2340
|
-
async function webhooksDeleteFlow(context, webhookId) {
|
|
2341
|
-
writeProgress('🔄 Deleting trigger...');
|
|
2342
|
-
try {
|
|
2343
|
-
const result = await context.unifiedToApi.deleteWebhookSubscription(context.agentId, webhookId);
|
|
2344
|
-
if (result.success) {
|
|
2345
|
-
writeSuccess(`✅ Trigger deleted: ${webhookId}\n`);
|
|
2346
|
-
}
|
|
2347
|
-
else {
|
|
2348
|
-
writeError(`❌ Failed to delete trigger: ${result.error?.message}`);
|
|
2349
|
-
}
|
|
2350
|
-
}
|
|
2351
|
-
catch (error) {
|
|
2352
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
2356
|
-
// MCP Server Management
|
|
2357
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
2358
|
-
/**
|
|
2359
|
-
* Handle mcp subcommand (non-interactive entry point)
|
|
2360
|
-
*/
|
|
2361
|
-
async function mcpSubcommand(context, cmdOptions) {
|
|
2362
|
-
const subAction = cmdOptions?._?.[0]?.toLowerCase() || '';
|
|
2363
|
-
const options = {
|
|
2364
|
-
connectionId: cmdOptions?.connection || cmdOptions?.connectionId,
|
|
2365
|
-
};
|
|
2366
|
-
await mcpManagementFlow(context, options, subAction);
|
|
2367
|
-
}
|
|
2368
|
-
/**
|
|
2369
|
-
* Main handler for MCP management subcommand
|
|
2370
|
-
*/
|
|
2371
|
-
async function mcpManagementFlow(context, options, subAction) {
|
|
2372
|
-
// Non-interactive mode
|
|
2373
|
-
if (subAction === 'list') {
|
|
2374
|
-
await mcpListFlow(context);
|
|
2375
|
-
return;
|
|
2376
|
-
}
|
|
2377
|
-
if (subAction === 'activate') {
|
|
2378
|
-
if (!options.connectionId) {
|
|
2379
|
-
writeError('❌ Missing required option: --connection <id>');
|
|
2380
|
-
console.log("\n💡 Use 'lua integrations mcp list' to see available connection IDs.\n");
|
|
2381
|
-
return;
|
|
2382
|
-
}
|
|
2383
|
-
await mcpActivateFlow(context, options.connectionId);
|
|
2384
|
-
return;
|
|
2385
|
-
}
|
|
2386
|
-
if (subAction === 'deactivate') {
|
|
2387
|
-
if (!options.connectionId) {
|
|
2388
|
-
writeError('❌ Missing required option: --connection <id>');
|
|
2389
|
-
console.log("\n💡 Use 'lua integrations mcp list' to see available connection IDs.\n");
|
|
2390
|
-
return;
|
|
2391
|
-
}
|
|
2392
|
-
await mcpDeactivateFlow(context, options.connectionId);
|
|
2393
|
-
return;
|
|
2394
|
-
}
|
|
2395
|
-
// Interactive mode
|
|
2396
|
-
const actionAnswer = await safePrompt([
|
|
2397
|
-
{
|
|
2398
|
-
type: 'list',
|
|
2399
|
-
name: 'action',
|
|
2400
|
-
message: 'What would you like to do?',
|
|
2401
|
-
choices: [
|
|
2402
|
-
{ name: '📋 List connections with MCP status', value: 'list' },
|
|
2403
|
-
{ name: '✅ Activate MCP server for a connection', value: 'activate' },
|
|
2404
|
-
{ name: '⏸️ Deactivate MCP server for a connection', value: 'deactivate' },
|
|
2405
|
-
{ name: '← Back', value: 'back' },
|
|
2406
|
-
],
|
|
2407
|
-
},
|
|
2408
|
-
]);
|
|
2409
|
-
if (!actionAnswer || actionAnswer.action === 'back')
|
|
2410
|
-
return;
|
|
2411
|
-
switch (actionAnswer.action) {
|
|
2412
|
-
case 'list':
|
|
2413
|
-
await mcpListFlow(context);
|
|
2414
|
-
break;
|
|
2415
|
-
case 'activate':
|
|
2416
|
-
await mcpActivateInteractive(context);
|
|
2417
|
-
break;
|
|
2418
|
-
case 'deactivate':
|
|
2419
|
-
await mcpDeactivateInteractive(context);
|
|
2420
|
-
break;
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
/**
|
|
2424
|
-
* List all connections with their MCP server status
|
|
2425
|
-
*/
|
|
2426
|
-
async function mcpListFlow(context) {
|
|
2427
|
-
writeProgress('🔄 Loading connections and MCP servers...');
|
|
2428
|
-
try {
|
|
2429
|
-
const [connectionsResult, mcpServers] = await Promise.all([
|
|
2430
|
-
context.unifiedToApi.getConnections(context.agentId),
|
|
2431
|
-
fetchServersCore(context),
|
|
2432
|
-
]);
|
|
2433
|
-
if (!connectionsResult.success) {
|
|
2434
|
-
writeError(`❌ Failed to load connections: ${connectionsResult.error?.message}`);
|
|
2435
|
-
return;
|
|
2436
|
-
}
|
|
2437
|
-
if (!mcpServers)
|
|
2438
|
-
return;
|
|
2439
|
-
const connections = connectionsResult.data || [];
|
|
2440
|
-
const unifiedServers = mcpServers.filter((s) => s.source === 'unifiedto');
|
|
2441
|
-
// Map connection IDs to MCP servers
|
|
2442
|
-
const serverByConnectionId = new Map();
|
|
2443
|
-
for (const server of unifiedServers) {
|
|
2444
|
-
const connectionMatch = server.url?.match(/connection=([a-f0-9]+)/i);
|
|
2445
|
-
if (connectionMatch) {
|
|
2446
|
-
serverByConnectionId.set(connectionMatch[1], server);
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
console.log('\n' + '─'.repeat(80));
|
|
2450
|
-
console.log('🔌 MCP Servers for Connections');
|
|
2451
|
-
console.log('─'.repeat(80) + '\n');
|
|
2452
|
-
if (connections.length === 0) {
|
|
2453
|
-
console.log('ℹ️ No connections found.\n');
|
|
2454
|
-
console.log('💡 Connect an integration with: lua integrations connect\n');
|
|
2455
|
-
return;
|
|
2456
|
-
}
|
|
2457
|
-
for (const conn of connections) {
|
|
2458
|
-
const mcpServer = serverByConnectionId.get(conn.id);
|
|
2459
|
-
const status = mcpServer?.active ? '✅ active' : '⏸️ inactive';
|
|
2460
|
-
const serverName = mcpServer?.name || 'Not found';
|
|
2461
|
-
console.log(` Connection: ${conn.id}`);
|
|
2462
|
-
console.log(` Integration: ${conn.integrationName || conn.integrationType}`);
|
|
2463
|
-
console.log(` MCP Server: ${serverName}`);
|
|
2464
|
-
console.log(` Status: ${status}`);
|
|
2465
|
-
console.log('─'.repeat(80));
|
|
2466
|
-
}
|
|
2467
|
-
console.log(`\nTotal: ${connections.length} connection(s)`);
|
|
2468
|
-
console.log("\n💡 Use --connection <id> with 'activate' or 'deactivate' commands.\n");
|
|
2469
|
-
}
|
|
2470
|
-
catch (error) {
|
|
2471
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
/**
|
|
2475
|
-
* Activate MCP server for a connection (non-interactive)
|
|
2476
|
-
*/
|
|
2477
|
-
async function mcpActivateFlow(context, connectionId) {
|
|
2478
|
-
writeProgress('🔄 Finding MCP server for connection...');
|
|
2479
|
-
try {
|
|
2480
|
-
const mcpServers = await fetchServersCore(context);
|
|
2481
|
-
if (!mcpServers)
|
|
2482
|
-
return;
|
|
2483
|
-
const mcpServer = mcpServers.find((s) => s.source === 'unifiedto' && s.url?.includes(`connection=${connectionId}`));
|
|
2484
|
-
if (!mcpServer) {
|
|
2485
|
-
writeError(`❌ No MCP server found for connection: ${connectionId}`);
|
|
2486
|
-
console.log("\n💡 Make sure the connection exists. Use 'lua integrations list' to check.\n");
|
|
2487
|
-
return;
|
|
2488
|
-
}
|
|
2489
|
-
await activateServerCore(context, mcpServer);
|
|
2490
|
-
}
|
|
2491
|
-
catch (error) {
|
|
2492
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
/**
|
|
2496
|
-
* Deactivate MCP server for a connection (non-interactive)
|
|
2497
|
-
*/
|
|
2498
|
-
async function mcpDeactivateFlow(context, connectionId) {
|
|
2499
|
-
writeProgress('🔄 Finding MCP server for connection...');
|
|
2500
|
-
try {
|
|
2501
|
-
const mcpServers = await fetchServersCore(context);
|
|
2502
|
-
if (!mcpServers)
|
|
2503
|
-
return;
|
|
2504
|
-
const mcpServer = mcpServers.find((s) => s.source === 'unifiedto' && s.url?.includes(`connection=${connectionId}`));
|
|
2505
|
-
if (!mcpServer) {
|
|
2506
|
-
writeError(`❌ No MCP server found for connection: ${connectionId}`);
|
|
2507
|
-
console.log("\n💡 Make sure the connection exists. Use 'lua integrations list' to check.\n");
|
|
2508
|
-
return;
|
|
2509
|
-
}
|
|
2510
|
-
await deactivateServerCore(context, mcpServer);
|
|
2511
|
-
}
|
|
2512
|
-
catch (error) {
|
|
2513
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
/**
|
|
2517
|
-
* Interactive flow for activating MCP server
|
|
2518
|
-
*/
|
|
2519
|
-
async function mcpActivateInteractive(context) {
|
|
2520
|
-
writeProgress('🔄 Loading connections...');
|
|
2521
|
-
try {
|
|
2522
|
-
const [connectionsResult, mcpServers] = await Promise.all([
|
|
2523
|
-
context.unifiedToApi.getConnections(context.agentId),
|
|
2524
|
-
fetchServersCore(context),
|
|
2525
|
-
]);
|
|
2526
|
-
if (!connectionsResult.success) {
|
|
2527
|
-
writeError(`❌ Failed to load connections: ${connectionsResult.error?.message}`);
|
|
2528
|
-
return;
|
|
2529
|
-
}
|
|
2530
|
-
if (!mcpServers)
|
|
2531
|
-
return;
|
|
2532
|
-
const connections = connectionsResult.data || [];
|
|
2533
|
-
// Map connection IDs to MCP servers
|
|
2534
|
-
const serverByConnectionId = new Map();
|
|
2535
|
-
for (const server of mcpServers) {
|
|
2536
|
-
if (server.source === 'unifiedto') {
|
|
2537
|
-
const connectionMatch = server.url?.match(/connection=([a-f0-9]+)/i);
|
|
2538
|
-
if (connectionMatch) {
|
|
2539
|
-
serverByConnectionId.set(connectionMatch[1], server);
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
// Filter to show only inactive MCP servers
|
|
2544
|
-
const inactiveConnections = connections.filter((conn) => {
|
|
2545
|
-
const server = serverByConnectionId.get(conn.id);
|
|
2546
|
-
return server && !server.active;
|
|
2547
|
-
});
|
|
2548
|
-
if (inactiveConnections.length === 0) {
|
|
2549
|
-
writeInfo('ℹ️ All MCP servers are already active (or no connections found).\n');
|
|
2550
|
-
return;
|
|
2551
|
-
}
|
|
2552
|
-
const connectionAnswer = await safePrompt([
|
|
2553
|
-
{
|
|
2554
|
-
type: 'list',
|
|
2555
|
-
name: 'connectionId',
|
|
2556
|
-
message: 'Select a connection to activate MCP:',
|
|
2557
|
-
choices: inactiveConnections.map((conn) => ({
|
|
2558
|
-
name: `${conn.integrationName || conn.integrationType} (${conn.id.substring(0, 12)}...)`,
|
|
2559
|
-
value: conn.id,
|
|
2560
|
-
})),
|
|
2561
|
-
},
|
|
2562
|
-
]);
|
|
2563
|
-
if (!connectionAnswer)
|
|
2564
|
-
return;
|
|
2565
|
-
await mcpActivateFlow(context, connectionAnswer.connectionId);
|
|
2566
|
-
}
|
|
2567
|
-
catch (error) {
|
|
2568
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
/**
|
|
2572
|
-
* Interactive flow for deactivating MCP server
|
|
2573
|
-
*/
|
|
2574
|
-
async function mcpDeactivateInteractive(context) {
|
|
2575
|
-
writeProgress('🔄 Loading connections...');
|
|
2576
|
-
try {
|
|
2577
|
-
const [connectionsResult, mcpServers] = await Promise.all([
|
|
2578
|
-
context.unifiedToApi.getConnections(context.agentId),
|
|
2579
|
-
fetchServersCore(context),
|
|
2580
|
-
]);
|
|
2581
|
-
if (!connectionsResult.success) {
|
|
2582
|
-
writeError(`❌ Failed to load connections: ${connectionsResult.error?.message}`);
|
|
2583
|
-
return;
|
|
2584
|
-
}
|
|
2585
|
-
if (!mcpServers)
|
|
2586
|
-
return;
|
|
2587
|
-
const connections = connectionsResult.data || [];
|
|
2588
|
-
// Map connection IDs to MCP servers
|
|
2589
|
-
const serverByConnectionId = new Map();
|
|
2590
|
-
for (const server of mcpServers) {
|
|
2591
|
-
if (server.source === 'unifiedto') {
|
|
2592
|
-
const connectionMatch = server.url?.match(/connection=([a-f0-9]+)/i);
|
|
2593
|
-
if (connectionMatch) {
|
|
2594
|
-
serverByConnectionId.set(connectionMatch[1], server);
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
// Filter to show only active MCP servers
|
|
2599
|
-
const activeConnections = connections.filter((conn) => {
|
|
2600
|
-
const server = serverByConnectionId.get(conn.id);
|
|
2601
|
-
return server && server.active;
|
|
2602
|
-
});
|
|
2603
|
-
if (activeConnections.length === 0) {
|
|
2604
|
-
writeInfo('ℹ️ No active MCP servers found to deactivate.\n');
|
|
2605
|
-
return;
|
|
2606
|
-
}
|
|
2607
|
-
const connectionAnswer = await safePrompt([
|
|
2608
|
-
{
|
|
2609
|
-
type: 'list',
|
|
2610
|
-
name: 'connectionId',
|
|
2611
|
-
message: 'Select a connection to deactivate MCP:',
|
|
2612
|
-
choices: activeConnections.map((conn) => ({
|
|
2613
|
-
name: `${conn.integrationName || conn.integrationType} (${conn.id.substring(0, 12)}...)`,
|
|
2614
|
-
value: conn.id,
|
|
2615
|
-
})),
|
|
2616
|
-
},
|
|
2617
|
-
]);
|
|
2618
|
-
if (!connectionAnswer)
|
|
2619
|
-
return;
|
|
2620
|
-
await mcpDeactivateFlow(context, connectionAnswer.connectionId);
|
|
2621
|
-
}
|
|
2622
|
-
catch (error) {
|
|
2623
|
-
writeError(`❌ Error: ${error.message}`);
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
2627
|
-
// Help
|
|
2628
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
2629
|
-
function showUsage() {
|
|
2630
|
-
console.log('\nUsage:');
|
|
2631
|
-
console.log(' lua integrations Interactive integration management');
|
|
2632
|
-
console.log(' lua integrations connect Connect a new integration (interactive)');
|
|
2633
|
-
console.log(' lua integrations connect --integration <type> Connect a specific integration');
|
|
2634
|
-
console.log(' lua integrations connect --integration <type> --triggers <events> Connect with triggers');
|
|
2635
|
-
console.log(' lua integrations update Update connection scopes (interactive)');
|
|
2636
|
-
console.log(' lua integrations update --integration <type> Update scopes for a specific integration');
|
|
2637
|
-
console.log(' lua integrations list List connected integrations');
|
|
2638
|
-
console.log(' lua integrations available List available integrations');
|
|
2639
|
-
console.log(' lua integrations info <type> Show integration details (scopes, triggers)');
|
|
2640
|
-
console.log(' lua integrations info <type> --json Output as JSON for scripting');
|
|
2641
|
-
console.log(' lua integrations disconnect --connection-id <id> Disconnect an integration');
|
|
2642
|
-
console.log('\nTriggers (also available as: lua triggers <action>):');
|
|
2643
|
-
console.log(' lua integrations webhooks list List all triggers');
|
|
2644
|
-
console.log(' lua integrations webhooks list --json Output as JSON');
|
|
2645
|
-
console.log(' lua integrations webhooks events --connection <id> List available events for a connection');
|
|
2646
|
-
console.log(' lua integrations webhooks events --integration <type> List available events for an integration');
|
|
2647
|
-
console.log(' lua integrations webhooks create Create trigger (interactive)');
|
|
2648
|
-
console.log(' lua integrations webhooks create --connection <id> --object <type> --event <event> --hook-url <url>');
|
|
2649
|
-
console.log(' lua integrations webhooks delete --webhook-id <id> Delete a trigger');
|
|
2650
|
-
console.log(' lua integrations webhooks pause --webhook-id <id> Pause a trigger');
|
|
2651
|
-
console.log(' lua integrations webhooks pause --connection-id <id> Pause all triggers for a connection');
|
|
2652
|
-
console.log(' lua integrations webhooks resume --webhook-id <id> Resume a trigger');
|
|
2653
|
-
console.log(' lua integrations webhooks resume --connection-id <id> Resume all triggers for a connection');
|
|
2654
|
-
console.log('\nMCP Server Management:');
|
|
2655
|
-
console.log(' lua integrations mcp list List connections with MCP status');
|
|
2656
|
-
console.log(' lua integrations mcp activate --connection <id> Activate MCP server');
|
|
2657
|
-
console.log(' lua integrations mcp deactivate --connection <id> Deactivate MCP server');
|
|
2658
|
-
console.log('\nTrigger Options (use with connect):');
|
|
2659
|
-
console.log(' --triggers <events> Comma-separated triggers (e.g., task_task.created,task_task.updated)');
|
|
2660
|
-
console.log(' Omit to skip triggers and add them later');
|
|
2661
|
-
console.log(' --custom-webhook Use custom URL instead of agent trigger');
|
|
2662
|
-
console.log(' --hook-url <url> Custom URL for triggers');
|
|
2663
|
-
console.log('\nPause Options (use with webhooks pause):');
|
|
2664
|
-
console.log(' --reason <text> Optional reason for pausing (informational)');
|
|
2665
|
-
}
|
|
2666
|
-
//# sourceMappingURL=integrations.js.map
|