lua-cli 3.1.0-alpha.4 → 3.1.0

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 (97) hide show
  1. package/dist/api/cdn.api.service.d.ts +18 -0
  2. package/dist/api/cdn.api.service.js +43 -0
  3. package/dist/api/custom.data.api.service.d.ts +4 -3
  4. package/dist/api/custom.data.api.service.js +4 -3
  5. package/dist/api/developer.api.service.d.ts +54 -1
  6. package/dist/api/developer.api.service.js +89 -0
  7. package/dist/api/job.api.service.d.ts +10 -0
  8. package/dist/api/job.api.service.js +14 -0
  9. package/dist/api/lazy-instances.d.ts +8 -0
  10. package/dist/api/lazy-instances.js +16 -0
  11. package/dist/api/postprocessor.api.service.d.ts +3 -6
  12. package/dist/api/postprocessor.api.service.js +2 -3
  13. package/dist/api-exports.d.ts +74 -6
  14. package/dist/api-exports.js +87 -7
  15. package/dist/cli/command-definitions.js +34 -7
  16. package/dist/commands/admin.js +1 -1
  17. package/dist/commands/channels.js +1 -1
  18. package/dist/commands/compile.js +23 -4
  19. package/dist/commands/evals.d.ts +8 -0
  20. package/dist/commands/evals.js +41 -0
  21. package/dist/commands/index.d.ts +2 -0
  22. package/dist/commands/index.js +2 -0
  23. package/dist/commands/init.d.ts +10 -1
  24. package/dist/commands/init.js +13 -3
  25. package/dist/commands/mcp.d.ts +18 -0
  26. package/dist/commands/mcp.js +393 -0
  27. package/dist/commands/push.js +172 -14
  28. package/dist/common/data.entry.instance.d.ts +1 -1
  29. package/dist/common/data.entry.instance.js +4 -4
  30. package/dist/common/job.instance.d.ts +24 -0
  31. package/dist/common/job.instance.js +38 -0
  32. package/dist/config/constants.d.ts +1 -0
  33. package/dist/config/constants.js +1 -0
  34. package/dist/index.js +1 -0
  35. package/dist/interfaces/cdn.d.ts +24 -0
  36. package/dist/interfaces/cdn.js +5 -0
  37. package/dist/interfaces/compile.d.ts +1 -0
  38. package/dist/interfaces/custom.data.d.ts +3 -3
  39. package/dist/interfaces/index.d.ts +1 -0
  40. package/dist/interfaces/mcp.d.ts +64 -0
  41. package/dist/interfaces/mcp.js +5 -0
  42. package/dist/types/api-contracts.d.ts +36 -14
  43. package/dist/types/compile.types.d.ts +5 -0
  44. package/dist/types/index.d.ts +2 -2
  45. package/dist/types/index.js +3 -1
  46. package/dist/types/skill.d.ts +120 -13
  47. package/dist/types/skill.js +95 -5
  48. package/dist/utils/bundling.d.ts +4 -11
  49. package/dist/utils/bundling.js +19 -27
  50. package/dist/utils/compile.d.ts +17 -8
  51. package/dist/utils/compile.js +71 -37
  52. package/dist/utils/deployment.js +13 -6
  53. package/dist/utils/dev-api.js +1 -2
  54. package/dist/utils/dev-server.js +1 -1
  55. package/dist/utils/files.d.ts +8 -1
  56. package/dist/utils/files.js +13 -2
  57. package/dist/utils/init-helpers.d.ts +3 -1
  58. package/dist/utils/init-helpers.js +7 -2
  59. package/dist/utils/mcp-server-management.d.ts +23 -0
  60. package/dist/utils/mcp-server-management.js +212 -0
  61. package/dist/utils/sandbox.d.ts +4 -2
  62. package/dist/utils/sandbox.js +22 -3
  63. package/dist/web/app.css +1505 -14
  64. package/dist/web/app.js +79 -64
  65. package/package.json +2 -6
  66. package/template/QUICKSTART.md +57 -761
  67. package/template/README.md +80 -906
  68. package/template/examples/README.md +106 -0
  69. package/template/{src → examples}/jobs/AbandonedBasketProcessorJob.ts +67 -11
  70. package/template/{src → examples}/postprocessors/modifyResponse.ts +3 -3
  71. package/template/{src → examples}/skills/tools/GameScoreTrackerTool.ts +11 -15
  72. package/template/{src → examples}/skills/tools/OrderTool.ts +25 -0
  73. package/template/examples/skills/tools/PremiumFeatureTool.ts +98 -0
  74. package/template/{src → examples}/skills/tools/UserDataTool.ts +34 -0
  75. package/template/examples/webhooks/FileUploadWebhook.ts +86 -0
  76. package/template/package-lock.json +7895 -0
  77. package/template/package.json +1 -1
  78. package/template/src/index.ts +40 -22
  79. /package/template/{src → examples}/jobs/DailyCleanupJob.ts +0 -0
  80. /package/template/{src → examples}/jobs/DataMigrationJob.ts +0 -0
  81. /package/template/{src → examples}/jobs/HealthCheckJob.ts +0 -0
  82. /package/template/{src → examples}/preprocessors/messageMatching.ts +0 -0
  83. /package/template/{src → examples}/services/ApiService.ts +0 -0
  84. /package/template/{src → examples}/services/GetWeather.ts +0 -0
  85. /package/template/{src → examples}/skills/basket.skill.ts +0 -0
  86. /package/template/{src → examples}/skills/product.skill.ts +0 -0
  87. /package/template/{src → examples}/skills/tools/BasketTool.ts +0 -0
  88. /package/template/{src → examples}/skills/tools/CreateInlineJob.ts +0 -0
  89. /package/template/{src → examples}/skills/tools/CreatePostTool.ts +0 -0
  90. /package/template/{src → examples}/skills/tools/CustomDataTool.ts +0 -0
  91. /package/template/{src → examples}/skills/tools/GetWeatherTool.ts +0 -0
  92. /package/template/{src → examples}/skills/tools/PaymentTool.ts +0 -0
  93. /package/template/{src → examples}/skills/tools/ProductsTool.ts +0 -0
  94. /package/template/{src → examples}/skills/tools/SmartBasketTool.ts +0 -0
  95. /package/template/{src → examples}/skills/user.skill.ts +0 -0
  96. /package/template/{src → examples}/webhooks/PaymentWebhook.ts +0 -0
  97. /package/template/{src → examples}/webhooks/UserEventWebhook.ts +0 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * MCP Server Management Utilities
3
+ * Handles MCP server configuration in lua.skill.yaml
4
+ */
5
+ import { YamlConfig } from '../types/compile.types.js';
6
+ /**
7
+ * Ensures all detected MCP servers exist in the YAML config and database.
8
+ * Uses upsert to create or update servers via API during compile (like skills).
9
+ * YAML only tracks name and ID - the full configuration stays in source code.
10
+ *
11
+ * @param mcpServersArray - Array of MCP servers detected from source code (with full config)
12
+ * @param config - The skill configuration from lua.skill.yaml
13
+ * @returns Updated MCP servers array with IDs assigned
14
+ */
15
+ export declare function ensureMCPServersExistInYaml(mcpServersArray: any[], config: YamlConfig): Promise<any[]>;
16
+ /**
17
+ * Syncs the server MCP servers with the YAML configuration.
18
+ * Deletes MCP servers from the server that aren't in YAML (removed from source code).
19
+ *
20
+ * @param config - The skill configuration from lua.skill.yaml
21
+ * @returns Array of messages about sync operations
22
+ */
23
+ export declare function syncServerMCPServersWithYaml(config: YamlConfig): Promise<string[]>;
@@ -0,0 +1,212 @@
1
+ /**
2
+ * MCP Server Management Utilities
3
+ * Handles MCP server configuration in 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
+ import { loadApiKey } from '../services/auth.js';
10
+ import { BASE_URLS } from '../config/constants.js';
11
+ import DeveloperApi from '../api/developer.api.service.js';
12
+ /**
13
+ * Ensures all detected MCP servers exist in the YAML config and database.
14
+ * Uses upsert to create or update servers via API during compile (like skills).
15
+ * YAML only tracks name and ID - the full configuration stays in source code.
16
+ *
17
+ * @param mcpServersArray - Array of MCP servers detected from source code (with full config)
18
+ * @param config - The skill configuration from lua.skill.yaml
19
+ * @returns Updated MCP servers array with IDs assigned
20
+ */
21
+ export async function ensureMCPServersExistInYaml(mcpServersArray, config) {
22
+ const existingServers = config?.mcpServers || [];
23
+ const existingServersMap = createMCPServersMap(existingServers);
24
+ const updatedServersArray = [];
25
+ let yamlUpdated = false;
26
+ // Process each detected MCP server from source code
27
+ for (const server of mcpServersArray) {
28
+ const existingServer = existingServersMap.get(server.name);
29
+ if (existingServer && existingServer.mcpServerId && existingServer.mcpServerId !== '') {
30
+ // Server exists with valid ID - reuse it
31
+ updatedServersArray.push({
32
+ ...server, // Full config from source code
33
+ mcpServerId: existingServer.mcpServerId // ID from YAML
34
+ });
35
+ }
36
+ else {
37
+ // Server doesn't exist or missing ID - upsert via API
38
+ const upsertedServer = await upsertMCPServerViaApi(server, config, existingServers, existingServer);
39
+ updatedServersArray.push(upsertedServer);
40
+ yamlUpdated = true;
41
+ }
42
+ }
43
+ // Update YAML file with tracking info (name + ID only)
44
+ if (yamlUpdated) {
45
+ await updateYamlWithMCPServers(updatedServersArray, config);
46
+ }
47
+ return updatedServersArray;
48
+ }
49
+ /**
50
+ * Creates a map of existing MCP servers for quick lookup by name.
51
+ */
52
+ function createMCPServersMap(existingServers) {
53
+ const map = new Map();
54
+ existingServers.forEach((server) => {
55
+ map.set(server.name, server);
56
+ });
57
+ return map;
58
+ }
59
+ /**
60
+ * Creates or updates an MCP server via the Lua API (upsert by name).
61
+ *
62
+ * @param server - The MCP server to upsert (with full config)
63
+ * @param config - The skill configuration
64
+ * @param existingServers - Array of existing servers (mutated)
65
+ * @param existingServer - The existing server entry if one exists (may be without ID)
66
+ * @returns The server with its ID
67
+ */
68
+ async function upsertMCPServerViaApi(server, config, existingServers, existingServer) {
69
+ try {
70
+ // Validate prerequisites
71
+ const apiKey = await loadApiKey();
72
+ if (!apiKey) {
73
+ throw new Error("No API key found. Run 'lua auth configure' first.");
74
+ }
75
+ const agentId = config?.agent?.agentId;
76
+ if (!agentId) {
77
+ throw new Error("No agent ID found in lua.skill.yaml. Run 'lua init' first.");
78
+ }
79
+ // Prepare server data for upsert
80
+ const serverData = {
81
+ name: server.name,
82
+ transport: server.transport,
83
+ timeout: server.timeout,
84
+ ...(server.transport === 'stdio' ? {
85
+ command: server.command,
86
+ args: server.args,
87
+ env: server.env
88
+ } : {
89
+ url: server.url,
90
+ headers: server.headers
91
+ })
92
+ };
93
+ // Upsert server via API (creates if new, updates if exists by name)
94
+ const developerApi = new DeveloperApi(BASE_URLS.API, apiKey, agentId);
95
+ const result = await developerApi.upsertMCPServer(serverData);
96
+ if (!result.success || !result.data?.id) {
97
+ throw new Error(result.error?.message || 'Failed to upsert MCP server');
98
+ }
99
+ const mcpServerId = result.data.id;
100
+ // Update or add to existing servers array
101
+ if (existingServer) {
102
+ existingServer.mcpServerId = mcpServerId;
103
+ }
104
+ else {
105
+ existingServers.push({
106
+ name: server.name,
107
+ mcpServerId: mcpServerId
108
+ });
109
+ }
110
+ console.log(` ✅ Synced MCP server "${server.name}" with ID: ${mcpServerId}`);
111
+ return {
112
+ ...server,
113
+ mcpServerId: mcpServerId
114
+ };
115
+ }
116
+ catch (error) {
117
+ console.error(` ❌ Failed to sync MCP server "${server.name}":`, error.message);
118
+ throw error;
119
+ }
120
+ }
121
+ /**
122
+ * Updates the lua.skill.yaml file with MCP server tracking (name and ID only).
123
+ * IDs are assigned during compile via API (like skills).
124
+ * The full server configuration remains in the source code as the single source of truth.
125
+ */
126
+ async function updateYamlWithMCPServers(mcpServers, config) {
127
+ const yamlPath = path.join(process.cwd(), COMPILE_FILES.LUA_SKILL_YAML);
128
+ // Read existing content
129
+ let existingConfig = {};
130
+ if (fs.existsSync(yamlPath)) {
131
+ const yamlContent = fs.readFileSync(yamlPath, 'utf8');
132
+ existingConfig = yaml.load(yamlContent);
133
+ }
134
+ // Update MCP servers section - only track name and ID (like skills)
135
+ existingConfig.mcpServers = mcpServers.map(server => ({
136
+ name: server.name,
137
+ mcpServerId: server.mcpServerId // Always present after upsert during compile
138
+ }));
139
+ // Write updated YAML
140
+ const yamlContent = yaml.dump(existingConfig, {
141
+ indent: YAML_FORMAT.INDENT,
142
+ lineWidth: YAML_FORMAT.LINE_WIDTH,
143
+ noRefs: YAML_FORMAT.NO_REFS
144
+ });
145
+ fs.writeFileSync(yamlPath, yamlContent);
146
+ }
147
+ /**
148
+ * Syncs the server MCP servers with the YAML configuration.
149
+ * Deletes MCP servers from the server that aren't in YAML (removed from source code).
150
+ *
151
+ * @param config - The skill configuration from lua.skill.yaml
152
+ * @returns Array of messages about sync operations
153
+ */
154
+ export async function syncServerMCPServersWithYaml(config) {
155
+ const messages = [];
156
+ try {
157
+ // Validate prerequisites
158
+ const apiKey = await loadApiKey();
159
+ if (!apiKey) {
160
+ console.warn("⚠️ No API key found. Skipping server MCP server sync.");
161
+ return messages;
162
+ }
163
+ const agentId = config?.agent?.agentId;
164
+ if (!agentId) {
165
+ console.warn("⚠️ No agent ID found in lua.skill.yaml. Skipping server MCP server sync.");
166
+ return messages;
167
+ }
168
+ // Get MCP servers from server
169
+ const developerApi = new DeveloperApi(BASE_URLS.API, apiKey, agentId);
170
+ const serverMCPServersResponse = await developerApi.getMCPServers();
171
+ if (!serverMCPServersResponse.success || !serverMCPServersResponse.data) {
172
+ console.warn("⚠️ Could not retrieve server MCP servers. Skipping server MCP server sync.");
173
+ return messages;
174
+ }
175
+ const serverMCPServers = serverMCPServersResponse.data;
176
+ const yamlMCPServers = config?.mcpServers || [];
177
+ // Create map of YAML MCP servers by ID for efficient lookup
178
+ const yamlMCPServersMap = new Map(yamlMCPServers
179
+ .filter((server) => server.mcpServerId)
180
+ .map((server) => [server.mcpServerId, server]));
181
+ // Find MCP servers on server that aren't in YAML (removed from source code)
182
+ const serversToDelete = serverMCPServers.filter(serverMCP => !yamlMCPServersMap.has(serverMCP.id));
183
+ // Delete servers that are no longer in YAML
184
+ for (const server of serversToDelete) {
185
+ try {
186
+ const deleteResponse = await developerApi.deleteMCPServer(server.id);
187
+ if (deleteResponse.success) {
188
+ const msg = `✅ Deleted MCP server "${server.name}" from server (removed from source code)`;
189
+ messages.push(msg);
190
+ console.log(msg);
191
+ }
192
+ else {
193
+ const msg = `❌ Failed to delete MCP server "${server.name}": ${deleteResponse.error?.message || 'Unknown error'}`;
194
+ messages.push(msg);
195
+ console.error(msg);
196
+ }
197
+ }
198
+ catch (error) {
199
+ const msg = `❌ Error deleting MCP server "${server.name}": ${error}`;
200
+ messages.push(msg);
201
+ console.error(msg);
202
+ }
203
+ }
204
+ if (serversToDelete.length === 0) {
205
+ console.log("✅ Server MCP servers and YAML are fully in sync");
206
+ }
207
+ }
208
+ catch (error) {
209
+ console.error("❌ Error syncing server MCP servers:", error);
210
+ }
211
+ return messages;
212
+ }
@@ -45,8 +45,10 @@ export declare function loadEnvironmentVariables(): Record<string, string>;
45
45
  * - Data: Custom data collections API
46
46
  * - Baskets: Shopping basket API
47
47
  * - Orders: Order management API
48
- * - Webhooks: Webhook management API (new)
49
- * - Jobs: Job scheduling API (new)
48
+ * - Templates: Template APIs (whatsapp)
49
+ * - CDN: File upload/retrieval API
50
+ * - Jobs: Job scheduling API
51
+ * - AI: AI generation API
50
52
  * - env(): Environment variable access function
51
53
  * - console, fetch, and other standard globals
52
54
  */
@@ -12,6 +12,7 @@ import CustomDataApiService from "../api/custom.data.api.service.js";
12
12
  import WebhookApi from "../api/webhook.api.service.js";
13
13
  import JobApi from "../api/job.api.service.js";
14
14
  import WhatsAppTemplatesApiService from "../api/whatsapp-templates.api.service.js";
15
+ import CdnApiService from "../api/cdn.api.service.js";
15
16
  import { BasketStatus } from "../interfaces/baskets.js";
16
17
  import { OrderStatus } from "../interfaces/orders.js";
17
18
  import { compressCode } from "./compile.js";
@@ -68,8 +69,10 @@ export function loadEnvironmentVariables() {
68
69
  * - Data: Custom data collections API
69
70
  * - Baskets: Shopping basket API
70
71
  * - Orders: Order management API
71
- * - Webhooks: Webhook management API (new)
72
- * - Jobs: Job scheduling API (new)
72
+ * - Templates: Template APIs (whatsapp)
73
+ * - CDN: File upload/retrieval API
74
+ * - Jobs: Job scheduling API
75
+ * - AI: AI generation API
73
76
  * - env(): Environment variable access function
74
77
  * - console, fetch, and other standard globals
75
78
  */
@@ -90,6 +93,7 @@ export function createSandbox(options) {
90
93
  const webhookService = new WebhookApi(BASE_URLS.API, apiKey, agentId);
91
94
  const jobService = new JobApi(BASE_URLS.API, apiKey, agentId);
92
95
  const whatsAppTemplatesService = new WhatsAppTemplatesApiService(BASE_URLS.API, apiKey, agentId);
96
+ const cdnService = new CdnApiService(BASE_URLS.CDN, apiKey);
93
97
  // Override User service methods if needed
94
98
  // Example: Override the update method
95
99
  // const originalUpdate = userService.update.bind(userService);
@@ -197,6 +201,8 @@ export function createSandbox(options) {
197
201
  Headers: globalThis.Headers,
198
202
  Request: globalThis.Request,
199
203
  Response: globalThis.Response,
204
+ File: globalThis.File,
205
+ Blob: globalThis.Blob,
200
206
  FormData: polyfills.FormData,
201
207
  AbortController: polyfills.AbortController,
202
208
  TextEncoder: polyfills.TextEncoder,
@@ -230,6 +236,8 @@ export function createSandbox(options) {
230
236
  Templates: {
231
237
  whatsapp: whatsAppTemplatesService
232
238
  },
239
+ // CDN API
240
+ CDN: cdnService,
233
241
  // Jobs API
234
242
  Jobs: {
235
243
  create: async (config) => {
@@ -258,7 +266,8 @@ export function createSandbox(options) {
258
266
  activate: config.activate ?? true
259
267
  });
260
268
  },
261
- getJob: async (jobId) => jobService.getJob(jobId)
269
+ getJob: async (jobId) => jobService.getJob(jobId),
270
+ getAll: async (options = {}) => jobService.getAll(options)
262
271
  },
263
272
  // Environment variables function
264
273
  env: (key) => envVars[key],
@@ -327,6 +336,8 @@ try{
327
336
  global.Response = Response;
328
337
  global.URL = URL;
329
338
  global.URLSearchParams = URLSearchParams;
339
+ global.File = File;
340
+ global.Blob = Blob;
330
341
  }
331
342
  `, context);
332
343
  vm.runInContext(commonJsWrapper, context);
@@ -374,6 +385,8 @@ try{
374
385
  global.Response = Response;
375
386
  global.URL = URL;
376
387
  global.URLSearchParams = URLSearchParams;
388
+ global.File = File;
389
+ global.Blob = Blob;
377
390
  }
378
391
  `, context);
379
392
  vm.runInContext(commonJsWrapper, context);
@@ -449,6 +462,8 @@ try{
449
462
  global.Response = Response;
450
463
  global.URL = URL;
451
464
  global.URLSearchParams = URLSearchParams;
465
+ global.File = File;
466
+ global.Blob = Blob;
452
467
  }
453
468
  `, context);
454
469
  vm.runInContext(commonJsWrapper, context);
@@ -501,6 +516,8 @@ try{
501
516
  global.Response = Response;
502
517
  global.URL = URL;
503
518
  global.URLSearchParams = URLSearchParams;
519
+ global.File = File;
520
+ global.Blob = Blob;
504
521
  }
505
522
  `, context);
506
523
  vm.runInContext(commonJsWrapper, context);
@@ -553,6 +570,8 @@ try{
553
570
  global.Response = Response;
554
571
  global.URL = URL;
555
572
  global.URLSearchParams = URLSearchParams;
573
+ global.File = File;
574
+ global.Blob = Blob;
556
575
  }
557
576
  `, context);
558
577
  vm.runInContext(commonJsWrapper, context);