lua-cli 2.5.7 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/api/agent.api.service.d.ts +45 -0
  2. package/dist/api/agent.api.service.js +54 -0
  3. package/dist/api/job.api.service.d.ts +210 -0
  4. package/dist/api/job.api.service.js +200 -0
  5. package/dist/api/lazy-instances.d.ts +24 -0
  6. package/dist/api/lazy-instances.js +48 -0
  7. package/dist/api/postprocessor.api.service.d.ts +98 -0
  8. package/dist/api/postprocessor.api.service.js +76 -0
  9. package/dist/api/preprocessor.api.service.d.ts +98 -0
  10. package/dist/api/preprocessor.api.service.js +76 -0
  11. package/dist/api/user.data.api.service.d.ts +28 -0
  12. package/dist/api/user.data.api.service.js +51 -0
  13. package/dist/api/webhook.api.service.d.ts +151 -0
  14. package/dist/api/webhook.api.service.js +134 -0
  15. package/dist/api-exports.d.ts +156 -41
  16. package/dist/api-exports.js +182 -21
  17. package/dist/cli/command-definitions.js +149 -7
  18. package/dist/commands/compile.js +124 -5
  19. package/dist/commands/completion.d.ts +11 -0
  20. package/dist/commands/completion.js +209 -0
  21. package/dist/commands/env.d.ts +3 -2
  22. package/dist/commands/env.js +42 -17
  23. package/dist/commands/features.d.ts +16 -0
  24. package/dist/commands/features.js +352 -0
  25. package/dist/commands/index.d.ts +7 -0
  26. package/dist/commands/index.js +7 -0
  27. package/dist/commands/init.js +53 -7
  28. package/dist/commands/jobs.d.ts +20 -0
  29. package/dist/commands/jobs.js +533 -0
  30. package/dist/commands/logs.js +2 -5
  31. package/dist/commands/persona.d.ts +3 -2
  32. package/dist/commands/persona.js +43 -18
  33. package/dist/commands/postprocessors.d.ts +8 -0
  34. package/dist/commands/postprocessors.js +431 -0
  35. package/dist/commands/preprocessors.d.ts +8 -0
  36. package/dist/commands/preprocessors.js +431 -0
  37. package/dist/commands/push.d.ts +9 -13
  38. package/dist/commands/push.js +937 -69
  39. package/dist/commands/skills.d.ts +16 -0
  40. package/dist/commands/skills.js +438 -0
  41. package/dist/commands/test.d.ts +9 -18
  42. package/dist/commands/test.js +558 -82
  43. package/dist/commands/webhooks.d.ts +18 -0
  44. package/dist/commands/webhooks.js +424 -0
  45. package/dist/common/data.entry.instance.d.ts +7 -0
  46. package/dist/common/data.entry.instance.js +15 -0
  47. package/dist/common/job.instance.d.ts +77 -0
  48. package/dist/common/job.instance.js +108 -0
  49. package/dist/common/order.instance.d.ts +6 -0
  50. package/dist/common/order.instance.js +14 -0
  51. package/dist/common/product.instance.d.ts +6 -0
  52. package/dist/common/product.instance.js +14 -0
  53. package/dist/common/user.instance.d.ts +15 -0
  54. package/dist/common/user.instance.js +38 -0
  55. package/dist/config/constants.d.ts +2 -2
  56. package/dist/config/constants.js +4 -4
  57. package/dist/index.js +14 -3
  58. package/dist/interfaces/agent.d.ts +33 -1
  59. package/dist/interfaces/chat.d.ts +22 -0
  60. package/dist/interfaces/index.d.ts +10 -0
  61. package/dist/interfaces/index.js +7 -0
  62. package/dist/interfaces/jobs.d.ts +172 -0
  63. package/dist/interfaces/jobs.js +5 -0
  64. package/dist/interfaces/message.d.ts +18 -0
  65. package/dist/interfaces/message.js +1 -0
  66. package/dist/interfaces/postprocessors.d.ts +35 -0
  67. package/dist/interfaces/postprocessors.js +4 -0
  68. package/dist/interfaces/preprocessors.d.ts +35 -0
  69. package/dist/interfaces/preprocessors.js +4 -0
  70. package/dist/interfaces/webhooks.d.ts +104 -0
  71. package/dist/interfaces/webhooks.js +5 -0
  72. package/dist/types/api-contracts.d.ts +14 -0
  73. package/dist/types/api-contracts.js +0 -7
  74. package/dist/types/compile.types.d.ts +49 -0
  75. package/dist/types/index.d.ts +1 -1
  76. package/dist/types/index.js +1 -1
  77. package/dist/types/skill.d.ts +502 -0
  78. package/dist/types/skill.js +477 -0
  79. package/dist/utils/agent-management.d.ts +25 -0
  80. package/dist/utils/agent-management.js +67 -0
  81. package/dist/utils/bundling.d.ts +31 -1
  82. package/dist/utils/bundling.js +653 -10
  83. package/dist/utils/compile.d.ts +63 -0
  84. package/dist/utils/compile.js +691 -36
  85. package/dist/utils/deployment.d.ts +2 -1
  86. package/dist/utils/deployment.js +16 -2
  87. package/dist/utils/init-agent.d.ts +3 -1
  88. package/dist/utils/init-agent.js +6 -4
  89. package/dist/utils/init-prompts.d.ts +2 -1
  90. package/dist/utils/init-prompts.js +14 -9
  91. package/dist/utils/job-management.d.ts +24 -0
  92. package/dist/utils/job-management.js +264 -0
  93. package/dist/utils/postprocessor-management.d.ts +9 -0
  94. package/dist/utils/postprocessor-management.js +118 -0
  95. package/dist/utils/preprocessor-management.d.ts +9 -0
  96. package/dist/utils/preprocessor-management.js +118 -0
  97. package/dist/utils/sandbox.d.ts +61 -1
  98. package/dist/utils/sandbox.js +283 -72
  99. package/dist/utils/tool-detection.d.ts +3 -2
  100. package/dist/utils/tool-detection.js +18 -4
  101. package/dist/utils/webhook-management.d.ts +24 -0
  102. package/dist/utils/webhook-management.js +256 -0
  103. package/dist/web/app.css +152 -736
  104. package/dist/web/app.js +45 -45
  105. package/package.json +2 -2
  106. package/template/AGENT_CONFIGURATION.md +251 -0
  107. package/template/COMPLEX_JOB_EXAMPLES.md +795 -0
  108. package/template/DYNAMIC_JOB_CREATION.md +371 -0
  109. package/template/README.md +30 -2
  110. package/template/WEBHOOKS_JOBS_QUICKSTART.md +318 -0
  111. package/template/WEBHOOK_JOB_EXAMPLES.md +817 -0
  112. package/template/package.json +1 -1
  113. package/template/src/index-agent-example.ts +201 -0
  114. package/template/src/index.ts +39 -0
  115. package/template/src/jobs/AbandonedBasketProcessorJob.ts +139 -0
  116. package/template/src/jobs/DailyCleanupJob.ts +100 -0
  117. package/template/src/jobs/DataMigrationJob.ts +133 -0
  118. package/template/src/jobs/HealthCheckJob.ts +87 -0
  119. package/template/src/postprocessors/ResponseFormatter.ts +151 -0
  120. package/template/src/preprocessors/MessageFilter.ts +91 -0
  121. package/template/src/tools/GameScoreTrackerTool.ts +356 -0
  122. package/template/src/tools/SmartBasketTool.ts +188 -0
  123. package/template/src/webhooks/PaymentWebhook.ts +113 -0
  124. package/template/src/webhooks/UserEventWebhook.ts +77 -0
@@ -26,17 +26,11 @@
26
26
  * const products = await Products.search('laptop');
27
27
  * ```
28
28
  */
29
- import { LuaSkill, env } from "./types/skill.js";
29
+ import { LuaSkill, LuaWebhook, LuaJob, PreProcessor, PostProcessor, LuaAgent, env } from "./types/skill.js";
30
30
  import { BasketStatus } from "./interfaces/baskets.js";
31
31
  import { OrderStatus } from "./interfaces/orders.js";
32
- import { getUserInstance, getDataInstance, getProductsInstance, getBasketsInstance, getOrderInstance, } from "./api/lazy-instances.js";
33
- // ============================================================================
34
- // USER DATA API
35
- // ============================================================================
36
- /**
37
- * User Data API
38
- * Access user information and preferences
39
- */
32
+ import { getUserInstance, getDataInstance, getProductsInstance, getBasketsInstance, getOrderInstance, getJobInstance, getChatInstance, } from "./api/lazy-instances.js";
33
+ import { JobInstance } from "./common/job.instance.js";
40
34
  export const User = {
41
35
  /**
42
36
  * Retrieves current user data.
@@ -46,6 +40,24 @@ export const User = {
46
40
  async get() {
47
41
  const instance = await getUserInstance();
48
42
  return instance.get();
43
+ },
44
+ /**
45
+ * Gets the chat history for the current user.
46
+ *
47
+ * @returns Promise resolving to array of chat messages
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const history = await User.getChatHistory();
52
+ * // Returns: [
53
+ * // { role: 'user', content: [{type: 'text', text: 'hello'}], createdAt: '...', id: '...', threadId: '...' },
54
+ * // { role: 'assistant', content: [{type: 'text', text: 'hi'}], createdAt: '...', id: '...', threadId: '...' }
55
+ * // ]
56
+ * ```
57
+ */
58
+ async getChatHistory() {
59
+ const instance = await getUserInstance();
60
+ return instance.getChatHistory();
49
61
  }
50
62
  };
51
63
  // ============================================================================
@@ -158,17 +170,6 @@ export const Products = {
158
170
  const instance = await getProductsInstance();
159
171
  return instance.create(product);
160
172
  },
161
- /**
162
- * Updates an existing product.
163
- *
164
- * @param data - Updated product data
165
- * @param id - Product ID
166
- * @returns Promise resolving to updated product
167
- */
168
- async update(data, id) {
169
- const instance = await getProductsInstance();
170
- return instance.update(data, id);
171
- },
172
173
  /**
173
174
  * Deletes a product.
174
175
  *
@@ -366,7 +367,167 @@ export const Orders = {
366
367
  }
367
368
  };
368
369
  // ============================================================================
370
+ // JOBS API
371
+ // ============================================================================
372
+ /**
373
+ * Jobs API
374
+ * Manage and trigger scheduled jobs from within your tools
375
+ */
376
+ export const Jobs = {
377
+ /**
378
+ * Creates a new job dynamically from within a tool.
379
+ * This allows tools to schedule one-time or recurring jobs programmatically.
380
+ *
381
+ * @param config - Job configuration
382
+ * @param config.name - Unique job name
383
+ * @param config.description - Job description
384
+ * @param config.schedule - Schedule configuration (cron, once, or interval)
385
+ * @param config.execute - Async function to execute
386
+ * @param config.timeout - Optional timeout in seconds
387
+ * @param config.retry - Optional retry configuration
388
+ * @returns Promise resolving to created job details
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * // Create a one-time job to check basket in 3 hours
393
+ * await Jobs.create({
394
+ * name: `check-basket-${basketId}`,
395
+ * description: 'Check if basket was abandoned',
396
+ * schedule: {
397
+ * type: 'once',
398
+ * executeAt: new Date(Date.now() + 3 * 60 * 60 * 1000)
399
+ * },
400
+ * execute: async () => {
401
+ * const basket = await Baskets.getById(basketId);
402
+ * if (basket.status === 'active') {
403
+ * // Send reminder
404
+ * }
405
+ * return { checked: true };
406
+ * }
407
+ * });
408
+ * ```
409
+ */
410
+ async create(config) {
411
+ const instance = await getJobInstance();
412
+ // Convert the execute function to a string
413
+ const executeString = config.execute.toString();
414
+ // Step 1: Create the job
415
+ const createResult = await instance.createJobInstance({
416
+ name: config.name,
417
+ description: config.description,
418
+ context: config.description || '',
419
+ schedule: config.schedule,
420
+ timeout: config.timeout,
421
+ retry: config.retry,
422
+ metadata: config.metadata
423
+ });
424
+ const jobId = createResult.jobId;
425
+ // Step 2: Push the initial version with execute function
426
+ const pushResult = await instance.pushJob(jobId, {
427
+ name: config.name,
428
+ version: '1.0.0',
429
+ description: config.description,
430
+ context: config.description || '',
431
+ jobId: jobId,
432
+ schedule: config.schedule,
433
+ timeout: config.timeout,
434
+ retry: config.retry,
435
+ executeFunction: executeString,
436
+ metadata: config.metadata
437
+ });
438
+ if (!pushResult.success) {
439
+ throw new Error(`Failed to push job version: ${pushResult.error?.message}`);
440
+ }
441
+ // Step 3: Activate the job so it starts running
442
+ const activateResult = await instance.activateJob(jobId);
443
+ if (!activateResult.success) {
444
+ console.warn(`Job created but activation failed: ${activateResult.error?.message}`);
445
+ }
446
+ // Step 4: Return a JobInstance for easy manipulation
447
+ return new JobInstance(instance, {
448
+ id: jobId,
449
+ jobId: jobId,
450
+ name: config.name,
451
+ schedule: config.schedule,
452
+ metadata: config.metadata || {},
453
+ active: activateResult.success
454
+ });
455
+ },
456
+ /**
457
+ * Retrieves a job by its unique identifier
458
+ * @param jobId - The unique identifier of the job to retrieve
459
+ * @returns Promise resolving to an JobInstance representing the job
460
+ * @throws Error if the job is not found or the request fails
461
+ */
462
+ async getJob(jobId) {
463
+ const instance = await getJobInstance();
464
+ return instance.getJob(jobId);
465
+ }
466
+ };
467
+ // ============================================================================
468
+ // AI GENERATION API
469
+ // ============================================================================
470
+ /**
471
+ * AI API
472
+ * Generate AI responses with custom context
473
+ */
474
+ export const AI = {
475
+ /**
476
+ * Generates an AI response with custom runtime context.
477
+ *
478
+ * @param context - Runtime context to provide to the AI
479
+ * @param messages - Array of messages (text, image, file, etc.)
480
+ * @param agentId - Optional agent ID to use (defaults to current agent)
481
+ * @returns Promise resolving to AI response text
482
+ *
483
+ * @example
484
+ * ```typescript
485
+ * // Simple text message with current agent
486
+ * const response = await AI.generate(
487
+ * 'You are a helpful sales assistant for our e-commerce store.',
488
+ * [{ type: 'text', text: 'What products do you recommend for beginners?' }]
489
+ * );
490
+ * console.log(response); // AI-generated recommendation
491
+ *
492
+ * // Multiple messages with images
493
+ * const response2 = await AI.generate(
494
+ * 'You are an image analysis expert.',
495
+ * [
496
+ * { type: 'text', text: 'What do you see in this image?' },
497
+ * { type: 'image', url: 'https://example.com/image.jpg' }
498
+ * ]
499
+ * );
500
+ *
501
+ * // Use a different agent
502
+ * const response3 = await AI.generate(
503
+ * 'You are a specialized assistant.',
504
+ * [{ type: 'text', text: 'Help me with this task' }],
505
+ * 'agent_different_123'
506
+ * );
507
+ * ```
508
+ */
509
+ async generate(context, messages, agentId) {
510
+ const chatInstance = await getChatInstance();
511
+ const { getCredentials } = await import('./api/credentials.js');
512
+ const credentials = await getCredentials();
513
+ // Use provided agentId or default to current agent
514
+ const targetAgentId = agentId || 'luaAgent';
515
+ const result = await chatInstance.sendMessage(targetAgentId, {
516
+ messages,
517
+ navigate: false,
518
+ skillOverride: [],
519
+ runtimeContext: context
520
+ });
521
+ if (!result.success) {
522
+ throw new Error(result.error?.message || 'AI generation failed');
523
+ }
524
+ return result.data?.text || '';
525
+ }
526
+ };
527
+ // ============================================================================
369
528
  // EXPORTS
370
529
  // ============================================================================
371
530
  // Export skill classes and utilities
372
- export { LuaSkill, BasketStatus, OrderStatus, env };
531
+ export { LuaSkill, LuaWebhook, LuaJob, PreProcessor, PostProcessor, LuaAgent, BasketStatus, OrderStatus, env };
532
+ // Export instance classes
533
+ export { JobInstance };
@@ -2,7 +2,7 @@
2
2
  * Command Definitions
3
3
  * Centralized command structure for the CLI
4
4
  */
5
- import { configureCommand, initCommand, destroyCommand, apiKeyCommand, compileCommand, testCommand, pushCommand, deployCommand, chatCommand, chatClearCommand, envCommand, personaCommand, productionCommand, resourcesCommand, adminCommand, docsCommand, channelsCommand, logsCommand } from "../commands/index.js";
5
+ import { configureCommand, initCommand, destroyCommand, apiKeyCommand, compileCommand, testCommand, pushCommand, deployCommand, chatCommand, chatClearCommand, envCommand, personaCommand, productionCommand, resourcesCommand, adminCommand, docsCommand, channelsCommand, logsCommand, completionCommand, skillsCommand, webhooksCommand, jobsCommand, featuresCommand, preprocessorsCommand, postprocessorsCommand } from "../commands/index.js";
6
6
  /**
7
7
  * Sets up authentication-related commands.
8
8
  *
@@ -53,13 +53,34 @@ export function setupSkillCommands(program) {
53
53
  .description("đŸ“Ļ Compile skill to deployable format")
54
54
  .action(compileCommand);
55
55
  program
56
- .command("test")
57
- .description("đŸ§Ē Test skill tools interactively")
56
+ .command("test [type]")
57
+ .description("đŸ§Ē Test skills, webhooks, or jobs interactively")
58
+ .addHelpText('after', `
59
+ Arguments:
60
+ type Optional: 'skill', 'webhook', or 'job' (prompts if not provided)
61
+
62
+ Examples:
63
+ $ lua test Interactive selection
64
+ $ lua test skill Test a skill/tool directly
65
+ $ lua test webhook Test a webhook with query/headers/body
66
+ $ lua test job Test a job by executing it
67
+ `)
58
68
  .action(testCommand);
59
69
  // Deployment Commands
60
70
  program
61
- .command("push")
62
- .description("â˜ī¸ Push skill version to server")
71
+ .command("push [type]")
72
+ .description("â˜ī¸ Push skill, webhook, job, or persona version to server")
73
+ .addHelpText('after', `
74
+ Arguments:
75
+ type Optional: 'skill', 'webhook', 'job', or 'persona' (prompts if not provided)
76
+
77
+ Examples:
78
+ $ lua push Interactive selection
79
+ $ lua push skill Push a skill directly
80
+ $ lua push webhook Push a webhook directly
81
+ $ lua push job Push a job directly
82
+ $ lua push persona Push a persona directly
83
+ `)
63
84
  .action(pushCommand);
64
85
  program
65
86
  .command("deploy")
@@ -86,12 +107,32 @@ Examples:
86
107
  .action(chatClearCommand);
87
108
  // Configuration Commands
88
109
  program
89
- .command("env")
110
+ .command("env [environment]")
90
111
  .description("âš™ī¸ Manage environment variables")
112
+ .addHelpText('after', `
113
+ Arguments:
114
+ environment Optional: 'sandbox', 'staging', or 'production' (prompts if not provided)
115
+
116
+ Examples:
117
+ $ lua env Interactive selection
118
+ $ lua env sandbox Manage sandbox env vars directly
119
+ $ lua env staging Manage staging env vars (alias for sandbox)
120
+ $ lua env production Manage production env vars directly
121
+ `)
91
122
  .action(envCommand);
92
123
  program
93
- .command("persona")
124
+ .command("persona [env]")
94
125
  .description("🤖 Manage agent persona")
126
+ .addHelpText('after', `
127
+ Arguments:
128
+ env Optional: 'sandbox', 'staging', or 'production' (prompts if not provided)
129
+
130
+ Examples:
131
+ $ lua persona Interactive selection
132
+ $ lua persona sandbox Manage sandbox persona directly
133
+ $ lua persona staging Manage staging persona (alias for sandbox)
134
+ $ lua persona production Manage production persona directly
135
+ `)
95
136
  .action(personaCommand);
96
137
  program
97
138
  .command("production")
@@ -117,4 +158,105 @@ Examples:
117
158
  .command("logs")
118
159
  .description("📊 View agent and skill logs")
119
160
  .action(logsCommand);
161
+ program
162
+ .command("skills [env]")
163
+ .description("âš™ī¸ Manage and view skills")
164
+ .addHelpText('after', `
165
+ Arguments:
166
+ env Optional: 'sandbox', 'staging', or 'production' (prompts if not provided)
167
+
168
+ Examples:
169
+ $ lua skills Interactive selection
170
+ $ lua skills sandbox View sandbox skills directly
171
+ $ lua skills staging View staging skills (alias for sandbox)
172
+ $ lua skills production Manage production skills directly
173
+ `)
174
+ .action(skillsCommand);
175
+ program
176
+ .command("webhooks [env]")
177
+ .description("đŸĒ Manage and view webhooks")
178
+ .addHelpText('after', `
179
+ Arguments:
180
+ env Optional: 'sandbox', 'staging', or 'production' (prompts if not provided)
181
+
182
+ Examples:
183
+ $ lua webhooks Interactive selection
184
+ $ lua webhooks sandbox View sandbox webhooks directly
185
+ $ lua webhooks staging View staging webhooks (alias for sandbox)
186
+ $ lua webhooks production Manage production webhooks directly
187
+ `)
188
+ .action(webhooksCommand);
189
+ program
190
+ .command("jobs [env]")
191
+ .description("⏰ Manage and view scheduled jobs")
192
+ .addHelpText('after', `
193
+ Arguments:
194
+ env Optional: 'sandbox', 'staging', or 'production' (prompts if not provided)
195
+
196
+ Examples:
197
+ $ lua jobs Interactive selection
198
+ $ lua jobs sandbox View sandbox jobs directly
199
+ $ lua jobs staging View staging jobs (alias for sandbox)
200
+ $ lua jobs production Manage production jobs (pause/resume/trigger)
201
+ `)
202
+ .action(jobsCommand);
203
+ program
204
+ .command("features")
205
+ .description("đŸŽ¯ Manage agent features (tickets, RAG, etc.)")
206
+ .addHelpText('after', `
207
+ Features:
208
+ â€ĸ View all available features
209
+ â€ĸ Enable/disable features
210
+ â€ĸ Update feature context and instructions
211
+ â€ĸ Manage capabilities like tickets, RAG search, web search, and more
212
+
213
+ Examples:
214
+ $ lua features View and manage all agent features
215
+ `)
216
+ .action(featuresCommand);
217
+ program
218
+ .command("preprocessors")
219
+ .description("đŸ“Ĩ Manage message preprocessors")
220
+ .addHelpText('after', `
221
+ Features:
222
+ â€ĸ View deployed preprocessors
223
+ â€ĸ View preprocessor versions
224
+ â€ĸ Deploy versions to production
225
+ â€ĸ Activate/deactivate preprocessors
226
+ â€ĸ Delete preprocessors
227
+
228
+ Examples:
229
+ $ lua preprocessors Manage production preprocessors
230
+ `)
231
+ .action(preprocessorsCommand);
232
+ program
233
+ .command("postprocessors")
234
+ .description("📤 Manage response postprocessors")
235
+ .addHelpText('after', `
236
+ Features:
237
+ â€ĸ View deployed postprocessors
238
+ â€ĸ View postprocessor versions
239
+ â€ĸ Deploy versions to production
240
+ â€ĸ Activate/deactivate postprocessors
241
+ â€ĸ Delete postprocessors
242
+
243
+ Examples:
244
+ $ lua postprocessors Manage production postprocessors
245
+ `)
246
+ .action(postprocessorsCommand);
247
+ program
248
+ .command("completion [shell]")
249
+ .description("đŸŽ¯ Generate shell completion script")
250
+ .addHelpText('after', `
251
+ Arguments:
252
+ shell Optional: 'bash', 'zsh', or 'fish' (shows instructions if not provided)
253
+
254
+ Examples:
255
+ $ lua completion Show installation instructions
256
+ $ lua completion bash Generate bash completion script
257
+ $ lua completion bash >> ~/.bashrc
258
+ $ lua completion zsh >> ~/.zshrc
259
+ $ lua completion fish > ~/.config/fish/completions/lua.fish
260
+ `)
261
+ .action(completionCommand);
120
262
  }
@@ -6,13 +6,18 @@ import fs from "fs";
6
6
  import path from "path";
7
7
  import { Project } from "ts-morph";
8
8
  import { withErrorHandling, writeProgress, writeSuccess } from "../utils/cli.js";
9
- import { findIndexFile } from '../utils/compile.js';
9
+ import { findIndexFile, extractWebhooksMetadata, extractJobsMetadata, extractPreProcessorsMetadata, extractPostProcessorsMetadata } from '../utils/compile.js';
10
10
  import { detectTools } from '../utils/tool-detection.js';
11
- import { bundleTool, bundleMainIndex, extractExecuteCode } from '../utils/bundling.js';
11
+ import { bundleTool, bundleMainIndex, extractExecuteCode, bundleWebhook, bundleJob, bundlePreProcessor, bundlePostProcessor } from '../utils/bundling.js';
12
12
  import { createDeploymentData, createLegacyDeploymentData } from '../utils/deployment.js';
13
13
  import { syncYamlWithDeployJson, syncServerSkillsWithYaml } from '../utils/skill-management.js';
14
+ import { ensureWebhooksExistInYaml, syncServerWebhooksWithYaml } from '../utils/webhook-management.js';
15
+ import { ensureJobsExistInYaml, syncServerJobsWithYaml } from '../utils/job-management.js';
16
+ import { ensurePreProcessorsExistInYaml, syncServerPreProcessorsWithYaml } from '../utils/preprocessor-management.js';
17
+ import { ensurePostProcessorsExistInYaml, syncServerPostProcessorsWithYaml } from '../utils/postprocessor-management.js';
14
18
  import { readSkillConfig } from '../utils/files.js';
15
19
  import { COMPILE_DIRS, COMPILE_FILES } from '../config/compile.constants.js';
20
+ import { syncAgentPersonaWithYaml } from '../utils/agent-management.js';
16
21
  /**
17
22
  * Main compile command - orchestrates the entire skill compilation process.
18
23
  *
@@ -49,7 +54,28 @@ export async function compileCommand() {
49
54
  const indexPath = findIndexFile();
50
55
  const project = createTypeScriptProject();
51
56
  const indexFile = project.addSourceFileAtPath(indexPath);
52
- const tools = await detectTools(indexFile, project);
57
+ // Step 2a: Check for LuaAgent (unified agent configuration)
58
+ writeProgress("🔍 Checking for LuaAgent configuration...");
59
+ const { extractLuaAgentMetadata, resolveLuaAgentReferences, getSkillFilePaths } = await import('../utils/compile.js');
60
+ const agentMetadata = extractLuaAgentMetadata(indexFile);
61
+ let skillFilePaths = [];
62
+ let resolvedAgentData = null;
63
+ if (agentMetadata) {
64
+ writeProgress(`✨ Found LuaAgent: ${agentMetadata.name}`);
65
+ writeProgress(` Using new unified agent configuration approach`);
66
+ // Sync persona and welcome message with YAML
67
+ await syncAgentPersonaWithYaml(agentMetadata);
68
+ // Resolve references to get actual metadata for all components
69
+ resolvedAgentData = resolveLuaAgentReferences(agentMetadata, indexFile, project);
70
+ // Get file paths where skills are defined so we can scan them for tools
71
+ skillFilePaths = getSkillFilePaths(agentMetadata, indexFile);
72
+ writeProgress(`đŸ“Ļ Agent contains: ${resolvedAgentData.skills.length} skill(s), ${resolvedAgentData.webhooks.length} webhook(s), ${resolvedAgentData.jobs.length} job(s), ${resolvedAgentData.preProcessors.length} preprocessor(s), ${resolvedAgentData.postProcessors.length} postprocessor(s)`);
73
+ }
74
+ else {
75
+ writeProgress(`â„šī¸ No LuaAgent found, using legacy detection for individual components`);
76
+ }
77
+ // Step 2b: Detect tools from index file and skill files
78
+ const tools = await detectTools(indexFile, project, skillFilePaths);
53
79
  writeProgress(`đŸ“Ļ Found ${tools.length} tools to bundle...`);
54
80
  // Step 3: Bundle each tool and extract metadata
55
81
  for (const tool of tools) {
@@ -60,7 +86,7 @@ export async function compileCommand() {
60
86
  await bundleMainIndex(indexPath, distDir);
61
87
  // Step 5: Create deployment data in both formats
62
88
  await createDeploymentData(tools, distDir);
63
- await createLegacyDeploymentData(tools, luaDir, indexFile);
89
+ await createLegacyDeploymentData(tools, luaDir, indexFile, resolvedAgentData);
64
90
  // Step 6: Sync YAML with deploy.json
65
91
  writeProgress("🔄 Syncing YAML with deploy.json...");
66
92
  const deployJsonPath = path.join(luaDir, COMPILE_FILES.DEPLOY_JSON);
@@ -70,7 +96,100 @@ export async function compileCommand() {
70
96
  writeProgress("🔄 Syncing server with YAML...");
71
97
  const updatedConfig = readSkillConfig(); // Re-read config after YAML sync
72
98
  await syncServerSkillsWithYaml(updatedConfig);
73
- writeSuccess(`✅ Skill compiled successfully - ${tools.length} tools bundled`);
99
+ // Step 8: Detect and process webhooks
100
+ writeProgress("🔍 Detecting webhooks...");
101
+ // Use resolved agent webhooks if available, otherwise scan index file
102
+ let webhooksMetadata = resolvedAgentData?.webhooks || extractWebhooksMetadata(indexFile);
103
+ let bundledWebhooks = [];
104
+ if (webhooksMetadata.length > 0) {
105
+ writeProgress(`đŸ“Ļ Found ${webhooksMetadata.length} webhook(s)...`);
106
+ // Bundle each webhook (extract execute function and schemas)
107
+ for (const webhook of webhooksMetadata) {
108
+ const bundled = await bundleWebhook(webhook, indexFile, distDir, project);
109
+ bundledWebhooks.push(bundled);
110
+ }
111
+ // Ensure webhooks exist in YAML with valid IDs
112
+ const configForWebhooks = readSkillConfig(); // Re-read for webhooks
113
+ await ensureWebhooksExistInYaml(webhooksMetadata, configForWebhooks);
114
+ // Sync server webhooks with YAML
115
+ writeProgress("🔄 Syncing server webhooks with YAML...");
116
+ const webhookConfig = readSkillConfig(); // Re-read after webhook updates
117
+ await syncServerWebhooksWithYaml(webhookConfig);
118
+ // Write bundled webhooks to file for reference
119
+ fs.writeFileSync(path.join(distDir, 'webhooks.json'), JSON.stringify(bundledWebhooks, null, 2));
120
+ }
121
+ // Step 9: Detect and process jobs
122
+ writeProgress("🔍 Detecting jobs...");
123
+ // Use resolved agent jobs if available, otherwise scan index file
124
+ let jobsMetadata = resolvedAgentData?.jobs || extractJobsMetadata(indexFile);
125
+ let bundledJobs = [];
126
+ if (jobsMetadata.length > 0) {
127
+ writeProgress(`đŸ“Ļ Found ${jobsMetadata.length} job(s)...`);
128
+ // Bundle each job (extract execute function)
129
+ for (const job of jobsMetadata) {
130
+ const bundled = await bundleJob(job, indexFile, distDir, project);
131
+ bundledJobs.push(bundled);
132
+ }
133
+ // Ensure jobs exist in YAML with valid IDs
134
+ const configForJobs = readSkillConfig(); // Re-read for jobs
135
+ await ensureJobsExistInYaml(jobsMetadata, configForJobs);
136
+ // Sync server jobs with YAML
137
+ writeProgress("🔄 Syncing server jobs with YAML...");
138
+ const jobConfig = readSkillConfig(); // Re-read after job updates
139
+ await syncServerJobsWithYaml(jobConfig);
140
+ // Write bundled jobs to file for reference
141
+ fs.writeFileSync(path.join(distDir, 'jobs.json'), JSON.stringify(bundledJobs, null, 2));
142
+ }
143
+ // Step 10: Detect and process preprocessors
144
+ writeProgress("🔍 Detecting preprocessors...");
145
+ // Use resolved agent preprocessors if available, otherwise scan index file
146
+ let preprocessorsMetadata = resolvedAgentData?.preProcessors || extractPreProcessorsMetadata(indexFile);
147
+ let bundledPreProcessors = [];
148
+ if (preprocessorsMetadata.length > 0) {
149
+ writeProgress(`đŸ“Ļ Found ${preprocessorsMetadata.length} preprocessor(s)...`);
150
+ for (const preprocessor of preprocessorsMetadata) {
151
+ const bundled = await bundlePreProcessor(preprocessor, indexFile, distDir, project);
152
+ bundledPreProcessors.push(bundled);
153
+ }
154
+ // Ensure preprocessors exist in YAML with valid IDs
155
+ const configForPreProcessors = readSkillConfig();
156
+ await ensurePreProcessorsExistInYaml(preprocessorsMetadata, configForPreProcessors);
157
+ // Sync server preprocessors with YAML
158
+ writeProgress("🔄 Syncing server preprocessors with YAML...");
159
+ const preprocessorConfig = readSkillConfig();
160
+ await syncServerPreProcessorsWithYaml(preprocessorConfig);
161
+ fs.writeFileSync(path.join(distDir, 'preprocessors.json'), JSON.stringify(bundledPreProcessors, null, 2));
162
+ }
163
+ // Step 11: Detect and process postprocessors
164
+ writeProgress("🔍 Detecting postprocessors...");
165
+ // Use resolved agent postprocessors if available, otherwise scan index file
166
+ let postprocessorsMetadata = resolvedAgentData?.postProcessors || extractPostProcessorsMetadata(indexFile);
167
+ let bundledPostProcessors = [];
168
+ if (postprocessorsMetadata.length > 0) {
169
+ writeProgress(`đŸ“Ļ Found ${postprocessorsMetadata.length} postprocessor(s)...`);
170
+ for (const postprocessor of postprocessorsMetadata) {
171
+ const bundled = await bundlePostProcessor(postprocessor, indexFile, distDir, project);
172
+ bundledPostProcessors.push(bundled);
173
+ }
174
+ // Ensure postprocessors exist in YAML with valid IDs
175
+ const configForPostProcessors = readSkillConfig();
176
+ await ensurePostProcessorsExistInYaml(postprocessorsMetadata, configForPostProcessors);
177
+ // Sync server postprocessors with YAML
178
+ writeProgress("🔄 Syncing server postprocessors with YAML...");
179
+ const postprocessorConfig = readSkillConfig();
180
+ await syncServerPostProcessorsWithYaml(postprocessorConfig);
181
+ fs.writeFileSync(path.join(distDir, 'postprocessors.json'), JSON.stringify(bundledPostProcessors, null, 2));
182
+ }
183
+ const summaryParts = [`${tools.length} tools bundled`];
184
+ if (webhooksMetadata.length > 0)
185
+ summaryParts.push(`${webhooksMetadata.length} webhook(s) registered`);
186
+ if (jobsMetadata.length > 0)
187
+ summaryParts.push(`${jobsMetadata.length} job(s) registered`);
188
+ if (preprocessorsMetadata.length > 0)
189
+ summaryParts.push(`${preprocessorsMetadata.length} preprocessor(s) registered`);
190
+ if (postprocessorsMetadata.length > 0)
191
+ summaryParts.push(`${postprocessorsMetadata.length} postprocessor(s) registered`);
192
+ writeSuccess(`✅ Skill compiled successfully - ${summaryParts.join(', ')}`);
74
193
  }, "compilation");
75
194
  }
76
195
  /**
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Completion Command
3
+ * Generates shell completion scripts for the Lua CLI
4
+ */
5
+ /**
6
+ * Main completion command - generates shell completion scripts
7
+ *
8
+ * @param shell - Shell type (bash, zsh, fish)
9
+ * @returns Promise that resolves when command completes
10
+ */
11
+ export declare function completionCommand(shell?: string): Promise<void>;