lua-cli 3.1.0-alpha.3 → 3.1.0-alpha.5

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 (125) hide show
  1. package/README.md +0 -4
  2. package/dist/api/cdn.api.service.d.ts +18 -0
  3. package/dist/api/cdn.api.service.js +43 -0
  4. package/dist/api/custom.data.api.service.d.ts +4 -3
  5. package/dist/api/custom.data.api.service.js +4 -3
  6. package/dist/api/developer.api.service.d.ts +54 -1
  7. package/dist/api/developer.api.service.js +89 -0
  8. package/dist/api/job.api.service.d.ts +33 -100
  9. package/dist/api/job.api.service.js +27 -11
  10. package/dist/api/lazy-instances.d.ts +16 -0
  11. package/dist/api/lazy-instances.js +32 -0
  12. package/dist/api/postprocessor.api.service.d.ts +3 -13
  13. package/dist/api/postprocessor.api.service.js +2 -4
  14. package/dist/api/preprocessor.api.service.d.ts +1 -8
  15. package/dist/api/preprocessor.api.service.js +1 -2
  16. package/dist/api/webhook.api.service.d.ts +1 -3
  17. package/dist/api/webhook.api.service.js +1 -1
  18. package/dist/api/whatsapp-templates.api.service.d.ts +40 -0
  19. package/dist/api/whatsapp-templates.api.service.js +78 -0
  20. package/dist/api-exports.d.ts +153 -6
  21. package/dist/api-exports.js +177 -21
  22. package/dist/cli/command-definitions.js +34 -7
  23. package/dist/commands/admin.js +1 -1
  24. package/dist/commands/channels.js +1 -1
  25. package/dist/commands/chat.js +2 -4
  26. package/dist/commands/compile.js +23 -4
  27. package/dist/commands/evals.d.ts +8 -0
  28. package/dist/commands/evals.js +41 -0
  29. package/dist/commands/index.d.ts +2 -0
  30. package/dist/commands/index.js +2 -0
  31. package/dist/commands/init.d.ts +10 -1
  32. package/dist/commands/init.js +23 -46
  33. package/dist/commands/jobs.js +5 -5
  34. package/dist/commands/mcp.d.ts +18 -0
  35. package/dist/commands/mcp.js +393 -0
  36. package/dist/commands/push.js +174 -23
  37. package/dist/common/data.entry.instance.d.ts +1 -1
  38. package/dist/common/data.entry.instance.js +4 -4
  39. package/dist/common/job.instance.d.ts +59 -7
  40. package/dist/common/job.instance.js +84 -19
  41. package/dist/config/constants.d.ts +1 -0
  42. package/dist/config/constants.js +1 -0
  43. package/dist/index.js +1 -0
  44. package/dist/interfaces/agent.d.ts +0 -3
  45. package/dist/interfaces/cdn.d.ts +24 -0
  46. package/dist/interfaces/cdn.js +5 -0
  47. package/dist/interfaces/compile.d.ts +1 -0
  48. package/dist/interfaces/custom.data.d.ts +3 -3
  49. package/dist/interfaces/index.d.ts +2 -1
  50. package/dist/interfaces/init.d.ts +0 -1
  51. package/dist/interfaces/jobs.d.ts +88 -132
  52. package/dist/interfaces/jobs.js +1 -1
  53. package/dist/interfaces/mcp.d.ts +64 -0
  54. package/dist/interfaces/mcp.js +5 -0
  55. package/dist/interfaces/postprocessors.d.ts +0 -3
  56. package/dist/interfaces/preprocessors.d.ts +0 -3
  57. package/dist/interfaces/webhooks.d.ts +0 -5
  58. package/dist/interfaces/whatsapp-templates.d.ts +104 -0
  59. package/dist/interfaces/whatsapp-templates.js +5 -0
  60. package/dist/types/api-contracts.d.ts +68 -14
  61. package/dist/types/compile.types.d.ts +5 -6
  62. package/dist/types/index.d.ts +2 -2
  63. package/dist/types/index.js +3 -1
  64. package/dist/types/skill.d.ts +181 -103
  65. package/dist/types/skill.js +123 -91
  66. package/dist/utils/agent-management.d.ts +3 -5
  67. package/dist/utils/agent-management.js +6 -8
  68. package/dist/utils/bundling.d.ts +4 -11
  69. package/dist/utils/bundling.js +24 -33
  70. package/dist/utils/compile.d.ts +17 -9
  71. package/dist/utils/compile.js +72 -88
  72. package/dist/utils/deployment.js +13 -7
  73. package/dist/utils/dev-api.js +1 -4
  74. package/dist/utils/dev-server.js +1 -1
  75. package/dist/utils/files.d.ts +11 -4
  76. package/dist/utils/files.js +17 -14
  77. package/dist/utils/init-agent.d.ts +1 -2
  78. package/dist/utils/init-agent.js +4 -6
  79. package/dist/utils/init-helpers.d.ts +4 -4
  80. package/dist/utils/init-helpers.js +10 -11
  81. package/dist/utils/job-management.js +0 -2
  82. package/dist/utils/mcp-server-management.d.ts +23 -0
  83. package/dist/utils/mcp-server-management.js +212 -0
  84. package/dist/utils/postprocessor-management.js +2 -4
  85. package/dist/utils/preprocessor-management.js +2 -4
  86. package/dist/utils/sandbox.d.ts +4 -2
  87. package/dist/utils/sandbox.js +38 -9
  88. package/dist/utils/webhook-management.js +1 -3
  89. package/dist/web/app.css +1505 -14
  90. package/dist/web/app.js +79 -64
  91. package/package.json +2 -6
  92. package/template/QUICKSTART.md +57 -774
  93. package/template/README.md +80 -907
  94. package/template/examples/README.md +106 -0
  95. package/template/{src → examples}/jobs/AbandonedBasketProcessorJob.ts +67 -14
  96. package/template/{src → examples}/jobs/DailyCleanupJob.ts +0 -3
  97. package/template/{src → examples}/jobs/DataMigrationJob.ts +0 -3
  98. package/template/{src → examples}/jobs/HealthCheckJob.ts +0 -3
  99. package/template/{src → examples}/postprocessors/modifyResponse.ts +3 -4
  100. package/template/examples/preprocessors/messageMatching.ts +35 -0
  101. package/template/{src → examples}/skills/basket.skill.ts +0 -1
  102. package/template/{src → examples}/skills/product.skill.ts +0 -1
  103. package/template/{src → examples}/skills/tools/GameScoreTrackerTool.ts +11 -15
  104. package/template/{src → examples}/skills/tools/OrderTool.ts +25 -0
  105. package/template/examples/skills/tools/PremiumFeatureTool.ts +98 -0
  106. package/template/{src → examples}/skills/tools/UserDataTool.ts +34 -0
  107. package/template/{src → examples}/skills/user.skill.ts +0 -1
  108. package/template/examples/webhooks/FileUploadWebhook.ts +86 -0
  109. package/template/{src → examples}/webhooks/PaymentWebhook.ts +12 -9
  110. package/template/examples/webhooks/UserEventWebhook.ts +105 -0
  111. package/template/package-lock.json +7895 -0
  112. package/template/package.json +1 -1
  113. package/template/src/index.ts +40 -22
  114. package/template/src/preprocessors/messageMatching.ts +0 -22
  115. package/template/src/webhooks/UserEventWebhook.ts +0 -77
  116. /package/template/{src → examples}/services/ApiService.ts +0 -0
  117. /package/template/{src → examples}/services/GetWeather.ts +0 -0
  118. /package/template/{src → examples}/skills/tools/BasketTool.ts +0 -0
  119. /package/template/{src → examples}/skills/tools/CreateInlineJob.ts +0 -0
  120. /package/template/{src → examples}/skills/tools/CreatePostTool.ts +0 -0
  121. /package/template/{src → examples}/skills/tools/CustomDataTool.ts +0 -0
  122. /package/template/{src → examples}/skills/tools/GetWeatherTool.ts +0 -0
  123. /package/template/{src → examples}/skills/tools/PaymentTool.ts +0 -0
  124. /package/template/{src → examples}/skills/tools/ProductsTool.ts +0 -0
  125. /package/template/{src → examples}/skills/tools/SmartBasketTool.ts +0 -0
@@ -66,7 +66,6 @@ export const env = (key) => {
66
66
  *
67
67
  * const skill = new LuaSkill({
68
68
  * name: 'weather-skill',
69
- * version: '1.0.0',
70
69
  * description: "Weather and calculator utilities",
71
70
  * context: "This skill provides weather information and math operations. " +
72
71
  * "Use get_weather for current conditions and calculator for arithmetic.",
@@ -83,7 +82,6 @@ export class LuaSkill {
83
82
  *
84
83
  * @param config - Configuration object containing skill metadata
85
84
  * @param config.name - Skill name (optional, defaults to 'unnamed-skill')
86
- * @param config.version - Skill version (optional, defaults to '1.0.0')
87
85
  * @param config.description - Short description of what the skill does (1-2 sentences)
88
86
  * @param config.context - Detailed explanation of how the agent should use the tools
89
87
  * @param config.tools - Optional array of tools to add immediately
@@ -91,7 +89,6 @@ export class LuaSkill {
91
89
  constructor(config) {
92
90
  this.tools = [];
93
91
  this.name = config.name || 'unnamed-skill';
94
- this.version = config.version || '1.0.0';
95
92
  this.description = config.description;
96
93
  this.context = config.context;
97
94
  // Add tools from constructor if provided
@@ -157,9 +154,7 @@ export class LuaSkill {
157
154
  * // Daily cleanup job at 2 AM
158
155
  * const dailyCleanup = new LuaJob({
159
156
  * name: 'daily-cleanup',
160
- * version: '1.0.0',
161
157
  * description: "Daily database cleanup job",
162
- * context: "Runs at 2 AM daily to clean up old records and optimize tables.",
163
158
  * schedule: {
164
159
  * type: 'cron',
165
160
  * expression: '0 2 * * *', // 2 AM every day
@@ -180,9 +175,7 @@ export class LuaSkill {
180
175
  * // One-time job
181
176
  * const sendWelcome = new LuaJob({
182
177
  * name: 'send-welcome',
183
- * version: '1.0.0',
184
178
  * description: "Send welcome email to new users",
185
- * context: "Scheduled one-time task to send welcome emails.",
186
179
  * schedule: {
187
180
  * type: 'once',
188
181
  * executeAt: new Date('2025-12-31T10:00:00Z')
@@ -196,9 +189,7 @@ export class LuaSkill {
196
189
  * // Interval-based job (every 5 minutes)
197
190
  * const healthCheck = new LuaJob({
198
191
  * name: 'health-check',
199
- * version: '1.0.0',
200
192
  * description: "System health check",
201
- * context: "Runs every 5 minutes to check system health.",
202
193
  * schedule: {
203
194
  * type: 'interval',
204
195
  * seconds: 300 // 5 minutes
@@ -215,9 +206,7 @@ export class LuaJob {
215
206
  *
216
207
  * @param config - Configuration object containing job metadata
217
208
  * @param config.name - Job name (optional, defaults to 'unnamed-job')
218
- * @param config.version - Job version (optional, defaults to '1.0.0')
219
209
  * @param config.description - Short description of what the job does (1-2 sentences)
220
- * @param config.context - Detailed explanation of the job's purpose
221
210
  * @param config.schedule - Schedule configuration (cron, once, or interval)
222
211
  * @param config.timeout - Optional timeout in seconds (default: 300)
223
212
  * @param config.retry - Optional retry configuration
@@ -226,9 +215,7 @@ export class LuaJob {
226
215
  */
227
216
  constructor(config) {
228
217
  this.name = config.name || 'unnamed-job';
229
- this.version = config.version || '1.0.0';
230
218
  this.description = config.description;
231
- this.context = config.context;
232
219
  this.schedule = config.schedule;
233
220
  this.timeout = config.timeout || 300;
234
221
  this.retry = config.retry;
@@ -241,24 +228,12 @@ export class LuaJob {
241
228
  getName() {
242
229
  return this.name;
243
230
  }
244
- /**
245
- * Gets the job version.
246
- */
247
- getVersion() {
248
- return this.version;
249
- }
250
231
  /**
251
232
  * Gets the job description.
252
233
  */
253
234
  getDescription() {
254
235
  return this.description;
255
236
  }
256
- /**
257
- * Gets the job context.
258
- */
259
- getContext() {
260
- return this.context;
261
- }
262
237
  /**
263
238
  * Gets the job schedule.
264
239
  */
@@ -299,10 +274,7 @@ export class LuaJob {
299
274
  *
300
275
  * const webhook = new LuaWebhook({
301
276
  * name: 'user-created',
302
- * version: '1.0.0',
303
277
  * description: "Webhook that handles user creation events",
304
- * context: "This webhook processes new user registration events. " +
305
- * "It validates the user data and sends welcome emails.",
306
278
  * querySchema: z.object({
307
279
  * source: z.string().optional()
308
280
  * }),
@@ -315,7 +287,8 @@ export class LuaJob {
315
287
  * email: z.string().email(),
316
288
  * name: z.string()
317
289
  * }),
318
- * execute: async (query, headers, body) => {
290
+ * execute: async (event) => {
291
+ * const { query, headers, body } = event;
319
292
  * // Process the webhook...
320
293
  * console.log('New user:', body.email);
321
294
  * return { success: true, userId: body.userId };
@@ -336,9 +309,7 @@ export class LuaWebhook {
336
309
  *
337
310
  * @param config - Configuration object containing webhook metadata
338
311
  * @param config.name - Webhook name (optional, defaults to 'unnamed-webhook')
339
- * @param config.version - Webhook version (optional, defaults to '1.0.0')
340
312
  * @param config.description - Short description of what the webhook does (1-2 sentences)
341
- * @param config.context - Detailed explanation of the webhook's purpose and behavior
342
313
  * @param config.querySchema - Optional Zod schema for query parameter validation
343
314
  * @param config.headerSchema - Optional Zod schema for header validation
344
315
  * @param config.bodySchema - Optional Zod schema for body validation
@@ -346,9 +317,7 @@ export class LuaWebhook {
346
317
  */
347
318
  constructor(config) {
348
319
  this.name = config.name || 'unnamed-webhook';
349
- this.version = config.version || '1.0.0';
350
320
  this.description = config.description;
351
- this.context = config.context;
352
321
  this.querySchema = config.querySchema;
353
322
  this.headerSchema = config.headerSchema;
354
323
  this.bodySchema = config.bodySchema;
@@ -360,24 +329,12 @@ export class LuaWebhook {
360
329
  getName() {
361
330
  return this.name;
362
331
  }
363
- /**
364
- * Gets the webhook version.
365
- */
366
- getVersion() {
367
- return this.version;
368
- }
369
332
  /**
370
333
  * Gets the webhook description.
371
334
  */
372
335
  getDescription() {
373
336
  return this.description;
374
337
  }
375
- /**
376
- * Gets the webhook context.
377
- */
378
- getContext() {
379
- return this.context;
380
- }
381
338
  /**
382
339
  * Executes the webhook with validated input.
383
340
  * Validates query parameters, headers, and body against their respective schemas
@@ -429,8 +386,13 @@ export class LuaWebhook {
429
386
  throw new Error(`Body validation failed: ${error}`);
430
387
  }
431
388
  }
432
- // Execute the webhook function with validated inputs as separate parameters
433
- return this.executeFunction(validatedQuery, validatedHeaders, validatedBody);
389
+ const event = {
390
+ query: validatedQuery || {},
391
+ headers: validatedHeaders || {},
392
+ body: validatedBody,
393
+ timestamp: new Date().toISOString(),
394
+ };
395
+ return this.executeFunction(event);
434
396
  }
435
397
  }
436
398
  /**
@@ -442,23 +404,23 @@ export class LuaWebhook {
442
404
  * ```typescript
443
405
  * const contentFilter = new PreProcessor({
444
406
  * name: 'content-filter',
445
- * version: '1.0.0',
446
407
  * description: 'Filters and processes message content',
447
- * context: 'Filters spam, validates images, and adds context',
408
+ * priority: 10,
448
409
  * execute: async (user, messages, channel) => {
449
- * // Process each message
450
- * return messages.map(msg => {
451
- * if (msg.type === 'text') {
452
- * // Filter spam from text
453
- * const filtered = msg.text.replace(/spam/gi, '[filtered]');
454
- * return { type: 'text', text: filtered };
455
- * }
456
- * if (msg.type === 'image') {
457
- * // Could validate image, add watermark, etc.
458
- * return msg;
459
- * }
460
- * return msg;
461
- * });
410
+ * // Check for spam
411
+ * const hasSpam = messages.some(msg =>
412
+ * msg.type === 'text' && msg.text.includes('spam')
413
+ * );
414
+ *
415
+ * if (hasSpam) {
416
+ * return {
417
+ * action: 'block',
418
+ * response: "Message blocked due to spam content"
419
+ * };
420
+ * }
421
+ *
422
+ * // Return messages to proceed
423
+ * return { action: 'proceed' };
462
424
  * }
463
425
  * });
464
426
  * ```
@@ -466,27 +428,23 @@ export class LuaWebhook {
466
428
  export class PreProcessor {
467
429
  constructor(config) {
468
430
  this.name = config.name || 'unnamed-preprocessor';
469
- this.version = config.version || '1.0.0';
470
431
  this.description = config.description;
471
- this.context = config.context;
472
432
  this.asyncMode = config.async ?? false; // Default to synchronous
433
+ this.priority = config.priority ?? 100;
473
434
  this.executeFunction = config.execute;
474
435
  }
475
436
  getName() {
476
437
  return this.name;
477
438
  }
478
- getVersion() {
479
- return this.version;
480
- }
481
439
  getDescription() {
482
440
  return this.description;
483
441
  }
484
- getContext() {
485
- return this.context;
486
- }
487
442
  getAsync() {
488
443
  return this.asyncMode;
489
444
  }
445
+ getPriority() {
446
+ return this.priority;
447
+ }
490
448
  async execute(user, messages, channel) {
491
449
  return this.executeFunction(user, messages, channel);
492
450
  }
@@ -499,11 +457,9 @@ export class PreProcessor {
499
457
  * ```typescript
500
458
  * const responseFormatter = new PostProcessor({
501
459
  * name: 'response-formatter',
502
- * version: '1.0.0',
503
460
  * description: 'Formats responses with branding',
504
- * context: 'Adds company signature to all responses',
505
461
  * execute: async (user, message, response, channel) => {
506
- * return response + '\n\n---\nPowered by Acme Corp';
462
+ * return { modifiedResponse: response + '\n\n---\nPowered by Acme Corp' };
507
463
  * }
508
464
  * });
509
465
  * ```
@@ -511,31 +467,108 @@ export class PreProcessor {
511
467
  export class PostProcessor {
512
468
  constructor(config) {
513
469
  this.name = config.name || 'unnamed-postprocessor';
514
- this.version = config.version || '1.0.0';
515
470
  this.description = config.description;
516
- this.context = config.context;
517
- this.asyncMode = config.async ?? false; // Default to synchronous
518
471
  this.executeFunction = config.execute;
519
472
  }
520
473
  getName() {
521
474
  return this.name;
522
475
  }
523
- getVersion() {
524
- return this.version;
525
- }
526
476
  getDescription() {
527
477
  return this.description;
528
478
  }
529
- getContext() {
530
- return this.context;
531
- }
532
- getAsync() {
533
- return this.asyncMode;
534
- }
535
479
  async execute(user, message, response, channel) {
536
480
  return this.executeFunction(user, message, response, channel);
537
481
  }
538
482
  }
483
+ /**
484
+ * LuaMCPServer class.
485
+ * Defines an MCP (Model Context Protocol) server connection.
486
+ *
487
+ * MCP servers provide tools that can be used by your agent at runtime.
488
+ * You can connect to local servers (via stdio) or remote servers (via SSE/HTTP).
489
+ *
490
+ * @example
491
+ * ```typescript
492
+ * import { LuaMCPServer } from 'lua-cli';
493
+ *
494
+ * // Local MCP server via npx
495
+ * const wikipediaServer = new LuaMCPServer({
496
+ * name: 'wikipedia',
497
+ * transport: 'stdio',
498
+ * command: 'npx',
499
+ * args: ['-y', 'wikipedia-mcp'],
500
+ * description: 'Wikipedia search and retrieval'
501
+ * });
502
+ *
503
+ * // Remote MCP server via SSE
504
+ * const weatherServer = new LuaMCPServer({
505
+ * name: 'weather',
506
+ * transport: 'sse',
507
+ * url: 'https://api.example.com/mcp',
508
+ * headers: {
509
+ * 'Authorization': 'Bearer ${env.WEATHER_API_KEY}'
510
+ * },
511
+ * description: 'Weather information service'
512
+ * });
513
+ * ```
514
+ */
515
+ export class LuaMCPServer {
516
+ constructor(config) {
517
+ if (!config.name) {
518
+ throw new Error('MCP server name is required');
519
+ }
520
+ if (config.transport === 'stdio' && !config.command) {
521
+ throw new Error('Command is required for stdio transport');
522
+ }
523
+ if (config.transport === 'sse' && !config.url) {
524
+ throw new Error('URL is required for sse transport');
525
+ }
526
+ this.config = config;
527
+ }
528
+ getName() {
529
+ return this.config.name;
530
+ }
531
+ getTransport() {
532
+ return this.config.transport;
533
+ }
534
+ getTimeout() {
535
+ return this.config.timeout;
536
+ }
537
+ getConfig() {
538
+ return this.config;
539
+ }
540
+ /**
541
+ * Returns the server configuration in a format suitable for serialization.
542
+ * Environment variable references (${env.VAR_NAME}) are preserved for runtime resolution.
543
+ */
544
+ toJSON() {
545
+ const base = {
546
+ name: this.config.name,
547
+ transport: this.config.transport,
548
+ };
549
+ if (this.config.timeout) {
550
+ base.timeout = this.config.timeout;
551
+ }
552
+ if (this.config.transport === 'stdio') {
553
+ const stdioConfig = this.config;
554
+ base.command = stdioConfig.command;
555
+ if (stdioConfig.args) {
556
+ base.args = stdioConfig.args;
557
+ }
558
+ if (stdioConfig.env) {
559
+ base.env = stdioConfig.env;
560
+ }
561
+ }
562
+ else {
563
+ const sseConfig = this.config;
564
+ base.url = sseConfig.url;
565
+ if (sseConfig.headers) {
566
+ base.headers = sseConfig.headers;
567
+ }
568
+ }
569
+ return base;
570
+ }
571
+ }
539
572
  /**
540
573
  * LuaAgent class.
541
574
  * Unified agent configuration that consolidates skills, webhooks, jobs, and processors.
@@ -556,7 +589,6 @@ export class PostProcessor {
556
589
  * export const agent = new LuaAgent({
557
590
  * name: 'my-assistant',
558
591
  * persona: 'You are a helpful AI assistant that can manage users and products.',
559
- * welcomeMessage: 'Hello! How can I help you today?',
560
592
  * skills: [userSkill],
561
593
  * jobs: [healthCheckJob],
562
594
  * webhooks: [webhookHandler],
@@ -572,22 +604,22 @@ export class LuaAgent {
572
604
  * @param config - Agent configuration
573
605
  * @param config.name - Agent name
574
606
  * @param config.persona - Agent persona (behavior and personality)
575
- * @param config.welcomeMessage - Optional welcome message
576
607
  * @param config.skills - Optional array of skills
577
608
  * @param config.webhooks - Optional array of webhooks
578
609
  * @param config.jobs - Optional array of jobs
579
610
  * @param config.preProcessors - Optional array of preprocessors
580
611
  * @param config.postProcessors - Optional array of postprocessors
612
+ * @param config.mcpServers - Optional array of MCP servers
581
613
  */
582
614
  constructor(config) {
583
615
  this.name = config.name;
584
616
  this.persona = config.persona;
585
- this.welcomeMessage = config.welcomeMessage;
586
617
  this.skills = config.skills || [];
587
618
  this.webhooks = config.webhooks || [];
588
619
  this.jobs = config.jobs || [];
589
620
  this.preProcessors = config.preProcessors || [];
590
621
  this.postProcessors = config.postProcessors || [];
622
+ this.mcpServers = config.mcpServers || [];
591
623
  }
592
624
  getName() {
593
625
  return this.name;
@@ -595,9 +627,6 @@ export class LuaAgent {
595
627
  getPersona() {
596
628
  return this.persona;
597
629
  }
598
- getWelcomeMessage() {
599
- return this.welcomeMessage;
600
- }
601
630
  getSkills() {
602
631
  return this.skills;
603
632
  }
@@ -613,4 +642,7 @@ export class LuaAgent {
613
642
  getPostProcessors() {
614
643
  return this.postProcessors;
615
644
  }
645
+ getMCPServers() {
646
+ return this.mcpServers;
647
+ }
616
648
  }
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Agent Management Utilities
3
- * Handles LuaAgent persona and welcome message synchronization with lua.skill.yaml
3
+ * Handles LuaAgent persona synchronization with lua.skill.yaml
4
4
  */
5
5
  /**
6
- * Syncs the agent's name, persona, and welcome message with lua.skill.yaml.
6
+ * Syncs the agent's name and persona with lua.skill.yaml.
7
7
  * This ensures the YAML configuration reflects the agent definition in code.
8
8
  *
9
9
  * @param agentMetadata - Agent metadata extracted from LuaAgent
@@ -11,15 +11,13 @@
11
11
  export declare function syncAgentPersonaWithYaml(agentMetadata: {
12
12
  name: string;
13
13
  persona: string;
14
- welcomeMessage?: string;
15
14
  }): Promise<void>;
16
15
  /**
17
16
  * Reads the agent persona from lua.skill.yaml.
18
17
  * This can be used to ensure the code and YAML are in sync.
19
18
  *
20
- * @returns Agent persona and welcome message from YAML, or null if not found
19
+ * @returns Agent persona from YAML, or null if not found
21
20
  */
22
21
  export declare function readAgentPersonaFromYaml(): {
23
22
  persona?: string;
24
- welcomeMessage?: string;
25
23
  } | null;
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Agent Management Utilities
3
- * Handles LuaAgent persona and welcome message synchronization with lua.skill.yaml
3
+ * Handles LuaAgent persona synchronization with lua.skill.yaml
4
4
  */
5
5
  import fs from "fs";
6
6
  import path from "path";
7
7
  import yaml from "js-yaml";
8
8
  import { COMPILE_FILES, YAML_FORMAT } from '../config/compile.constants.js';
9
9
  /**
10
- * Syncs the agent's name, persona, and welcome message with lua.skill.yaml.
10
+ * Syncs the agent's name and persona with lua.skill.yaml.
11
11
  * This ensures the YAML configuration reflects the agent definition in code.
12
12
  *
13
13
  * @param agentMetadata - Agent metadata extracted from LuaAgent
@@ -20,11 +20,10 @@ export async function syncAgentPersonaWithYaml(agentMetadata) {
20
20
  const yamlContent = fs.readFileSync(yamlPath, 'utf8');
21
21
  config = yaml.load(yamlContent);
22
22
  }
23
- // Update agent section with name, persona, and welcome message
23
+ // Update agent section with persona
24
24
  config.agent = {
25
25
  ...config.agent,
26
- persona: agentMetadata.persona,
27
- welcomeMessage: agentMetadata.welcomeMessage
26
+ persona: agentMetadata.persona
28
27
  };
29
28
  // Store agent name as a comment or in metadata (YAML doesn't have an agentName field)
30
29
  // The agent name is primarily for the LuaAgent in code
@@ -45,7 +44,7 @@ export async function syncAgentPersonaWithYaml(agentMetadata) {
45
44
  * Reads the agent persona from lua.skill.yaml.
46
45
  * This can be used to ensure the code and YAML are in sync.
47
46
  *
48
- * @returns Agent persona and welcome message from YAML, or null if not found
47
+ * @returns Agent persona from YAML, or null if not found
49
48
  */
50
49
  export function readAgentPersonaFromYaml() {
51
50
  const yamlPath = path.join(process.cwd(), COMPILE_FILES.LUA_SKILL_YAML);
@@ -57,8 +56,7 @@ export function readAgentPersonaFromYaml() {
57
56
  const config = yaml.load(yamlContent);
58
57
  if (config.agent) {
59
58
  return {
60
- persona: config.agent.persona,
61
- welcomeMessage: config.agent.welcomeMessage
59
+ persona: config.agent.persona
62
60
  };
63
61
  }
64
62
  }
@@ -65,15 +65,8 @@ export declare function bundlePreProcessor(preprocessor: any, indexFile: any, di
65
65
  */
66
66
  export declare function bundlePostProcessor(postprocessor: any, indexFile: any, distDir: string, project?: any, debugMode?: boolean): Promise<any>;
67
67
  /**
68
- * Extracts execute code and input schema from a tool.
69
- * This function:
70
- * 1. Reads the bundled tool code
71
- * 2. Detects and bundles any Jobs.create() calls within execute
72
- * 3. Extracts the execute function
73
- * 4. Converts Zod schema to JSON Schema format
74
- *
75
- * @param tool - The tool to extract metadata from (mutated with executeCode and inputSchema)
76
- * @param project - The ts-morph Project instance for AST analysis
77
- * @param distDir - Distribution directory for bundling nested jobs
68
+ * Extracts tool code from a bundled tool.
69
+ * Reads the bundled code, wraps it for VM execution (execute and condition),
70
+ * and converts the Zod schema to JSON Schema format.
78
71
  */
79
- export declare function extractExecuteCode(tool: ToolInfo, project: Project, distDir?: string): Promise<void>;
72
+ export declare function extractToolCode(tool: ToolInfo, project: Project): Promise<void>;
@@ -8,7 +8,7 @@ import { build } from "esbuild";
8
8
  import { Project, Node } from "ts-morph";
9
9
  import { writeProgress } from "./cli.js";
10
10
  import { COMPILE_DIRS, COMPILE_FILES, ESBUILD_TOOL_CONFIG, ESBUILD_INDEX_CONFIG, DEFAULT_INPUT_SCHEMA, EXTERNAL_PACKAGES, } from '../config/compile.constants.js';
11
- import { wrapToolForVM, createExecuteFunction, evaluateZodSchemaToJsonSchema } from './compile.js';
11
+ import { wrapExecuteForVM, wrapConditionForVM, evaluateZodSchemaToJsonSchema } from './compile.js';
12
12
  /**
13
13
  * Helper function to remove lua-cli and api-exports imports from source code.
14
14
  * Used when bundling via stdin or temp files where the plugin can't process them.
@@ -248,7 +248,8 @@ export const sandboxGlobalsPlugin = {
248
248
  'Baskets': 'Baskets',
249
249
  'Orders': 'Orders',
250
250
  'Webhooks': 'Webhooks',
251
- 'Jobs': 'Jobs'
251
+ 'Jobs': 'Jobs',
252
+ 'Templates': 'Templates'
252
253
  };
253
254
  // Replace usage of imported names with globals
254
255
  for (const [importName, globalName] of Object.entries(globalMappings)) {
@@ -346,8 +347,6 @@ export async function bundleTool(tool, distDir, modifiedSource, debugMode) {
346
347
  plugins: [sandboxGlobalsPlugin],
347
348
  });
348
349
  }
349
- // Wrap the bundled code for VM execution environment
350
- await wrapToolForVM(outputPath, tool);
351
350
  // Clean up temp file if created (unless in debug mode)
352
351
  if (tempFile && fs.existsSync(tempFile) && !debugMode) {
353
352
  try {
@@ -527,7 +526,7 @@ export async function bundleWebhook(webhook, indexFile, distDir, project, debugM
527
526
  * @returns Compressed base64-encoded bundled code
528
527
  */
529
528
  async function bundleAndCompressWebhookCode(executeFunction, webhookName, distDir, sourceFilePath, debugMode) {
530
- return bundleAndCompressExecuteFunction(executeFunction, webhookName, 'webhook', (bundledCode) => `(async (query, headers, body) => {
529
+ return bundleAndCompressExecuteFunction(executeFunction, webhookName, 'webhook', (bundledCode) => `(async (event) => {
531
530
 
532
531
  // Execute the bundled webhook code
533
532
  ${bundledCode}
@@ -535,8 +534,8 @@ async function bundleAndCompressWebhookCode(executeFunction, webhookName, distDi
535
534
  // Get the execute function from exports
536
535
  const executeFunction = module.exports.default || module.exports;
537
536
 
538
- // Execute with three separate parameters (not an object)
539
- return await executeFunction(query, headers, body);
537
+ // Execute with the unified event object
538
+ return await executeFunction(event);
540
539
  })`, distDir, sourceFilePath, debugMode);
541
540
  }
542
541
  /**
@@ -733,7 +732,6 @@ export async function bundlePreProcessor(preprocessor, indexFile, distDir, proje
733
732
  name: preprocessor.name,
734
733
  version: preprocessor.version,
735
734
  description: preprocessor.description,
736
- context: preprocessor.context,
737
735
  async: preprocessor.async === true ? true : false, // Explicitly set boolean
738
736
  executeFunction,
739
737
  code: compressedCode
@@ -819,8 +817,6 @@ export async function bundlePostProcessor(postprocessor, indexFile, distDir, pro
819
817
  name: postprocessor.name,
820
818
  version: postprocessor.version,
821
819
  description: postprocessor.description,
822
- context: postprocessor.context,
823
- async: postprocessor.async === true ? true : false, // Explicitly set boolean
824
820
  executeFunction,
825
821
  code: compressedCode
826
822
  };
@@ -846,18 +842,11 @@ async function bundleAndCompressProcessorCode(executeFunction, processorName, ty
846
842
  })`, distDir, sourceFilePath, debugMode);
847
843
  }
848
844
  /**
849
- * Extracts execute code and input schema from a tool.
850
- * This function:
851
- * 1. Reads the bundled tool code
852
- * 2. Detects and bundles any Jobs.create() calls within execute
853
- * 3. Extracts the execute function
854
- * 4. Converts Zod schema to JSON Schema format
855
- *
856
- * @param tool - The tool to extract metadata from (mutated with executeCode and inputSchema)
857
- * @param project - The ts-morph Project instance for AST analysis
858
- * @param distDir - Distribution directory for bundling nested jobs
845
+ * Extracts tool code from a bundled tool.
846
+ * Reads the bundled code, wraps it for VM execution (execute and condition),
847
+ * and converts the Zod schema to JSON Schema format.
859
848
  */
860
- export async function extractExecuteCode(tool, project, distDir) {
849
+ export async function extractToolCode(tool, project) {
861
850
  try {
862
851
  const toolSourceFile = project.getSourceFile(tool.filePath);
863
852
  if (!toolSourceFile) {
@@ -891,28 +880,30 @@ export async function extractExecuteCode(tool, project, distDir) {
891
880
  return;
892
881
  }
893
882
  }
894
- // Extract execute code from bundled file
895
- tool.executeCode = extractExecuteCodeFromBundledFile(tool);
896
- // NOTE: Dynamic job bundling moved to source-level processing
897
- // Attempting to extract from minified bundled code is too fragile
883
+ // Read bundled code and wrap for VM execution
884
+ const rawBundledCode = readBundledToolCode(tool);
885
+ if (rawBundledCode) {
886
+ tool.executeCode = wrapExecuteForVM(rawBundledCode, tool.className);
887
+ // Check if tool has condition and wrap it
888
+ const hasCondition = classDecl.getMethod('condition') || classDecl.getProperty('condition');
889
+ if (hasCondition) {
890
+ tool.conditionCode = wrapConditionForVM(rawBundledCode, tool.className);
891
+ }
892
+ }
898
893
  // Extract and convert input schema
899
894
  tool.inputSchema = await extractInputSchema(classDecl, tool);
900
895
  }
901
896
  catch (error) {
902
- console.warn(`Warning: Could not extract execute code for ${tool.className}:`, error);
897
+ console.warn(`Warning: Could not extract tool metadata for ${tool.className}:`, error);
903
898
  }
904
899
  }
905
900
  /**
906
- * Extracts execute code from the bundled tool file.
907
- *
908
- * @param tool - The tool whose bundled code to read
909
- * @returns The execute function code or undefined if not found
901
+ * Reads the raw bundled tool code from the dist directory.
910
902
  */
911
- function extractExecuteCodeFromBundledFile(tool) {
903
+ function readBundledToolCode(tool) {
912
904
  const bundledPath = path.join(process.cwd(), COMPILE_DIRS.DIST, COMPILE_DIRS.TOOLS, `${tool.className}.js`);
913
905
  if (fs.existsSync(bundledPath)) {
914
- const bundledCode = fs.readFileSync(bundledPath, 'utf8');
915
- return createExecuteFunction(bundledCode, tool);
906
+ return fs.readFileSync(bundledPath, 'utf8');
916
907
  }
917
908
  return undefined;
918
909
  }