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
@@ -0,0 +1,86 @@
1
+ /**
2
+ * File Upload Webhook
3
+ *
4
+ * Receives file uploads from external systems and stores them in the CDN.
5
+ *
6
+ * Use cases:
7
+ * - Customer uploads documents via your website form
8
+ * - Integration with document management systems
9
+ * - Receiving images/files from third-party services
10
+ *
11
+ * Webhook URL: https://webhook.heylua.ai/{agentId}/file-upload
12
+ */
13
+
14
+ import { LuaWebhook, CDN, Data, User } from "lua-cli";
15
+ import { z } from "zod";
16
+
17
+ const fileUploadWebhook = new LuaWebhook({
18
+ name: "file-upload",
19
+ description: "Receives file uploads and stores them in CDN",
20
+
21
+ headerSchema: z.object({
22
+ 'content-type': z.string(),
23
+ 'x-api-key': z.string().optional()
24
+ }),
25
+
26
+ bodySchema: z.object({
27
+ filename: z.string(),
28
+ contentType: z.string(),
29
+ data: z.string().describe("Base64 encoded file data"),
30
+ metadata: z.object({
31
+ category: z.string().optional(),
32
+ description: z.string().optional(),
33
+ tags: z.array(z.string()).optional()
34
+ }).optional()
35
+ }),
36
+
37
+ execute: async (event: any) => {
38
+ const { body } = event;
39
+ console.log(`📁 Receiving file upload: ${body.filename}`);
40
+
41
+ // Decode base64 data
42
+ const buffer = Buffer.from(body.data, 'base64');
43
+ const blob = new Blob([buffer], { type: body.contentType });
44
+ const file = new File([blob], body.filename, { type: body.contentType });
45
+
46
+ console.log(`📤 Uploading to CDN: ${file.name} (${file.size} bytes)`);
47
+
48
+ // Upload to CDN
49
+ const fileId = await CDN.upload(file);
50
+
51
+ console.log(`✅ File stored with ID: ${fileId}`);
52
+
53
+ // Store file metadata in custom data for later retrieval
54
+ const fileRecord = await Data.create('uploaded-files', {
55
+ fileId: fileId,
56
+ filename: body.filename,
57
+ contentType: body.contentType,
58
+ size: file.size,
59
+ category: body.metadata?.category || 'uncategorized',
60
+ description: body.metadata?.description,
61
+ tags: body.metadata?.tags || [],
62
+ uploadedAt: new Date().toISOString()
63
+ }, `${body.filename} ${body.metadata?.category || ''} ${body.metadata?.tags?.join(' ') || ''}`);
64
+
65
+ // Notify user about the upload
66
+ const user = await User.get();
67
+ if (user) {
68
+ await user.send([{
69
+ type: "text",
70
+ text: `📁 New file uploaded: ${body.filename}`
71
+ }]);
72
+ }
73
+
74
+ return {
75
+ success: true,
76
+ fileId: fileId,
77
+ recordId: fileRecord.id,
78
+ filename: body.filename,
79
+ size: file.size,
80
+ message: 'File uploaded and stored successfully'
81
+ };
82
+ }
83
+ });
84
+
85
+ export default fileUploadWebhook;
86
+
@@ -5,6 +5,10 @@
5
5
  * It validates signatures, processes payment events, and updates order status.
6
6
  *
7
7
  * Common use case: Stripe webhook for payment confirmations
8
+ *
9
+ * Webhook URLs:
10
+ * https://webhook.heylua.ai/{agentId}/{webhookId}
11
+ * https://webhook.heylua.ai/{agentId}/{webhook-name}
8
12
  */
9
13
 
10
14
  import { LuaWebhook, Orders, Data } from "lua-cli";
@@ -12,10 +16,7 @@ import { z } from "zod";
12
16
 
13
17
  const paymentWebhook = new LuaWebhook({
14
18
  name: "payment-notifications",
15
- version: "1.0.0",
16
19
  description: "Receives payment notifications from payment providers",
17
- context: "This webhook processes payment confirmation events from Stripe or other providers. " +
18
- "It validates the payment, updates order status, and logs the transaction.",
19
20
 
20
21
  // Headers typically include webhook signature for verification
21
22
  headerSchema: z.object({
@@ -40,16 +41,18 @@ const paymentWebhook = new LuaWebhook({
40
41
  })
41
42
  }),
42
43
 
43
- execute: async ({ headers, body }) => {
44
- console.log(`💳 Payment event received:`, body.type);
44
+ execute: async (event: any) => {
45
+ const { headers, body } = event;
46
+ console.log(`💳 Payment event received:`, body?.type);
45
47
 
46
- // In production: Verify Stripe signature
48
+ // In production: Verify Stripe signature manually in your execute function
47
49
  // const signature = headers['stripe-signature'];
48
- // const isValid = verifyStripeSignature(body, signature);
50
+ // const secret = env('STRIPE_WEBHOOK_SECRET');
51
+ // const isValid = verifyStripeSignature(body, signature, secret);
49
52
  // if (!isValid) throw new Error('Invalid signature');
50
53
 
51
- const payment = body.data.object;
52
- const eventType = body.type;
54
+ const payment = body?.data?.object;
55
+ const eventType = body?.type;
53
56
 
54
57
  // Handle payment success
55
58
  if (eventType === 'payment_intent.succeeded') {
@@ -0,0 +1,105 @@
1
+ /**
2
+ * User Event Webhook Example
3
+ *
4
+ * This webhook receives user events from external systems (e.g., CRM, marketing tools).
5
+ * It validates incoming data, stores events for processing, and can send template
6
+ * messages using the Templates API (currently supports WhatsApp templates).
7
+ *
8
+ * Webhook URLs:
9
+ * https://webhook.heylua.ai/{agentId}/{webhookId}
10
+ * https://webhook.heylua.ai/{agentId}/{webhook-name}
11
+ */
12
+
13
+ import { LuaWebhook, Data, Templates } from "lua-cli";
14
+ import { z } from "zod";
15
+
16
+ const userEventWebhook = new LuaWebhook({
17
+ name: "user-events",
18
+ description: "Receives user events from external systems",
19
+
20
+ // Validate query parameters (optional source tracking)
21
+ querySchema: z.object({
22
+ source: z.string().optional(),
23
+ version: z.string().optional()
24
+ }),
25
+
26
+ // Validate headers (require API key for security)
27
+ headerSchema: z.object({
28
+ 'x-api-key': z.string(),
29
+ 'content-type': z.string().optional()
30
+ }),
31
+
32
+ // Validate request body
33
+ bodySchema: z.object({
34
+ eventType: z.enum(['signup', 'update', 'delete']),
35
+ userId: z.string(),
36
+ email: z.string().email(),
37
+ name: z.string().optional(),
38
+ phoneNumber: z.string().optional(),
39
+ channelId: z.string().optional(),
40
+ metadata: z.record(z.any()).optional(),
41
+ timestamp: z.string()
42
+ }),
43
+
44
+ execute: async (event: any) => {
45
+ const { query, headers, body } = event;
46
+ console.log(`📥 Received ${body?.eventType} event for user:`, body?.email);
47
+ console.log(`📍 Source:`, query?.source || 'unknown');
48
+
49
+ // Security: Validate API key (in production, use env variable)
50
+ const expectedKey = process.env.WEBHOOK_API_KEY || 'your-secret-key';
51
+ if (headers?.['x-api-key'] !== expectedKey) {
52
+ throw new Error('Invalid API key');
53
+ }
54
+
55
+ // Store the event in custom data collection
56
+ const eventData = {
57
+ ...body,
58
+ source: query?.source,
59
+ receivedAt: new Date().toISOString(),
60
+ processed: false
61
+ };
62
+
63
+ const result = await Data.create('user-events', eventData,
64
+ `${body?.eventType} ${body?.email} ${body?.name || ''}`
65
+ );
66
+
67
+ console.log('✅ Event stored successfully:', result.id);
68
+
69
+ // Example: Send welcome template on signup using Templates API
70
+ // Uses Templates.whatsapp namespace for WhatsApp templates
71
+ let templateResult = null;
72
+ if (body?.eventType === 'signup' && body?.phoneNumber && body?.channelId) {
73
+ try {
74
+ // Search for a welcome template
75
+ const response = await Templates.whatsapp.list(body.channelId, { search: 'welcome' });
76
+ const welcomeTemplate = response.templates.find((t: any) => t.status === 'APPROVED');
77
+
78
+ if (welcomeTemplate) {
79
+ // Send the template message
80
+ templateResult = await Templates.whatsapp.send(body.channelId, welcomeTemplate.id, {
81
+ phoneNumbers: [body.phoneNumber],
82
+ values: {
83
+ body: { name: body.name || 'there' }
84
+ }
85
+ });
86
+ console.log('📱 Welcome template sent:', templateResult.results[0]?.messages[0]?.id);
87
+ }
88
+ } catch (error: any) {
89
+ console.log('⚠️ Could not send welcome template:', error.message);
90
+ }
91
+ }
92
+
93
+ // Return success response
94
+ return {
95
+ success: true,
96
+ eventId: result.id,
97
+ userId: body?.userId,
98
+ templateSent: templateResult?.totalErrors === 0,
99
+ timestamp: new Date().toISOString()
100
+ };
101
+ }
102
+ });
103
+
104
+ export default userEventWebhook;
105
+