lua-cli 3.1.0-alpha.2 → 3.1.0-alpha.4

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 (70) hide show
  1. package/README.md +0 -4
  2. package/dist/api/job.api.service.d.ts +23 -100
  3. package/dist/api/job.api.service.js +13 -11
  4. package/dist/api/lazy-instances.d.ts +8 -0
  5. package/dist/api/lazy-instances.js +16 -0
  6. package/dist/api/postprocessor.api.service.d.ts +1 -8
  7. package/dist/api/postprocessor.api.service.js +1 -2
  8. package/dist/api/preprocessor.api.service.d.ts +1 -8
  9. package/dist/api/preprocessor.api.service.js +1 -2
  10. package/dist/api/webhook.api.service.d.ts +1 -3
  11. package/dist/api/webhook.api.service.js +1 -1
  12. package/dist/api/whatsapp-templates.api.service.d.ts +40 -0
  13. package/dist/api/whatsapp-templates.api.service.js +78 -0
  14. package/dist/api-exports.d.ts +81 -2
  15. package/dist/api-exports.js +91 -15
  16. package/dist/commands/chat.js +2 -4
  17. package/dist/commands/init.js +11 -44
  18. package/dist/commands/jobs.js +5 -5
  19. package/dist/commands/push.js +2 -9
  20. package/dist/common/job.instance.d.ts +35 -7
  21. package/dist/common/job.instance.js +46 -19
  22. package/dist/config/constants.d.ts +1 -1
  23. package/dist/config/constants.js +1 -5
  24. package/dist/interfaces/agent.d.ts +0 -3
  25. package/dist/interfaces/index.d.ts +1 -1
  26. package/dist/interfaces/init.d.ts +0 -1
  27. package/dist/interfaces/jobs.d.ts +88 -132
  28. package/dist/interfaces/jobs.js +1 -1
  29. package/dist/interfaces/postprocessors.d.ts +0 -3
  30. package/dist/interfaces/preprocessors.d.ts +0 -3
  31. package/dist/interfaces/webhooks.d.ts +0 -5
  32. package/dist/interfaces/whatsapp-templates.d.ts +104 -0
  33. package/dist/interfaces/whatsapp-templates.js +5 -0
  34. package/dist/types/api-contracts.d.ts +32 -0
  35. package/dist/types/compile.types.d.ts +0 -6
  36. package/dist/types/index.d.ts +1 -1
  37. package/dist/types/skill.d.ts +61 -90
  38. package/dist/types/skill.js +28 -86
  39. package/dist/utils/agent-management.d.ts +3 -5
  40. package/dist/utils/agent-management.js +6 -8
  41. package/dist/utils/bundling.js +5 -6
  42. package/dist/utils/compile.d.ts +0 -1
  43. package/dist/utils/compile.js +1 -51
  44. package/dist/utils/deployment.js +0 -1
  45. package/dist/utils/dev-api.js +0 -2
  46. package/dist/utils/files.d.ts +3 -3
  47. package/dist/utils/files.js +4 -12
  48. package/dist/utils/init-agent.d.ts +1 -2
  49. package/dist/utils/init-agent.js +4 -6
  50. package/dist/utils/init-helpers.d.ts +2 -4
  51. package/dist/utils/init-helpers.js +4 -10
  52. package/dist/utils/job-management.js +0 -2
  53. package/dist/utils/postprocessor-management.js +2 -4
  54. package/dist/utils/preprocessor-management.js +2 -4
  55. package/dist/utils/sandbox.js +17 -7
  56. package/dist/utils/webhook-management.js +1 -3
  57. package/package.json +1 -1
  58. package/template/QUICKSTART.md +0 -13
  59. package/template/README.md +6 -7
  60. package/template/src/jobs/AbandonedBasketProcessorJob.ts +0 -3
  61. package/template/src/jobs/DailyCleanupJob.ts +0 -3
  62. package/template/src/jobs/DataMigrationJob.ts +0 -3
  63. package/template/src/jobs/HealthCheckJob.ts +0 -3
  64. package/template/src/postprocessors/modifyResponse.ts +0 -1
  65. package/template/src/preprocessors/messageMatching.ts +18 -5
  66. package/template/src/skills/basket.skill.ts +0 -1
  67. package/template/src/skills/product.skill.ts +0 -1
  68. package/template/src/skills/user.skill.ts +0 -1
  69. package/template/src/webhooks/PaymentWebhook.ts +12 -9
  70. package/template/src/webhooks/UserEventWebhook.ts +39 -11
@@ -15,7 +15,6 @@ export type ASTNode = any;
15
15
  */
16
16
  export interface SkillMetadata {
17
17
  name: string;
18
- version: string;
19
18
  description: string;
20
19
  context: string;
21
20
  constructorTools: string[];
@@ -25,18 +24,14 @@ export interface SkillMetadata {
25
24
  */
26
25
  export interface WebhookMetadata {
27
26
  name: string;
28
- version: string;
29
27
  description: string;
30
- context: string;
31
28
  }
32
29
  /**
33
30
  * Job metadata extracted from source code
34
31
  */
35
32
  export interface JobMetadata {
36
33
  name: string;
37
- version: string;
38
34
  description: string;
39
- context: string;
40
35
  schedule: any;
41
36
  timeout?: number;
42
37
  retry?: {
@@ -59,7 +54,6 @@ export interface YamlConfigAgent {
59
54
  agentId?: string;
60
55
  orgId?: string;
61
56
  persona?: string;
62
- welcomeMessage?: string;
63
57
  }
64
58
  export interface YamlConfigSkill {
65
59
  name: string;
@@ -16,7 +16,7 @@
16
16
  */
17
17
  export { LuaSkill, LuaTool, LuaSkillConfig, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, env } from './skill.js';
18
18
  export { validateToolName, assertValidToolName } from './tool-validation.js';
19
- export { UserDataAPI, ProductAPI, BasketAPI, OrderAPI, CustomDataAPI } from './api-contracts.js';
19
+ export { UserDataAPI, ProductAPI, BasketAPI, OrderAPI, CustomDataAPI, WhatsAppTemplatesAPI } from './api-contracts.js';
20
20
  export { UserData, EmailAddress, Country, Admin, Organization, AgentAuth, OTPResponse, ApiKeyResponse } from '../interfaces/admin.js';
21
21
  export { Agent, AgentType, CreateAgentRequest, CreateAgentResponse, AgentDetailsResponse } from '../interfaces/agent.js';
22
22
  export { BasketStatus, BasketItem, Basket } from '../interfaces/baskets.js';
@@ -65,8 +65,6 @@ export interface LuaTool<TInput extends ZodType = ZodType> {
65
65
  export interface LuaSkillConfig {
66
66
  /** Skill name (optional, defaults to 'unnamed-skill') */
67
67
  name?: string;
68
- /** Skill version (optional, defaults to '1.0.0') */
69
- version?: string;
70
68
  /** Short description of the skill (1-2 sentences) */
71
69
  description: string;
72
70
  /** Detailed context for how the agent should use the tools */
@@ -87,7 +85,6 @@ export interface LuaSkillConfig {
87
85
  *
88
86
  * const skill = new LuaSkill({
89
87
  * name: 'weather-skill',
90
- * version: '1.0.0',
91
88
  * description: "Weather and calculator utilities",
92
89
  * context: "This skill provides weather information and math operations. " +
93
90
  * "Use get_weather for current conditions and calculator for arithmetic.",
@@ -101,7 +98,6 @@ export interface LuaSkillConfig {
101
98
  export declare class LuaSkill {
102
99
  private readonly tools;
103
100
  private readonly name;
104
- private readonly version;
105
101
  private readonly description;
106
102
  private readonly context;
107
103
  /**
@@ -109,7 +105,6 @@ export declare class LuaSkill {
109
105
  *
110
106
  * @param config - Configuration object containing skill metadata
111
107
  * @param config.name - Skill name (optional, defaults to 'unnamed-skill')
112
- * @param config.version - Skill version (optional, defaults to '1.0.0')
113
108
  * @param config.description - Short description of what the skill does (1-2 sentences)
114
109
  * @param config.context - Detailed explanation of how the agent should use the tools
115
110
  * @param config.tools - Optional array of tools to add immediately
@@ -164,12 +159,8 @@ export type JobSchedule = {
164
159
  export interface LuaJobConfig {
165
160
  /** Job name (optional, defaults to 'unnamed-job') */
166
161
  name?: string;
167
- /** Job version (optional, defaults to '1.0.0') */
168
- version?: string;
169
162
  /** Short description of the job (1-2 sentences) */
170
163
  description: string;
171
- /** Detailed context for what this job does */
172
- context: string;
173
164
  /** Schedule configuration - cron, once, or interval */
174
165
  schedule: JobSchedule;
175
166
  /**
@@ -205,9 +196,7 @@ export interface LuaJobConfig {
205
196
  * // Daily cleanup job at 2 AM
206
197
  * const dailyCleanup = new LuaJob({
207
198
  * name: 'daily-cleanup',
208
- * version: '1.0.0',
209
199
  * description: "Daily database cleanup job",
210
- * context: "Runs at 2 AM daily to clean up old records and optimize tables.",
211
200
  * schedule: {
212
201
  * type: 'cron',
213
202
  * expression: '0 2 * * *', // 2 AM every day
@@ -228,9 +217,7 @@ export interface LuaJobConfig {
228
217
  * // One-time job
229
218
  * const sendWelcome = new LuaJob({
230
219
  * name: 'send-welcome',
231
- * version: '1.0.0',
232
220
  * description: "Send welcome email to new users",
233
- * context: "Scheduled one-time task to send welcome emails.",
234
221
  * schedule: {
235
222
  * type: 'once',
236
223
  * executeAt: new Date('2025-12-31T10:00:00Z')
@@ -244,9 +231,7 @@ export interface LuaJobConfig {
244
231
  * // Interval-based job (every 5 minutes)
245
232
  * const healthCheck = new LuaJob({
246
233
  * name: 'health-check',
247
- * version: '1.0.0',
248
234
  * description: "System health check",
249
- * context: "Runs every 5 minutes to check system health.",
250
235
  * schedule: {
251
236
  * type: 'interval',
252
237
  * seconds: 300 // 5 minutes
@@ -259,9 +244,7 @@ export interface LuaJobConfig {
259
244
  */
260
245
  export declare class LuaJob {
261
246
  private readonly name;
262
- private readonly version;
263
247
  private readonly description;
264
- private readonly context;
265
248
  private readonly schedule;
266
249
  private readonly timeout;
267
250
  private readonly retry?;
@@ -272,9 +255,7 @@ export declare class LuaJob {
272
255
  *
273
256
  * @param config - Configuration object containing job metadata
274
257
  * @param config.name - Job name (optional, defaults to 'unnamed-job')
275
- * @param config.version - Job version (optional, defaults to '1.0.0')
276
258
  * @param config.description - Short description of what the job does (1-2 sentences)
277
- * @param config.context - Detailed explanation of the job's purpose
278
259
  * @param config.schedule - Schedule configuration (cron, once, or interval)
279
260
  * @param config.timeout - Optional timeout in seconds (default: 300)
280
261
  * @param config.retry - Optional retry configuration
@@ -286,18 +267,10 @@ export declare class LuaJob {
286
267
  * Gets the job name.
287
268
  */
288
269
  getName(): string;
289
- /**
290
- * Gets the job version.
291
- */
292
- getVersion(): string;
293
270
  /**
294
271
  * Gets the job description.
295
272
  */
296
273
  getDescription(): string;
297
- /**
298
- * Gets the job context.
299
- */
300
- getContext(): string;
301
274
  /**
302
275
  * Gets the job schedule.
303
276
  */
@@ -318,6 +291,19 @@ export declare class LuaJob {
318
291
  */
319
292
  getMetadata(): Record<string, any> | undefined;
320
293
  }
294
+ /**
295
+ * Event payload delivered to webhook execute functions.
296
+ */
297
+ export interface LuaWebhookEvent {
298
+ /** Parsed query parameters */
299
+ query?: Record<string, any>;
300
+ /** Request headers */
301
+ headers?: Record<string, any>;
302
+ /** Request body (JSON or raw data) */
303
+ body?: any;
304
+ /** ISO timestamp when the webhook was received */
305
+ timestamp: string;
306
+ }
321
307
  /**
322
308
  * Lua Webhook configuration.
323
309
  * Used to initialize a new LuaWebhook instance.
@@ -325,12 +311,8 @@ export declare class LuaJob {
325
311
  export interface LuaWebhookConfig {
326
312
  /** Webhook name (optional, defaults to 'unnamed-webhook') */
327
313
  name?: string;
328
- /** Webhook version (optional, defaults to '1.0.0') */
329
- version?: string;
330
314
  /** Short description of the webhook (1-2 sentences) */
331
315
  description: string;
332
- /** Detailed context for what this webhook does and how it should be used */
333
- context: string;
334
316
  /** Optional Zod schema for query parameter validation */
335
317
  querySchema?: ZodType;
336
318
  /** Optional Zod schema for header validation */
@@ -338,7 +320,7 @@ export interface LuaWebhookConfig {
338
320
  /** Optional Zod schema for body validation */
339
321
  bodySchema?: ZodType;
340
322
  /** Function that executes the webhook logic */
341
- execute: (query?: any, headers?: any, body?: any) => Promise<any>;
323
+ execute: (event: LuaWebhookEvent) => Promise<any>;
342
324
  }
343
325
  /**
344
326
  * Lua Webhook class.
@@ -355,10 +337,7 @@ export interface LuaWebhookConfig {
355
337
  *
356
338
  * const webhook = new LuaWebhook({
357
339
  * name: 'user-created',
358
- * version: '1.0.0',
359
340
  * description: "Webhook that handles user creation events",
360
- * context: "This webhook processes new user registration events. " +
361
- * "It validates the user data and sends welcome emails.",
362
341
  * querySchema: z.object({
363
342
  * source: z.string().optional()
364
343
  * }),
@@ -371,7 +350,8 @@ export interface LuaWebhookConfig {
371
350
  * email: z.string().email(),
372
351
  * name: z.string()
373
352
  * }),
374
- * execute: async (query, headers, body) => {
353
+ * execute: async (event) => {
354
+ * const { query, headers, body } = event;
375
355
  * // Process the webhook...
376
356
  * console.log('New user:', body.email);
377
357
  * return { success: true, userId: body.userId };
@@ -388,9 +368,7 @@ export interface LuaWebhookConfig {
388
368
  */
389
369
  export declare class LuaWebhook {
390
370
  private readonly name;
391
- private readonly version;
392
371
  private readonly description;
393
- private readonly context;
394
372
  private readonly querySchema?;
395
373
  private readonly headerSchema?;
396
374
  private readonly bodySchema?;
@@ -400,9 +378,7 @@ export declare class LuaWebhook {
400
378
  *
401
379
  * @param config - Configuration object containing webhook metadata
402
380
  * @param config.name - Webhook name (optional, defaults to 'unnamed-webhook')
403
- * @param config.version - Webhook version (optional, defaults to '1.0.0')
404
381
  * @param config.description - Short description of what the webhook does (1-2 sentences)
405
- * @param config.context - Detailed explanation of the webhook's purpose and behavior
406
382
  * @param config.querySchema - Optional Zod schema for query parameter validation
407
383
  * @param config.headerSchema - Optional Zod schema for header validation
408
384
  * @param config.bodySchema - Optional Zod schema for body validation
@@ -413,18 +389,10 @@ export declare class LuaWebhook {
413
389
  * Gets the webhook name.
414
390
  */
415
391
  getName(): string;
416
- /**
417
- * Gets the webhook version.
418
- */
419
- getVersion(): string;
420
392
  /**
421
393
  * Gets the webhook description.
422
394
  */
423
395
  getDescription(): string;
424
- /**
425
- * Gets the webhook context.
426
- */
427
- getContext(): string;
428
396
  /**
429
397
  * Executes the webhook with validated input.
430
398
  * Validates query parameters, headers, and body against their respective schemas
@@ -447,18 +415,35 @@ export declare class LuaWebhook {
447
415
  */
448
416
  execute(query?: Record<string, any>, headers?: Record<string, any>, body?: any): Promise<any>;
449
417
  }
418
+ export type PreProcessorAction = 'proceed' | 'block';
419
+ export type PreProcessorBlockResponse = {
420
+ /** Stop processing immediately */
421
+ action: 'block';
422
+ /** Message to show to the user */
423
+ response: string;
424
+ /** Optional metadata */
425
+ metadata?: Record<string, any>;
426
+ };
427
+ export type PreProcessorProceedResponse = {
428
+ /** Proceed to next preprocessor or agent */
429
+ action: 'proceed';
430
+ /** Optional modified message (if not provided, uses original/current message) */
431
+ modifiedMessage?: import("../interfaces/chat.js").ChatMessage[];
432
+ /** Optional metadata to pass along */
433
+ metadata?: Record<string, any>;
434
+ };
435
+ /**
436
+ * Result returned by the preprocessor
437
+ */
438
+ export type PreProcessorResult = PreProcessorBlockResponse | PreProcessorProceedResponse;
450
439
  /**
451
440
  * PreProcessor configuration.
452
441
  */
453
442
  export interface PreProcessorConfig {
454
443
  /** PreProcessor name (optional, defaults to 'unnamed-preprocessor') */
455
444
  name?: string;
456
- /** PreProcessor version (optional, defaults to '1.0.0') */
457
- version?: string;
458
445
  /** Short description of the preprocessor */
459
446
  description: string;
460
- /** Detailed context for what this preprocessor does */
461
- context: string;
462
447
  /**
463
448
  * Async flag - indicates if processor should run in background on server:
464
449
  * - true: Run asynchronously (non-blocking, for slow operations like API calls)
@@ -466,11 +451,15 @@ export interface PreProcessorConfig {
466
451
  * Default: false (synchronous)
467
452
  */
468
453
  async?: boolean;
454
+ /**
455
+ * Execution priority (lower runs first).
456
+ * Default: 100
457
+ */
458
+ priority?: number;
469
459
  /**
470
460
  * Function that processes messages before sending to agent.
471
- * MUST return ChatMessage[] - array of text, image, or file messages.
472
461
  */
473
- execute: (user: UserDataInstance, messages: import("../interfaces/chat.js").ChatMessage[], channel: string) => Promise<import("../interfaces/chat.js").ChatMessage[]>;
462
+ execute: (user: UserDataInstance, messages: import("../interfaces/chat.js").ChatMessage[], channel: string) => Promise<PreProcessorResult>;
474
463
  }
475
464
  /**
476
465
  * PreProcessor class.
@@ -481,41 +470,39 @@ export interface PreProcessorConfig {
481
470
  * ```typescript
482
471
  * const contentFilter = new PreProcessor({
483
472
  * name: 'content-filter',
484
- * version: '1.0.0',
485
473
  * description: 'Filters and processes message content',
486
- * context: 'Filters spam, validates images, and adds context',
474
+ * priority: 10,
487
475
  * execute: async (user, messages, channel) => {
488
- * // Process each message
489
- * return messages.map(msg => {
490
- * if (msg.type === 'text') {
491
- * // Filter spam from text
492
- * const filtered = msg.text.replace(/spam/gi, '[filtered]');
493
- * return { type: 'text', text: filtered };
494
- * }
495
- * if (msg.type === 'image') {
496
- * // Could validate image, add watermark, etc.
497
- * return msg;
498
- * }
499
- * return msg;
500
- * });
476
+ * // Check for spam
477
+ * const hasSpam = messages.some(msg =>
478
+ * msg.type === 'text' && msg.text.includes('spam')
479
+ * );
480
+ *
481
+ * if (hasSpam) {
482
+ * return {
483
+ * action: 'block',
484
+ * response: "Message blocked due to spam content"
485
+ * };
486
+ * }
487
+ *
488
+ * // Return messages to proceed
489
+ * return { action: 'proceed' };
501
490
  * }
502
491
  * });
503
492
  * ```
504
493
  */
505
494
  export declare class PreProcessor {
506
495
  private readonly name;
507
- private readonly version;
508
496
  private readonly description;
509
- private readonly context;
510
497
  private readonly asyncMode;
498
+ private readonly priority;
511
499
  private readonly executeFunction;
512
500
  constructor(config: PreProcessorConfig);
513
501
  getName(): string;
514
- getVersion(): string;
515
502
  getDescription(): string;
516
- getContext(): string;
517
503
  getAsync(): boolean;
518
- execute(user: UserDataInstance, messages: import("../interfaces/chat.js").ChatMessage[], channel: string): Promise<import("../interfaces/chat.js").ChatMessage[]>;
504
+ getPriority(): number;
505
+ execute(user: UserDataInstance, messages: import("../interfaces/chat.js").ChatMessage[], channel: string): Promise<PreProcessorResult>;
519
506
  }
520
507
  /**
521
508
  * PostProcessor configuration.
@@ -523,12 +510,8 @@ export declare class PreProcessor {
523
510
  export interface PostProcessorConfig {
524
511
  /** PostProcessor name (optional, defaults to 'unnamed-postprocessor') */
525
512
  name?: string;
526
- /** PostProcessor version (optional, defaults to '1.0.0') */
527
- version?: string;
528
513
  /** Short description of the postprocessor */
529
514
  description: string;
530
- /** Detailed context for what this postprocessor does */
531
- context: string;
532
515
  /**
533
516
  * Async flag - indicates if processor should run in background on server:
534
517
  * - true: Run asynchronously (non-blocking, for slow operations like API calls, translations)
@@ -550,9 +533,7 @@ export interface PostProcessorConfig {
550
533
  * ```typescript
551
534
  * const responseFormatter = new PostProcessor({
552
535
  * name: 'response-formatter',
553
- * version: '1.0.0',
554
536
  * description: 'Formats responses with branding',
555
- * context: 'Adds company signature to all responses',
556
537
  * execute: async (user, message, response, channel) => {
557
538
  * return response + '\n\n---\nPowered by Acme Corp';
558
539
  * }
@@ -561,16 +542,12 @@ export interface PostProcessorConfig {
561
542
  */
562
543
  export declare class PostProcessor {
563
544
  private readonly name;
564
- private readonly version;
565
545
  private readonly description;
566
- private readonly context;
567
546
  private readonly asyncMode;
568
547
  private readonly executeFunction;
569
548
  constructor(config: PostProcessorConfig);
570
549
  getName(): string;
571
- getVersion(): string;
572
550
  getDescription(): string;
573
- getContext(): string;
574
551
  getAsync(): boolean;
575
552
  execute(user: UserDataInstance, message: string, response: string, channel: string): Promise<string>;
576
553
  }
@@ -587,8 +564,6 @@ export interface LuaAgentConfig {
587
564
  name: string;
588
565
  /** Agent persona - defines the agent's behavior and personality */
589
566
  persona: string;
590
- /** Optional welcome message shown when users first interact */
591
- welcomeMessage?: string;
592
567
  /** Array of skills (each with tools) */
593
568
  skills?: LuaSkill[];
594
569
  /** Array of webhooks */
@@ -620,7 +595,6 @@ export interface LuaAgentConfig {
620
595
  * export const agent = new LuaAgent({
621
596
  * name: 'my-assistant',
622
597
  * persona: 'You are a helpful AI assistant that can manage users and products.',
623
- * welcomeMessage: 'Hello! How can I help you today?',
624
598
  * skills: [userSkill],
625
599
  * jobs: [healthCheckJob],
626
600
  * webhooks: [webhookHandler],
@@ -632,7 +606,6 @@ export interface LuaAgentConfig {
632
606
  export declare class LuaAgent {
633
607
  private readonly name;
634
608
  private readonly persona;
635
- private readonly welcomeMessage?;
636
609
  private readonly skills;
637
610
  private readonly webhooks;
638
611
  private readonly jobs;
@@ -644,7 +617,6 @@ export declare class LuaAgent {
644
617
  * @param config - Agent configuration
645
618
  * @param config.name - Agent name
646
619
  * @param config.persona - Agent persona (behavior and personality)
647
- * @param config.welcomeMessage - Optional welcome message
648
620
  * @param config.skills - Optional array of skills
649
621
  * @param config.webhooks - Optional array of webhooks
650
622
  * @param config.jobs - Optional array of jobs
@@ -654,7 +626,6 @@ export declare class LuaAgent {
654
626
  constructor(config: LuaAgentConfig);
655
627
  getName(): string;
656
628
  getPersona(): string;
657
- getWelcomeMessage(): string | undefined;
658
629
  getSkills(): LuaSkill[];
659
630
  getWebhooks(): LuaWebhook[];
660
631
  getJobs(): LuaJob[];