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
@@ -143,3 +143,480 @@ export class LuaSkill {
143
143
  return tool.execute(validatedInput);
144
144
  }
145
145
  }
146
+ /**
147
+ * Lua Job class.
148
+ * Main class for building scheduled jobs (cron jobs, one-time tasks, intervals).
149
+ *
150
+ * A job is a scheduled task that executes at specific times or intervals.
151
+ * Jobs can run once, on a recurring schedule (cron), or at fixed intervals.
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * import { LuaJob } from 'lua-cli';
156
+ *
157
+ * // Daily cleanup job at 2 AM
158
+ * const dailyCleanup = new LuaJob({
159
+ * name: 'daily-cleanup',
160
+ * version: '1.0.0',
161
+ * description: "Daily database cleanup job",
162
+ * context: "Runs at 2 AM daily to clean up old records and optimize tables.",
163
+ * schedule: {
164
+ * type: 'cron',
165
+ * expression: '0 2 * * *', // 2 AM every day
166
+ * timezone: 'America/New_York'
167
+ * },
168
+ * timeout: 600, // 10 minutes
169
+ * retry: {
170
+ * maxAttempts: 3,
171
+ * backoffSeconds: 60
172
+ * },
173
+ * execute: async () => {
174
+ * // Cleanup logic
175
+ * console.log('Running cleanup...');
176
+ * return { recordsDeleted: 150 };
177
+ * }
178
+ * });
179
+ *
180
+ * // One-time job
181
+ * const sendWelcome = new LuaJob({
182
+ * name: 'send-welcome',
183
+ * version: '1.0.0',
184
+ * description: "Send welcome email to new users",
185
+ * context: "Scheduled one-time task to send welcome emails.",
186
+ * schedule: {
187
+ * type: 'once',
188
+ * executeAt: new Date('2025-12-31T10:00:00Z')
189
+ * },
190
+ * execute: async () => {
191
+ * console.log('Sending welcome emails...');
192
+ * return { emailsSent: 100 };
193
+ * }
194
+ * });
195
+ *
196
+ * // Interval-based job (every 5 minutes)
197
+ * const healthCheck = new LuaJob({
198
+ * name: 'health-check',
199
+ * version: '1.0.0',
200
+ * description: "System health check",
201
+ * context: "Runs every 5 minutes to check system health.",
202
+ * schedule: {
203
+ * type: 'interval',
204
+ * seconds: 300 // 5 minutes
205
+ * },
206
+ * execute: async () => {
207
+ * return { status: 'healthy' };
208
+ * }
209
+ * });
210
+ * ```
211
+ */
212
+ export class LuaJob {
213
+ /**
214
+ * Creates a new LuaJob instance.
215
+ *
216
+ * @param config - Configuration object containing job metadata
217
+ * @param config.name - Job name (optional, defaults to 'unnamed-job')
218
+ * @param config.version - Job version (optional, defaults to '1.0.0')
219
+ * @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
+ * @param config.schedule - Schedule configuration (cron, once, or interval)
222
+ * @param config.timeout - Optional timeout in seconds (default: 300)
223
+ * @param config.retry - Optional retry configuration
224
+ * @param config.metadata - Optional metadata for the job
225
+ * @param config.execute - Function that processes the job (receives job instance as parameter)
226
+ */
227
+ constructor(config) {
228
+ this.name = config.name || 'unnamed-job';
229
+ this.version = config.version || '1.0.0';
230
+ this.description = config.description;
231
+ this.context = config.context;
232
+ this.schedule = config.schedule;
233
+ this.timeout = config.timeout || 300;
234
+ this.retry = config.retry;
235
+ this.metadata = config.metadata;
236
+ this.executeFunction = config.execute;
237
+ }
238
+ /**
239
+ * Gets the job name.
240
+ */
241
+ getName() {
242
+ return this.name;
243
+ }
244
+ /**
245
+ * Gets the job version.
246
+ */
247
+ getVersion() {
248
+ return this.version;
249
+ }
250
+ /**
251
+ * Gets the job description.
252
+ */
253
+ getDescription() {
254
+ return this.description;
255
+ }
256
+ /**
257
+ * Gets the job context.
258
+ */
259
+ getContext() {
260
+ return this.context;
261
+ }
262
+ /**
263
+ * Gets the job schedule.
264
+ */
265
+ getSchedule() {
266
+ return this.schedule;
267
+ }
268
+ /**
269
+ * Gets the job timeout in seconds.
270
+ */
271
+ getTimeout() {
272
+ return this.timeout;
273
+ }
274
+ /**
275
+ * Gets the retry configuration.
276
+ */
277
+ getRetry() {
278
+ return this.retry;
279
+ }
280
+ /**
281
+ * Gets the job metadata.
282
+ */
283
+ getMetadata() {
284
+ return this.metadata;
285
+ }
286
+ /**
287
+ * Executes the job.
288
+ * This is called by the scheduler at the appropriate time.
289
+ *
290
+ * @returns Promise resolving to job execution result
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const result = await job.execute();
295
+ * console.log('Job completed:', result);
296
+ * ```
297
+ */
298
+ async execute() {
299
+ return this.executeFunction();
300
+ }
301
+ }
302
+ /**
303
+ * Lua Webhook class.
304
+ * Main class for building webhooks with validated inputs.
305
+ *
306
+ * A webhook is an HTTP endpoint that can receive requests with validated
307
+ * query parameters, headers, and body. The execute function processes the
308
+ * validated input and returns a response.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * import { LuaWebhook } from 'lua-cli';
313
+ * import { z } from 'zod';
314
+ *
315
+ * const webhook = new LuaWebhook({
316
+ * name: 'user-created',
317
+ * version: '1.0.0',
318
+ * description: "Webhook that handles user creation events",
319
+ * context: "This webhook processes new user registration events. " +
320
+ * "It validates the user data and sends welcome emails.",
321
+ * querySchema: z.object({
322
+ * source: z.string().optional()
323
+ * }),
324
+ * headerSchema: z.object({
325
+ * 'x-api-key': z.string(),
326
+ * 'content-type': z.string().optional()
327
+ * }),
328
+ * bodySchema: z.object({
329
+ * userId: z.string(),
330
+ * email: z.string().email(),
331
+ * name: z.string()
332
+ * }),
333
+ * execute: async ({ query, headers, body }) => {
334
+ * // Process the webhook...
335
+ * console.log('New user:', body.email);
336
+ * return { success: true, userId: body.userId };
337
+ * }
338
+ * });
339
+ *
340
+ * // Execute the webhook with validated input
341
+ * const result = await webhook.execute({
342
+ * query: { source: 'mobile' },
343
+ * headers: { 'x-api-key': 'secret-key' },
344
+ * body: { userId: '123', email: 'user@example.com', name: 'John' }
345
+ * });
346
+ * ```
347
+ */
348
+ export class LuaWebhook {
349
+ /**
350
+ * Creates a new LuaWebhook instance.
351
+ *
352
+ * @param config - Configuration object containing webhook metadata
353
+ * @param config.name - Webhook name (optional, defaults to 'unnamed-webhook')
354
+ * @param config.version - Webhook version (optional, defaults to '1.0.0')
355
+ * @param config.description - Short description of what the webhook does (1-2 sentences)
356
+ * @param config.context - Detailed explanation of the webhook's purpose and behavior
357
+ * @param config.querySchema - Optional Zod schema for query parameter validation
358
+ * @param config.headerSchema - Optional Zod schema for header validation
359
+ * @param config.bodySchema - Optional Zod schema for body validation
360
+ * @param config.execute - Function that processes the webhook request
361
+ */
362
+ constructor(config) {
363
+ this.name = config.name || 'unnamed-webhook';
364
+ this.version = config.version || '1.0.0';
365
+ this.description = config.description;
366
+ this.context = config.context;
367
+ this.querySchema = config.querySchema;
368
+ this.headerSchema = config.headerSchema;
369
+ this.bodySchema = config.bodySchema;
370
+ this.executeFunction = config.execute;
371
+ }
372
+ /**
373
+ * Gets the webhook name.
374
+ */
375
+ getName() {
376
+ return this.name;
377
+ }
378
+ /**
379
+ * Gets the webhook version.
380
+ */
381
+ getVersion() {
382
+ return this.version;
383
+ }
384
+ /**
385
+ * Gets the webhook description.
386
+ */
387
+ getDescription() {
388
+ return this.description;
389
+ }
390
+ /**
391
+ * Gets the webhook context.
392
+ */
393
+ getContext() {
394
+ return this.context;
395
+ }
396
+ /**
397
+ * Executes the webhook with validated input.
398
+ * Validates query parameters, headers, and body against their respective schemas
399
+ * before executing the webhook function.
400
+ *
401
+ * @param input - Input object containing query, headers, and/or body
402
+ * @param input.query - Query parameters object
403
+ * @param input.headers - Headers object
404
+ * @param input.body - Request body
405
+ * @returns Promise resolving to webhook execution result
406
+ * @throws Error if validation fails for any input
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * const result = await webhook.execute({
411
+ * query: { limit: '10' },
412
+ * headers: { 'x-api-key': 'secret' },
413
+ * body: { data: 'value' }
414
+ * });
415
+ * ```
416
+ */
417
+ async execute(input) {
418
+ const validatedInput = {};
419
+ // Validate query parameters if schema is provided
420
+ if (this.querySchema) {
421
+ try {
422
+ validatedInput.query = this.querySchema.parse(input.query || {});
423
+ }
424
+ catch (error) {
425
+ throw new Error(`Query parameter validation failed: ${error}`);
426
+ }
427
+ }
428
+ else {
429
+ validatedInput.query = input.query;
430
+ }
431
+ // Validate headers if schema is provided
432
+ if (this.headerSchema) {
433
+ try {
434
+ validatedInput.headers = this.headerSchema.parse(input.headers || {});
435
+ }
436
+ catch (error) {
437
+ throw new Error(`Header validation failed: ${error}`);
438
+ }
439
+ }
440
+ else {
441
+ validatedInput.headers = input.headers;
442
+ }
443
+ // Validate body if schema is provided
444
+ if (this.bodySchema) {
445
+ try {
446
+ validatedInput.body = this.bodySchema.parse(input.body);
447
+ }
448
+ catch (error) {
449
+ throw new Error(`Body validation failed: ${error}`);
450
+ }
451
+ }
452
+ else {
453
+ validatedInput.body = input.body;
454
+ }
455
+ // Execute the webhook function with validated input
456
+ return this.executeFunction(validatedInput);
457
+ }
458
+ }
459
+ /**
460
+ * PreProcessor class.
461
+ * Processes user messages before they reach the agent.
462
+ *
463
+ * @example
464
+ * ```typescript
465
+ * const languageDetector = new PreProcessor({
466
+ * name: 'language-detector',
467
+ * version: '1.0.0',
468
+ * description: 'Detects and translates messages',
469
+ * context: 'Detects language and translates to English if needed',
470
+ * execute: async (user, message, channel) => {
471
+ * const language = await detectLanguage(message);
472
+ * if (language !== 'en') {
473
+ * return await translate(message, 'en');
474
+ * }
475
+ * return message;
476
+ * }
477
+ * });
478
+ * ```
479
+ */
480
+ export class PreProcessor {
481
+ constructor(config) {
482
+ this.name = config.name || 'unnamed-preprocessor';
483
+ this.version = config.version || '1.0.0';
484
+ this.description = config.description;
485
+ this.context = config.context;
486
+ this.executeFunction = config.execute;
487
+ }
488
+ getName() {
489
+ return this.name;
490
+ }
491
+ getVersion() {
492
+ return this.version;
493
+ }
494
+ getDescription() {
495
+ return this.description;
496
+ }
497
+ getContext() {
498
+ return this.context;
499
+ }
500
+ async execute(user, message, channel) {
501
+ return this.executeFunction(user, message, channel);
502
+ }
503
+ }
504
+ /**
505
+ * PostProcessor class.
506
+ * Processes agent responses before they reach the user.
507
+ *
508
+ * @example
509
+ * ```typescript
510
+ * const responseFormatter = new PostProcessor({
511
+ * name: 'response-formatter',
512
+ * version: '1.0.0',
513
+ * description: 'Formats responses with branding',
514
+ * context: 'Adds company signature to all responses',
515
+ * execute: async (user, message, response, channel) => {
516
+ * return response + '\n\n---\nPowered by Acme Corp';
517
+ * }
518
+ * });
519
+ * ```
520
+ */
521
+ export class PostProcessor {
522
+ constructor(config) {
523
+ this.name = config.name || 'unnamed-postprocessor';
524
+ this.version = config.version || '1.0.0';
525
+ this.description = config.description;
526
+ this.context = config.context;
527
+ this.executeFunction = config.execute;
528
+ }
529
+ getName() {
530
+ return this.name;
531
+ }
532
+ getVersion() {
533
+ return this.version;
534
+ }
535
+ getDescription() {
536
+ return this.description;
537
+ }
538
+ getContext() {
539
+ return this.context;
540
+ }
541
+ async execute(user, message, response, channel) {
542
+ return this.executeFunction(user, message, response, channel);
543
+ }
544
+ }
545
+ /**
546
+ * LuaAgent class.
547
+ * Unified agent configuration that consolidates skills, webhooks, jobs, and processors.
548
+ *
549
+ * This is the simplest way to define an agent. Instead of exporting multiple separate
550
+ * components, you create one LuaAgent that contains everything.
551
+ *
552
+ * @example
553
+ * ```typescript
554
+ * import { LuaAgent, LuaSkill, LuaJob, LuaWebhook } from 'lua-cli';
555
+ *
556
+ * // Define your skills, jobs, webhooks in separate files
557
+ * import { userSkill } from './skills/user-skill';
558
+ * import { healthCheckJob } from './jobs/health-check';
559
+ * import { webhookHandler } from './webhooks/handler';
560
+ *
561
+ * // Create a single agent configuration
562
+ * export const agent = new LuaAgent({
563
+ * name: 'my-assistant',
564
+ * persona: 'You are a helpful AI assistant that can manage users and products.',
565
+ * welcomeMessage: 'Hello! How can I help you today?',
566
+ * skills: [userSkill],
567
+ * jobs: [healthCheckJob],
568
+ * webhooks: [webhookHandler],
569
+ * preProcessors: [],
570
+ * postProcessors: []
571
+ * });
572
+ * ```
573
+ */
574
+ export class LuaAgent {
575
+ /**
576
+ * Creates a new LuaAgent instance.
577
+ *
578
+ * @param config - Agent configuration
579
+ * @param config.name - Agent name
580
+ * @param config.persona - Agent persona (behavior and personality)
581
+ * @param config.welcomeMessage - Optional welcome message
582
+ * @param config.skills - Optional array of skills
583
+ * @param config.webhooks - Optional array of webhooks
584
+ * @param config.jobs - Optional array of jobs
585
+ * @param config.preProcessors - Optional array of preprocessors
586
+ * @param config.postProcessors - Optional array of postprocessors
587
+ */
588
+ constructor(config) {
589
+ this.name = config.name;
590
+ this.persona = config.persona;
591
+ this.welcomeMessage = config.welcomeMessage;
592
+ this.skills = config.skills || [];
593
+ this.webhooks = config.webhooks || [];
594
+ this.jobs = config.jobs || [];
595
+ this.preProcessors = config.preProcessors || [];
596
+ this.postProcessors = config.postProcessors || [];
597
+ }
598
+ getName() {
599
+ return this.name;
600
+ }
601
+ getPersona() {
602
+ return this.persona;
603
+ }
604
+ getWelcomeMessage() {
605
+ return this.welcomeMessage;
606
+ }
607
+ getSkills() {
608
+ return this.skills;
609
+ }
610
+ getWebhooks() {
611
+ return this.webhooks;
612
+ }
613
+ getJobs() {
614
+ return this.jobs;
615
+ }
616
+ getPreProcessors() {
617
+ return this.preProcessors;
618
+ }
619
+ getPostProcessors() {
620
+ return this.postProcessors;
621
+ }
622
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Agent Management Utilities
3
+ * Handles LuaAgent persona and welcome message synchronization with lua.skill.yaml
4
+ */
5
+ /**
6
+ * Syncs the agent's persona and welcome message with lua.skill.yaml.
7
+ * This ensures the YAML configuration reflects the agent definition in code.
8
+ *
9
+ * @param agentMetadata - Agent metadata extracted from LuaAgent
10
+ */
11
+ export declare function syncAgentPersonaWithYaml(agentMetadata: {
12
+ name: string;
13
+ persona: string;
14
+ welcomeMessage?: string;
15
+ }): Promise<void>;
16
+ /**
17
+ * Reads the agent persona from lua.skill.yaml.
18
+ * This can be used to ensure the code and YAML are in sync.
19
+ *
20
+ * @returns Agent persona and welcome message from YAML, or null if not found
21
+ */
22
+ export declare function readAgentPersonaFromYaml(): {
23
+ persona?: string;
24
+ welcomeMessage?: string;
25
+ } | null;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Agent Management Utilities
3
+ * Handles LuaAgent persona and welcome message synchronization with lua.skill.yaml
4
+ */
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import yaml from "js-yaml";
8
+ import { COMPILE_FILES, YAML_FORMAT } from '../config/compile.constants.js';
9
+ /**
10
+ * Syncs the agent's persona and welcome message with lua.skill.yaml.
11
+ * This ensures the YAML configuration reflects the agent definition in code.
12
+ *
13
+ * @param agentMetadata - Agent metadata extracted from LuaAgent
14
+ */
15
+ export async function syncAgentPersonaWithYaml(agentMetadata) {
16
+ const yamlPath = path.join(process.cwd(), COMPILE_FILES.LUA_SKILL_YAML);
17
+ // Read existing YAML config
18
+ let config = {};
19
+ if (fs.existsSync(yamlPath)) {
20
+ const yamlContent = fs.readFileSync(yamlPath, 'utf8');
21
+ config = yaml.load(yamlContent);
22
+ }
23
+ // Update agent section with persona and welcome message
24
+ config.agent = {
25
+ ...config.agent,
26
+ persona: agentMetadata.persona,
27
+ welcomeMessage: agentMetadata.welcomeMessage
28
+ };
29
+ // Write updated YAML with consistent formatting
30
+ const yamlContent = yaml.dump(config, {
31
+ indent: YAML_FORMAT.INDENT,
32
+ lineWidth: YAML_FORMAT.LINE_WIDTH,
33
+ noRefs: YAML_FORMAT.NO_REFS,
34
+ replacer: (key, value) => {
35
+ // Replace undefined values with empty strings
36
+ return value === undefined ? '' : value;
37
+ }
38
+ });
39
+ fs.writeFileSync(yamlPath, yamlContent);
40
+ console.log(`✅ Synced agent persona to lua.skill.yaml`);
41
+ }
42
+ /**
43
+ * Reads the agent persona from lua.skill.yaml.
44
+ * This can be used to ensure the code and YAML are in sync.
45
+ *
46
+ * @returns Agent persona and welcome message from YAML, or null if not found
47
+ */
48
+ export function readAgentPersonaFromYaml() {
49
+ const yamlPath = path.join(process.cwd(), COMPILE_FILES.LUA_SKILL_YAML);
50
+ if (!fs.existsSync(yamlPath)) {
51
+ return null;
52
+ }
53
+ try {
54
+ const yamlContent = fs.readFileSync(yamlPath, 'utf8');
55
+ const config = yaml.load(yamlContent);
56
+ if (config.agent) {
57
+ return {
58
+ persona: config.agent.persona,
59
+ welcomeMessage: config.agent.welcomeMessage
60
+ };
61
+ }
62
+ }
63
+ catch (error) {
64
+ console.warn(`Warning: Could not read agent persona from lua.skill.yaml: ${error}`);
65
+ }
66
+ return null;
67
+ }
@@ -2,8 +2,8 @@
2
2
  * Bundling Utilities
3
3
  * Handles esbuild bundling of tools and main index
4
4
  */
5
- import { ToolInfo } from '../interfaces/compile.js';
6
5
  import { Project } from "ts-morph";
6
+ import { ToolInfo } from '../interfaces/compile.js';
7
7
  /**
8
8
  * Bundles a tool's TypeScript code into a standalone JavaScript file.
9
9
  * Uses esbuild to:
@@ -11,6 +11,8 @@ import { Project } from "ts-morph";
11
11
  * - Minify code for production
12
12
  * - Wrap for VM execution
13
13
  *
14
+ * For inline tools (defined in index.ts), creates a temporary export file first.
15
+ *
14
16
  * @param tool - The tool to bundle
15
17
  * @param distDir - The distribution directory for output
16
18
  */
@@ -23,6 +25,34 @@ export declare function bundleTool(tool: ToolInfo, distDir: string): Promise<voi
23
25
  * @param distDir - The distribution directory for output
24
26
  */
25
27
  export declare function bundleMainIndex(indexPath: string, distDir: string): Promise<void>;
28
+ /**
29
+ * Extracts and bundles webhook execute function and schemas.
30
+ *
31
+ * @param webhook - Webhook metadata with name and version
32
+ * @param indexFile - The TypeScript source file containing the webhook
33
+ * @param distDir - Distribution directory for output
34
+ * @param project - Optional ts-morph Project for resolving imports
35
+ * @returns Webhook with bundled code and schemas
36
+ */
37
+ export declare function bundleWebhook(webhook: any, indexFile: any, distDir: string, project?: any): Promise<any>;
38
+ /**
39
+ * Extracts and bundles job execute function.
40
+ *
41
+ * @param job - Job metadata with name and version
42
+ * @param indexFile - The TypeScript source file containing the job
43
+ * @param distDir - Distribution directory for output
44
+ * @param project - Optional ts-morph Project for resolving imports
45
+ * @returns Job with bundled code
46
+ */
47
+ export declare function bundleJob(job: any, indexFile: any, distDir: string, project?: any): Promise<any>;
48
+ /**
49
+ * Bundles and compresses preprocessor execute function code.
50
+ */
51
+ export declare function bundlePreProcessor(preprocessor: any, indexFile: any, distDir: string, project?: any): Promise<any>;
52
+ /**
53
+ * Bundles and compresses postprocessor execute function code.
54
+ */
55
+ export declare function bundlePostProcessor(postprocessor: any, indexFile: any, distDir: string, project?: any): Promise<any>;
26
56
  /**
27
57
  * Extracts execute code and input schema from a tool.
28
58
  * This function: