lua-cli 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/api/logs.api.service.d.ts +1 -1
  2. package/dist/api/logs.api.service.js.map +1 -1
  3. package/dist/api/products.api.service.d.ts +17 -5
  4. package/dist/api/products.api.service.js +21 -9
  5. package/dist/api/products.api.service.js.map +1 -1
  6. package/dist/api-exports.d.ts +17 -5
  7. package/dist/api-exports.js +20 -5
  8. package/dist/api-exports.js.map +1 -1
  9. package/dist/cli/command-definitions.js +320 -88
  10. package/dist/cli/command-definitions.js.map +1 -1
  11. package/dist/commands/apiKey.d.ts +5 -2
  12. package/dist/commands/apiKey.js +8 -2
  13. package/dist/commands/apiKey.js.map +1 -1
  14. package/dist/commands/channels.d.ts +4 -9
  15. package/dist/commands/channels.js +140 -84
  16. package/dist/commands/channels.js.map +1 -1
  17. package/dist/commands/chat.d.ts +4 -2
  18. package/dist/commands/chat.js +126 -32
  19. package/dist/commands/chat.js.map +1 -1
  20. package/dist/commands/chatClear.d.ts +3 -2
  21. package/dist/commands/chatClear.js +16 -15
  22. package/dist/commands/chatClear.js.map +1 -1
  23. package/dist/commands/compile.js +67 -4
  24. package/dist/commands/compile.js.map +1 -1
  25. package/dist/commands/deploy.d.ts +5 -24
  26. package/dist/commands/deploy.js +75 -48
  27. package/dist/commands/deploy.js.map +1 -1
  28. package/dist/commands/destroy.d.ts +5 -2
  29. package/dist/commands/destroy.js +14 -2
  30. package/dist/commands/destroy.js.map +1 -1
  31. package/dist/commands/env.d.ts +3 -1
  32. package/dist/commands/env.js +322 -122
  33. package/dist/commands/env.js.map +1 -1
  34. package/dist/commands/features.d.ts +5 -9
  35. package/dist/commands/features.js +249 -129
  36. package/dist/commands/features.js.map +1 -1
  37. package/dist/commands/init.d.ts +7 -1
  38. package/dist/commands/init.js +242 -59
  39. package/dist/commands/init.js.map +1 -1
  40. package/dist/commands/jobs.d.ts +5 -13
  41. package/dist/commands/jobs.js +449 -364
  42. package/dist/commands/jobs.js.map +1 -1
  43. package/dist/commands/logs.d.ts +5 -10
  44. package/dist/commands/logs.js +259 -103
  45. package/dist/commands/logs.js.map +1 -1
  46. package/dist/commands/marketplace.d.ts +23 -2
  47. package/dist/commands/marketplace.js +530 -7
  48. package/dist/commands/marketplace.js.map +1 -1
  49. package/dist/commands/mcp.d.ts +5 -11
  50. package/dist/commands/mcp.js +303 -288
  51. package/dist/commands/mcp.js.map +1 -1
  52. package/dist/commands/persona.d.ts +5 -9
  53. package/dist/commands/persona.js +349 -232
  54. package/dist/commands/persona.js.map +1 -1
  55. package/dist/commands/postprocessors.d.ts +6 -2
  56. package/dist/commands/postprocessors.js +387 -280
  57. package/dist/commands/postprocessors.js.map +1 -1
  58. package/dist/commands/preprocessors.d.ts +6 -2
  59. package/dist/commands/preprocessors.js +387 -280
  60. package/dist/commands/preprocessors.js.map +1 -1
  61. package/dist/commands/production.d.ts +5 -8
  62. package/dist/commands/production.js +317 -228
  63. package/dist/commands/production.js.map +1 -1
  64. package/dist/commands/push.js +385 -427
  65. package/dist/commands/push.js.map +1 -1
  66. package/dist/commands/resources.d.ts +5 -10
  67. package/dist/commands/resources.js +219 -154
  68. package/dist/commands/resources.js.map +1 -1
  69. package/dist/commands/skills.d.ts +5 -9
  70. package/dist/commands/skills.js +354 -277
  71. package/dist/commands/skills.js.map +1 -1
  72. package/dist/commands/sync.d.ts +10 -8
  73. package/dist/commands/sync.js +110 -19
  74. package/dist/commands/sync.js.map +1 -1
  75. package/dist/commands/test.d.ts +1 -11
  76. package/dist/commands/test.js +395 -438
  77. package/dist/commands/test.js.map +1 -1
  78. package/dist/commands/webhooks.d.ts +5 -11
  79. package/dist/commands/webhooks.js +356 -290
  80. package/dist/commands/webhooks.js.map +1 -1
  81. package/dist/interfaces/mcp.d.ts +28 -1
  82. package/dist/interfaces/product.d.ts +26 -0
  83. package/dist/types/api-contracts.d.ts +8 -4
  84. package/dist/types/index.d.ts +1 -1
  85. package/dist/types/index.js.map +1 -1
  86. package/dist/types/skill.d.ts +92 -17
  87. package/dist/types/skill.js +15 -11
  88. package/dist/types/skill.js.map +1 -1
  89. package/dist/utils/bundling.d.ts +17 -0
  90. package/dist/utils/bundling.js +96 -0
  91. package/dist/utils/bundling.js.map +1 -1
  92. package/dist/utils/compile.d.ts +4 -0
  93. package/dist/utils/compile.js +5 -0
  94. package/dist/utils/compile.js.map +1 -1
  95. package/dist/utils/dev-helpers.d.ts +3 -2
  96. package/dist/utils/dev-helpers.js +3 -5
  97. package/dist/utils/dev-helpers.js.map +1 -1
  98. package/dist/utils/mcp-server-management.d.ts +1 -1
  99. package/dist/utils/mcp-server-management.js +13 -14
  100. package/dist/utils/mcp-server-management.js.map +1 -1
  101. package/package.json +1 -1
  102. package/template/package.json +1 -1
@@ -9,22 +9,23 @@ import { BASE_URLS } from '../config/constants.js';
9
9
  import { safePrompt } from '../utils/prompt-handler.js';
10
10
  import { validateConfig, validateAgentConfig, } from '../utils/dev-helpers.js';
11
11
  import WebhookApi from '../api/webhook.api.service.js';
12
+ // ─────────────────────────────────────────────────────────────────────────────
13
+ // Main Command Entry
14
+ // ─────────────────────────────────────────────────────────────────────────────
12
15
  /**
13
- * Main webhooks command - manages agent webhooks
16
+ * Main webhooks command - manages agent webhooks.
14
17
  *
15
- * Features:
16
- * - View deployed webhooks
17
- * - View webhook versions
18
- * - Deploy webhook versions to production
19
- * - Activate/deactivate webhooks
20
- *
21
- * Note: For local testing, use `lua test webhook`
22
- *
23
- * @returns Promise that resolves when command completes
18
+ * Supports both interactive and non-interactive modes:
19
+ * - Interactive: prompts for action and webhook selection
20
+ * - Non-interactive: use action argument with -i and -v flags
24
21
  */
25
- export async function webhooksCommand() {
22
+ export async function webhooksCommand(action, cmdObj) {
26
23
  return withErrorHandling(async () => {
27
- // Step 1: Load configuration first (to get agentId)
24
+ const options = {
25
+ webhookName: cmdObj?.webhookName || null,
26
+ webhookVersion: cmdObj?.webhookVersion || null,
27
+ };
28
+ // Step 1: Load configuration
28
29
  const config = readSkillConfig();
29
30
  validateConfig(config);
30
31
  validateAgentConfig(config);
@@ -42,14 +43,284 @@ export async function webhooksCommand() {
42
43
  agentId,
43
44
  apiKey,
44
45
  };
45
- // Start webhook management
46
- await manageProductionWebhooks(context, config);
46
+ // Determine mode
47
+ if (action) {
48
+ await executeNonInteractive(context, config, action, options);
49
+ }
50
+ else {
51
+ await manageWebhooksInteractive(context, config);
52
+ }
47
53
  }, "webhooks");
48
54
  }
55
+ // ─────────────────────────────────────────────────────────────────────────────
56
+ // Shared Core Functions
57
+ // ─────────────────────────────────────────────────────────────────────────────
58
+ /**
59
+ * Displays all webhooks with their current status.
60
+ */
61
+ async function displayWebhooksCore(context, webhooks) {
62
+ console.log("\n" + "=".repeat(60));
63
+ console.log("⚙️ Production Webhooks");
64
+ console.log("=".repeat(60) + "\n");
65
+ const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
66
+ for (const webhook of webhooks) {
67
+ try {
68
+ const response = await webhookApi.getWebhookVersions(webhook.webhookId);
69
+ if (response.success && response.data) {
70
+ const versions = response.data.versions || [];
71
+ const activeVersionId = response.data.activeVersionId;
72
+ const activeVersion = versions.find((v) => v.webhookId === activeVersionId);
73
+ console.log(`🪝 ${webhook.name}`);
74
+ console.log(` Webhook ID: ${webhook.webhookId}`);
75
+ if (activeVersion) {
76
+ console.log(` Deployed Version: ${activeVersion.version} ⭐`);
77
+ console.log(` Deployed: ${new Date(activeVersion.createdAt).toLocaleString()}`);
78
+ }
79
+ else {
80
+ console.log(` Deployed Version: Not deployed`);
81
+ }
82
+ console.log(` Total Versions: ${versions.length}`);
83
+ console.log();
84
+ }
85
+ else {
86
+ displayWebhookError(webhook, "Unable to fetch version info");
87
+ }
88
+ }
89
+ catch {
90
+ displayWebhookError(webhook, "Error loading versions");
91
+ }
92
+ }
93
+ console.log("=".repeat(60));
94
+ }
95
+ function displayWebhookError(webhook, status) {
96
+ console.log(`🪝 ${webhook.name}`);
97
+ console.log(` Webhook ID: ${webhook.webhookId}`);
98
+ console.log(` Status: ${status}`);
99
+ console.log();
100
+ }
101
+ /**
102
+ * Fetches and returns sorted webhook versions.
103
+ */
104
+ async function fetchVersionsCore(context, webhook) {
105
+ const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
106
+ const response = await webhookApi.getWebhookVersions(webhook.webhookId);
107
+ if (!response.success || !response.data) {
108
+ console.error(`❌ Failed to fetch versions: ${response.error?.message || 'Unknown error'}`);
109
+ return null;
110
+ }
111
+ const versions = (response.data.versions || []).sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
112
+ return { versions, activeVersionId: response.data.activeVersionId };
113
+ }
114
+ /**
115
+ * Displays versions for a webhook.
116
+ */
117
+ function displayVersionsCore(webhook, versions, activeVersionId) {
118
+ console.log("\n" + "=".repeat(60));
119
+ console.log(`📜 Versions for ${webhook.name}`);
120
+ console.log("=".repeat(60) + "\n");
121
+ versions.forEach((version, index) => {
122
+ const isActive = version.webhookId === activeVersionId;
123
+ console.log(`${index + 1}. Version ${version.version}${isActive ? ' ⭐ DEPLOYED' : ''}`);
124
+ console.log(` Created: ${new Date(version.createdAt).toLocaleString()}`);
125
+ console.log(` Version ID: ${version.webhookId}`);
126
+ console.log();
127
+ });
128
+ console.log("=".repeat(60));
129
+ }
49
130
  /**
50
- * Manage production webhooks - view and deploy versions
131
+ * Deploys a specific version of a webhook.
51
132
  */
52
- async function manageProductionWebhooks(context, config) {
133
+ async function deployVersionCore(context, webhook, version) {
134
+ writeProgress(`🔄 Deploying version ${version} of "${webhook.name}"...`);
135
+ const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
136
+ const deployResponse = await webhookApi.publishWebhookVersion(webhook.webhookId, version);
137
+ if (!deployResponse.success) {
138
+ console.error(`❌ Deploy Error: ${deployResponse.error?.message || 'Unknown error'}`);
139
+ return false;
140
+ }
141
+ writeSuccess(`✅ Version ${version} of "${webhook.name}" deployed successfully`);
142
+ writeInfo("💡 The new version is now active for all users.");
143
+ return true;
144
+ }
145
+ /**
146
+ * Activates a webhook.
147
+ */
148
+ async function activateWebhookCore(context, webhook) {
149
+ writeProgress(`🔄 Activating webhook "${webhook.name}"...`);
150
+ const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
151
+ const response = await webhookApi.activateWebhook(webhook.webhookId);
152
+ if (response.success) {
153
+ writeSuccess(`✅ Webhook "${webhook.name}" activated successfully`);
154
+ writeInfo("💡 The webhook is now enabled and can receive requests.");
155
+ return true;
156
+ }
157
+ else {
158
+ console.error(`❌ Failed to activate webhook: ${response.error?.message || 'Unknown error'}`);
159
+ return false;
160
+ }
161
+ }
162
+ /**
163
+ * Deactivates a webhook.
164
+ */
165
+ async function deactivateWebhookCore(context, webhook) {
166
+ writeProgress(`🔄 Deactivating webhook "${webhook.name}"...`);
167
+ const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
168
+ const response = await webhookApi.deactivateWebhook(webhook.webhookId);
169
+ if (response.success) {
170
+ writeSuccess(`✅ Webhook "${webhook.name}" deactivated successfully`);
171
+ writeInfo("💡 The webhook is now disabled and will not receive requests.");
172
+ return true;
173
+ }
174
+ else {
175
+ console.error(`❌ Failed to deactivate webhook: ${response.error?.message || 'Unknown error'}`);
176
+ return false;
177
+ }
178
+ }
179
+ /**
180
+ * Resolves a version string to an actual version, supporting "latest".
181
+ */
182
+ function resolveVersion(versions, versionArg) {
183
+ if (versionArg.toLowerCase() === 'latest') {
184
+ return versions[0].version;
185
+ }
186
+ const exists = versions.some((v) => v.version === versionArg);
187
+ if (!exists) {
188
+ console.error(`❌ Version "${versionArg}" not found`);
189
+ console.log('\nAvailable versions:');
190
+ versions.slice(0, 5).forEach((v) => console.log(` - ${v.version}`));
191
+ return null;
192
+ }
193
+ return versionArg;
194
+ }
195
+ /**
196
+ * Prompts user to select a webhook from a list.
197
+ */
198
+ async function promptWebhookSelection(webhooks, message) {
199
+ const answer = await safePrompt([
200
+ {
201
+ type: 'list',
202
+ name: 'selectedWebhook',
203
+ message,
204
+ choices: webhooks.map((webhook) => ({
205
+ name: `${webhook.name} (${webhook.webhookId})`,
206
+ value: webhook
207
+ }))
208
+ }
209
+ ]);
210
+ return answer?.selectedWebhook || null;
211
+ }
212
+ /**
213
+ * Prompts user to select a version from a list.
214
+ */
215
+ async function promptVersionSelection(versions, activeVersionId) {
216
+ const answer = await safePrompt([
217
+ {
218
+ type: 'list',
219
+ name: 'selectedVersion',
220
+ message: 'Select a version to deploy:',
221
+ choices: versions.map((version) => {
222
+ const isActive = version.webhookId === activeVersionId;
223
+ return {
224
+ name: `Version ${version.version} (${new Date(version.createdAt).toLocaleDateString()})${isActive ? ' ⭐ CURRENT' : ''}`,
225
+ value: version
226
+ };
227
+ })
228
+ }
229
+ ]);
230
+ return answer?.selectedVersion || null;
231
+ }
232
+ // ─────────────────────────────────────────────────────────────────────────────
233
+ // Non-Interactive Mode
234
+ // ─────────────────────────────────────────────────────────────────────────────
235
+ async function executeNonInteractive(context, config, action, options) {
236
+ const validActions = ['view', 'versions', 'deploy', 'activate', 'deactivate'];
237
+ const normalizedAction = action.toLowerCase();
238
+ if (!validActions.includes(normalizedAction)) {
239
+ console.error(`❌ Invalid action: "${action}"`);
240
+ console.log('\nValid actions: view, versions, deploy, activate, deactivate');
241
+ console.log('\nExamples:');
242
+ console.log(' lua webhooks view List all webhooks');
243
+ console.log(' lua webhooks activate -i myWebhook Activate a webhook');
244
+ console.log(' lua webhooks deploy -i myWebhook -v 1.0.3 Deploy specific version');
245
+ process.exit(1);
246
+ }
247
+ const webhooks = config.webhooks || [];
248
+ // View action doesn't require webhook selection
249
+ if (normalizedAction === 'view') {
250
+ if (webhooks.length === 0) {
251
+ console.log("ℹ️ No webhooks found in configuration.");
252
+ return;
253
+ }
254
+ await displayWebhooksCore(context, webhooks);
255
+ return;
256
+ }
257
+ // All other actions require webhook selection
258
+ if (!options.webhookName) {
259
+ console.error(`❌ --webhook-name is required for action "${normalizedAction}"`);
260
+ console.log(`\nUsage: lua webhooks ${normalizedAction} --webhook-name <name>`);
261
+ process.exit(1);
262
+ }
263
+ const selectedWebhook = webhooks.find((w) => w.webhookId === options.webhookName || w.name === options.webhookName);
264
+ if (!selectedWebhook) {
265
+ console.error(`❌ Webhook "${options.webhookName}" not found`);
266
+ console.log('\nAvailable webhooks:');
267
+ webhooks.forEach((w) => console.log(` - ${w.name} (${w.webhookId})`));
268
+ process.exit(1);
269
+ }
270
+ switch (normalizedAction) {
271
+ case 'versions': {
272
+ const data = await fetchVersionsCore(context, selectedWebhook);
273
+ if (!data)
274
+ process.exit(1);
275
+ if (data.versions.length === 0) {
276
+ console.log(`ℹ️ No versions found for ${selectedWebhook.name}.`);
277
+ console.log("💡 Push a version first using 'lua push webhook'.");
278
+ return;
279
+ }
280
+ displayVersionsCore(selectedWebhook, data.versions, data.activeVersionId);
281
+ break;
282
+ }
283
+ case 'deploy': {
284
+ if (!options.webhookVersion) {
285
+ console.error('❌ --webhook-version is required for deploy action');
286
+ console.log('\nUsage: lua webhooks deploy --webhook-name myWebhook --webhook-version 1.0.3');
287
+ console.log(' lua webhooks deploy -i myWebhook -v latest');
288
+ process.exit(1);
289
+ }
290
+ const data = await fetchVersionsCore(context, selectedWebhook);
291
+ if (!data)
292
+ process.exit(1);
293
+ if (data.versions.length === 0) {
294
+ console.error(`❌ No versions found for ${selectedWebhook.name}.`);
295
+ console.log("💡 Push a version first using 'lua push webhook'.");
296
+ process.exit(1);
297
+ }
298
+ const resolvedVersion = resolveVersion(data.versions, options.webhookVersion);
299
+ if (!resolvedVersion)
300
+ process.exit(1);
301
+ const success = await deployVersionCore(context, selectedWebhook, resolvedVersion);
302
+ if (!success)
303
+ process.exit(1);
304
+ break;
305
+ }
306
+ case 'activate': {
307
+ const success = await activateWebhookCore(context, selectedWebhook);
308
+ if (!success)
309
+ process.exit(1);
310
+ break;
311
+ }
312
+ case 'deactivate': {
313
+ const success = await deactivateWebhookCore(context, selectedWebhook);
314
+ if (!success)
315
+ process.exit(1);
316
+ break;
317
+ }
318
+ }
319
+ }
320
+ // ─────────────────────────────────────────────────────────────────────────────
321
+ // Interactive Mode
322
+ // ─────────────────────────────────────────────────────────────────────────────
323
+ async function manageWebhooksInteractive(context, config) {
53
324
  let continueManaging = true;
54
325
  while (continueManaging) {
55
326
  console.log("\n" + "=".repeat(60));
@@ -75,19 +346,19 @@ async function manageProductionWebhooks(context, config) {
75
346
  const { action } = actionAnswer;
76
347
  switch (action) {
77
348
  case 'view':
78
- await viewDeployedWebhooks(context, config);
349
+ await viewWebhooksInteractive(context, config);
79
350
  break;
80
351
  case 'versions':
81
- await viewWebhookVersions(context, config);
352
+ await viewVersionsInteractive(context, config);
82
353
  break;
83
354
  case 'deploy':
84
- await deployWebhookVersion(context, config);
355
+ await deployVersionInteractive(context, config);
85
356
  break;
86
357
  case 'activate':
87
- await activateWebhook(context, config);
358
+ await activateWebhookInteractive(context, config);
88
359
  break;
89
360
  case 'deactivate':
90
- await deactivateWebhook(context, config);
361
+ await deactivateWebhookInteractive(context, config);
91
362
  break;
92
363
  case 'exit':
93
364
  continueManaging = false;
@@ -96,303 +367,112 @@ async function manageProductionWebhooks(context, config) {
96
367
  }
97
368
  }
98
369
  }
99
- /**
100
- * View deployed webhooks in production
101
- */
102
- async function viewDeployedWebhooks(context, config) {
370
+ async function viewWebhooksInteractive(context, config) {
103
371
  writeProgress("🔄 Loading webhook information...");
104
- try {
105
- const webhooks = config.webhooks || [];
106
- if (webhooks.length === 0) {
107
- console.log("\nℹ️ No webhooks found in configuration.\n");
108
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
109
- return;
110
- }
111
- console.log("\n" + "=".repeat(60));
112
- console.log("⚙️ Production Webhooks");
113
- console.log("=".repeat(60) + "\n");
114
- const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
115
- // Fetch version info for each webhook
116
- for (const webhook of webhooks) {
117
- try {
118
- const response = await webhookApi.getWebhookVersions(webhook.webhookId);
119
- if (response.success && response.data) {
120
- const versions = response.data.versions || [];
121
- const activeVersionId = response.data.activeVersionId;
122
- // Find active version
123
- const activeVersion = versions.find((v) => v.webhookId === activeVersionId);
124
- console.log(`🪝 ${webhook.name}`);
125
- console.log(` Webhook ID: ${webhook.webhookId}`);
126
- if (activeVersion) {
127
- console.log(` Deployed Version: ${activeVersion.version} ⭐`);
128
- const date = new Date(activeVersion.createdAt);
129
- console.log(` Deployed: ${date.toLocaleString()}`);
130
- }
131
- else {
132
- console.log(` Deployed Version: Not deployed`);
133
- }
134
- console.log(` Total Versions: ${versions.length}`);
135
- console.log();
136
- }
137
- else {
138
- console.log(`🪝 ${webhook.name}`);
139
- console.log(` Webhook ID: ${webhook.webhookId}`);
140
- console.log(` Status: Unable to fetch version info`);
141
- console.log();
142
- }
143
- }
144
- catch (error) {
145
- console.log(`🪝 ${webhook.name}`);
146
- console.log(` Webhook ID: ${webhook.webhookId}`);
147
- console.log(` Status: Error loading versions`);
148
- console.log();
149
- }
150
- }
151
- console.log("=".repeat(60) + "\n");
152
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
372
+ const webhooks = config.webhooks || [];
373
+ if (webhooks.length === 0) {
374
+ console.log("\nℹ️ No webhooks found in configuration.\n");
153
375
  }
154
- catch (error) {
155
- console.error('❌ Error loading webhook information:', error);
156
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
376
+ else {
377
+ await displayWebhooksCore(context, webhooks);
378
+ console.log();
157
379
  }
380
+ await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
158
381
  }
159
- /**
160
- * View versions for a specific webhook
161
- */
162
- async function viewWebhookVersions(context, config) {
382
+ async function viewVersionsInteractive(context, config) {
163
383
  const webhooks = config.webhooks || [];
164
384
  if (webhooks.length === 0) {
165
385
  console.log("\nℹ️ No webhooks found in configuration.\n");
166
386
  await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
167
387
  return;
168
388
  }
169
- // Prompt to select a webhook
170
- const webhookAnswer = await safePrompt([
171
- {
172
- type: 'list',
173
- name: 'selectedWebhook',
174
- message: 'Select a webhook to view versions:',
175
- choices: webhooks.map((webhook) => ({
176
- name: `${webhook.name} (${webhook.webhookId})`,
177
- value: webhook
178
- }))
179
- }
180
- ]);
181
- if (!webhookAnswer)
389
+ const selectedWebhook = await promptWebhookSelection(webhooks, 'Select a webhook to view versions:');
390
+ if (!selectedWebhook)
182
391
  return;
183
- const selectedWebhook = webhookAnswer.selectedWebhook;
184
392
  writeProgress(`🔄 Loading versions for ${selectedWebhook.name}...`);
185
- try {
186
- const response = await fetch(`${BASE_URLS.API}/developer/webhooks/${context.agentId}/${selectedWebhook.webhookId}/versions`, {
187
- method: 'GET',
188
- headers: {
189
- 'Authorization': `Bearer ${context.apiKey}`,
190
- 'Content-Type': 'application/json'
191
- }
192
- });
193
- if (!response.ok) {
194
- throw new Error(`HTTP error! status: ${response.status}`);
195
- }
196
- const data = await response.json();
197
- const versions = data.data?.versions || data.versions || [];
198
- const activeVersionId = data.data?.activeVersionId || data.activeVersionId;
199
- if (versions.length === 0) {
200
- console.log(`\nℹ️ No versions found for ${selectedWebhook.name}.\n`);
201
- console.log("💡 Push a version first using 'lua push webhook'.\n");
202
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
203
- return;
204
- }
205
- console.log("\n" + "=".repeat(60));
206
- console.log(`📜 Versions for ${selectedWebhook.name}`);
207
- console.log("=".repeat(60) + "\n");
208
- // Sort versions by date (newest first)
209
- const sortedVersions = versions.sort((a, b) => {
210
- const dateA = new Date(a.createdAt).getTime();
211
- const dateB = new Date(b.createdAt).getTime();
212
- return dateB - dateA;
213
- });
214
- sortedVersions.forEach((version, index) => {
215
- const isActive = version.webhookId === activeVersionId;
216
- const date = new Date(version.createdAt);
217
- console.log(`${index + 1}. Version ${version.version}${isActive ? ' ⭐ DEPLOYED' : ''}`);
218
- console.log(` Created: ${date.toLocaleString()}`);
219
- console.log(` Version ID: ${version.webhookId}`);
220
- console.log();
221
- });
222
- console.log("=".repeat(60) + "\n");
393
+ const data = await fetchVersionsCore(context, selectedWebhook);
394
+ if (!data) {
223
395
  await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
396
+ return;
224
397
  }
225
- catch (error) {
226
- console.error('❌ Error loading versions:', error);
227
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
398
+ if (data.versions.length === 0) {
399
+ console.log(`\nℹ️ No versions found for ${selectedWebhook.name}.\n`);
400
+ console.log("💡 Push a version first using 'lua push webhook'.\n");
401
+ }
402
+ else {
403
+ displayVersionsCore(selectedWebhook, data.versions, data.activeVersionId);
404
+ console.log();
228
405
  }
406
+ await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
229
407
  }
230
- /**
231
- * Deploy a webhook version to production
232
- */
233
- async function deployWebhookVersion(context, config) {
408
+ async function deployVersionInteractive(context, config) {
234
409
  const webhooks = config.webhooks || [];
235
410
  if (webhooks.length === 0) {
236
411
  console.log("\nℹ️ No webhooks found in configuration.\n");
237
412
  await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
238
413
  return;
239
414
  }
240
- // Prompt to select a webhook
241
- const webhookAnswer = await safePrompt([
242
- {
243
- type: 'list',
244
- name: 'selectedWebhook',
245
- message: 'Select a webhook to deploy:',
246
- choices: webhooks.map((webhook) => ({
247
- name: `${webhook.name} (${webhook.webhookId})`,
248
- value: webhook
249
- }))
250
- }
251
- ]);
252
- if (!webhookAnswer)
415
+ const selectedWebhook = await promptWebhookSelection(webhooks, 'Select a webhook to deploy:');
416
+ if (!selectedWebhook)
253
417
  return;
254
- const selectedWebhook = webhookAnswer.selectedWebhook;
255
418
  writeProgress(`🔄 Loading versions for ${selectedWebhook.name}...`);
256
- try {
257
- const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
258
- const response = await webhookApi.getWebhookVersions(selectedWebhook.webhookId);
259
- if (!response.success || !response.data) {
260
- throw new Error(response.error?.message || 'Failed to fetch versions');
261
- }
262
- const versions = response.data.versions || [];
263
- const activeVersionId = response.data.activeVersionId;
264
- if (versions.length === 0) {
265
- console.log(`\nℹ️ No versions found for ${selectedWebhook.name}.\n`);
266
- console.log("💡 Push a version first using 'lua push webhook'.\n");
267
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
268
- return;
269
- }
270
- // Sort versions by date (newest first)
271
- const sortedVersions = versions.sort((a, b) => {
272
- const dateA = new Date(a.createdAt).getTime();
273
- const dateB = new Date(b.createdAt).getTime();
274
- return dateB - dateA;
275
- });
276
- // Prompt to select a version
277
- const versionAnswer = await safePrompt([
278
- {
279
- type: 'list',
280
- name: 'selectedVersion',
281
- message: 'Select a version to deploy:',
282
- choices: sortedVersions.map((version) => {
283
- const isActive = version.webhookId === activeVersionId;
284
- const date = new Date(version.createdAt);
285
- return {
286
- name: `Version ${version.version} (${date.toLocaleDateString()})${isActive ? ' ⭐ CURRENT' : ''}`,
287
- value: version
288
- };
289
- })
290
- }
291
- ]);
292
- if (!versionAnswer)
293
- return;
294
- const selectedVersion = versionAnswer.selectedVersion;
295
- // Show warning
296
- console.log("\n⚠️ WARNING: You are about to deploy to PRODUCTION!");
297
- console.log("⚠️ This will affect ALL users immediately.\n");
298
- console.log(`Webhook: ${selectedWebhook.name}`);
299
- console.log(`Version: ${selectedVersion.version}\n`);
300
- const confirmAnswer = await safePrompt([
301
- {
302
- type: 'confirm',
303
- name: 'confirm',
304
- message: 'Are you absolutely sure you want to deploy this version?',
305
- default: false
306
- }
307
- ]);
308
- if (!confirmAnswer || !confirmAnswer.confirm) {
309
- console.log("\n❌ Deployment cancelled.\n");
310
- return;
311
- }
312
- writeProgress("🔄 Deploying version...");
313
- // Reuse the same webhookApi instance
314
- const deployResponse = await webhookApi.publishWebhookVersion(selectedWebhook.webhookId, selectedVersion.version);
315
- if (!deployResponse.success) {
316
- console.error(`\n❌ Deploy Error: ${deployResponse.error?.message || 'Unknown error'}\n`);
317
- throw new Error(deployResponse.error?.message || 'Failed to publish webhook version');
318
- }
319
- writeSuccess(`\n✅ Version ${selectedVersion.version} of "${selectedWebhook.name}" deployed successfully to production\n`);
320
- writeInfo("💡 The new version is now active for all users.");
419
+ const data = await fetchVersionsCore(context, selectedWebhook);
420
+ if (!data) {
321
421
  await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
422
+ return;
322
423
  }
323
- catch (error) {
324
- console.error('\n Error deploying version:', error);
325
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
326
- }
327
- }
328
- /**
329
- * Activate a webhook
330
- */
331
- async function activateWebhook(context, config) {
332
- const webhooks = config.webhooks || [];
333
- if (webhooks.length === 0) {
334
- console.log("\nℹ️ No webhooks found in configuration.\n");
424
+ if (data.versions.length === 0) {
425
+ console.log(`\nℹ️ No versions found for ${selectedWebhook.name}.\n`);
426
+ console.log("💡 Push a version first using 'lua push webhook'.\n");
335
427
  await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
336
428
  return;
337
429
  }
338
- // Prompt to select a webhook
339
- const webhookAnswer = await safePrompt([
430
+ const selectedVersion = await promptVersionSelection(data.versions, data.activeVersionId);
431
+ if (!selectedVersion)
432
+ return;
433
+ // Show warning and confirm
434
+ console.log("\n⚠️ WARNING: You are about to deploy to PRODUCTION!");
435
+ console.log("⚠️ This will affect ALL users immediately.\n");
436
+ console.log(`Webhook: ${selectedWebhook.name}`);
437
+ console.log(`Version: ${selectedVersion.version}\n`);
438
+ const confirmAnswer = await safePrompt([
340
439
  {
341
- type: 'list',
342
- name: 'selectedWebhook',
343
- message: 'Select a webhook to activate:',
344
- choices: webhooks.map((webhook) => ({
345
- name: `${webhook.name} (${webhook.webhookId})`,
346
- value: webhook
347
- }))
440
+ type: 'confirm',
441
+ name: 'confirm',
442
+ message: 'Are you absolutely sure you want to deploy this version?',
443
+ default: false
348
444
  }
349
445
  ]);
350
- if (!webhookAnswer)
446
+ if (!confirmAnswer || !confirmAnswer.confirm) {
447
+ console.log("\n❌ Deployment cancelled.\n");
351
448
  return;
352
- const selectedWebhook = webhookAnswer.selectedWebhook;
353
- writeProgress(`🔄 Activating webhook "${selectedWebhook.name}"...`);
354
- try {
355
- const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
356
- const response = await webhookApi.activateWebhook(selectedWebhook.webhookId);
357
- if (!response.success) {
358
- console.error(`\n❌ Error: ${response.error?.message || 'Unknown error'}\n`);
359
- throw new Error(response.error?.message || 'Failed to activate webhook');
360
- }
361
- writeSuccess(`\n✅ Webhook "${selectedWebhook.name}" activated successfully\n`);
362
- writeInfo("💡 The webhook is now enabled and can receive requests.");
363
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
364
449
  }
365
- catch (error) {
366
- console.error('\n❌ Error activating webhook:', error);
450
+ await deployVersionCore(context, selectedWebhook, selectedVersion.version);
451
+ await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
452
+ }
453
+ async function activateWebhookInteractive(context, config) {
454
+ const webhooks = config.webhooks || [];
455
+ if (webhooks.length === 0) {
456
+ console.log("\nℹ️ No webhooks found in configuration.\n");
367
457
  await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
458
+ return;
368
459
  }
460
+ const selectedWebhook = await promptWebhookSelection(webhooks, 'Select a webhook to activate:');
461
+ if (!selectedWebhook)
462
+ return;
463
+ await activateWebhookCore(context, selectedWebhook);
464
+ await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
369
465
  }
370
- /**
371
- * Deactivate a webhook
372
- */
373
- async function deactivateWebhook(context, config) {
466
+ async function deactivateWebhookInteractive(context, config) {
374
467
  const webhooks = config.webhooks || [];
375
468
  if (webhooks.length === 0) {
376
469
  console.log("\nℹ️ No webhooks found in configuration.\n");
377
470
  await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
378
471
  return;
379
472
  }
380
- // Prompt to select a webhook
381
- const webhookAnswer = await safePrompt([
382
- {
383
- type: 'list',
384
- name: 'selectedWebhook',
385
- message: 'Select a webhook to deactivate:',
386
- choices: webhooks.map((webhook) => ({
387
- name: `${webhook.name} (${webhook.webhookId})`,
388
- value: webhook
389
- }))
390
- }
391
- ]);
392
- if (!webhookAnswer)
473
+ const selectedWebhook = await promptWebhookSelection(webhooks, 'Select a webhook to deactivate:');
474
+ if (!selectedWebhook)
393
475
  return;
394
- const selectedWebhook = webhookAnswer.selectedWebhook;
395
- // Confirm deactivation
396
476
  const confirmAnswer = await safePrompt([
397
477
  {
398
478
  type: 'confirm',
@@ -405,21 +485,7 @@ async function deactivateWebhook(context, config) {
405
485
  console.log("\n❌ Deactivation cancelled.\n");
406
486
  return;
407
487
  }
408
- writeProgress(`🔄 Deactivating webhook "${selectedWebhook.name}"...`);
409
- try {
410
- const webhookApi = new WebhookApi(BASE_URLS.API, context.apiKey, context.agentId);
411
- const response = await webhookApi.deactivateWebhook(selectedWebhook.webhookId);
412
- if (!response.success) {
413
- console.error(`\n❌ Error: ${response.error?.message || 'Unknown error'}\n`);
414
- throw new Error(response.error?.message || 'Failed to deactivate webhook');
415
- }
416
- writeSuccess(`\n✅ Webhook "${selectedWebhook.name}" deactivated successfully\n`);
417
- writeInfo("💡 The webhook is now disabled and will not receive requests.");
418
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
419
- }
420
- catch (error) {
421
- console.error('\n❌ Error deactivating webhook:', error);
422
- await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
423
- }
488
+ await deactivateWebhookCore(context, selectedWebhook);
489
+ await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
424
490
  }
425
491
  //# sourceMappingURL=webhooks.js.map