lua-cli 2.5.8 → 3.0.0-alpha.10
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.
- package/dist/api/chat.api.service.d.ts +8 -0
- package/dist/api/chat.api.service.js +50 -0
- package/dist/api/job.api.service.d.ts +219 -0
- package/dist/api/job.api.service.js +216 -0
- package/dist/api/lazy-instances.d.ts +24 -0
- package/dist/api/lazy-instances.js +48 -0
- package/dist/api/postprocessor.api.service.d.ts +158 -0
- package/dist/api/postprocessor.api.service.js +111 -0
- package/dist/api/preprocessor.api.service.d.ts +158 -0
- package/dist/api/preprocessor.api.service.js +111 -0
- package/dist/api/user.data.api.service.d.ts +13 -0
- package/dist/api/user.data.api.service.js +20 -0
- package/dist/api/webhook.api.service.d.ts +151 -0
- package/dist/api/webhook.api.service.js +134 -0
- package/dist/api-exports.d.ts +176 -41
- package/dist/api-exports.js +195 -21
- package/dist/cli/command-definitions.js +85 -8
- package/dist/commands/chat.js +73 -36
- package/dist/commands/compile.js +140 -7
- package/dist/commands/dev.js +23 -2
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.js +4 -0
- package/dist/commands/init.js +53 -7
- package/dist/commands/jobs.d.ts +20 -0
- package/dist/commands/jobs.js +533 -0
- package/dist/commands/logs.js +2 -5
- package/dist/commands/postprocessors.d.ts +8 -0
- package/dist/commands/postprocessors.js +431 -0
- package/dist/commands/preprocessors.d.ts +8 -0
- package/dist/commands/preprocessors.js +431 -0
- package/dist/commands/push.d.ts +3 -2
- package/dist/commands/push.js +1216 -7
- package/dist/commands/test.d.ts +9 -18
- package/dist/commands/test.js +574 -82
- package/dist/commands/webhooks.d.ts +18 -0
- package/dist/commands/webhooks.js +424 -0
- package/dist/common/job.instance.d.ts +80 -0
- package/dist/common/job.instance.js +116 -0
- package/dist/common/user.instance.d.ts +1 -0
- package/dist/common/user.instance.js +9 -0
- package/dist/config/constants.d.ts +4 -3
- package/dist/config/constants.js +10 -8
- package/dist/interfaces/agent.d.ts +2 -1
- package/dist/interfaces/chat.d.ts +52 -1
- package/dist/interfaces/index.d.ts +10 -0
- package/dist/interfaces/index.js +7 -0
- package/dist/interfaces/jobs.d.ts +193 -0
- package/dist/interfaces/jobs.js +5 -0
- package/dist/interfaces/postprocessors.d.ts +35 -0
- package/dist/interfaces/postprocessors.js +4 -0
- package/dist/interfaces/preprocessors.d.ts +35 -0
- package/dist/interfaces/preprocessors.js +4 -0
- package/dist/interfaces/webhooks.d.ts +104 -0
- package/dist/interfaces/webhooks.js +5 -0
- package/dist/services/auth.d.ts +8 -2
- package/dist/services/auth.js +35 -3
- package/dist/types/api-contracts.d.ts +5 -0
- package/dist/types/compile.types.d.ts +49 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/skill.d.ts +521 -0
- package/dist/types/skill.js +471 -0
- package/dist/utils/agent-management.d.ts +25 -0
- package/dist/utils/agent-management.js +67 -0
- package/dist/utils/bundling.d.ts +44 -5
- package/dist/utils/bundling.js +723 -23
- package/dist/utils/compile.d.ts +63 -0
- package/dist/utils/compile.js +712 -36
- package/dist/utils/deployment.d.ts +2 -1
- package/dist/utils/deployment.js +16 -2
- package/dist/utils/dev-api.d.ts +42 -2
- package/dist/utils/dev-api.js +177 -4
- package/dist/utils/dev-server.d.ts +1 -1
- package/dist/utils/dev-server.js +4 -4
- package/dist/utils/dynamic-job-bundler.d.ts +17 -0
- package/dist/utils/dynamic-job-bundler.js +143 -0
- package/dist/utils/init-agent.d.ts +3 -1
- package/dist/utils/init-agent.js +6 -4
- package/dist/utils/init-prompts.d.ts +2 -1
- package/dist/utils/init-prompts.js +14 -9
- package/dist/utils/job-management.d.ts +24 -0
- package/dist/utils/job-management.js +264 -0
- package/dist/utils/postprocessor-management.d.ts +9 -0
- package/dist/utils/postprocessor-management.js +118 -0
- package/dist/utils/pre-bundle-jobs.d.ts +26 -0
- package/dist/utils/pre-bundle-jobs.js +176 -0
- package/dist/utils/preprocessor-management.d.ts +9 -0
- package/dist/utils/preprocessor-management.js +118 -0
- package/dist/utils/sandbox-storage.d.ts +48 -0
- package/dist/utils/sandbox-storage.js +114 -0
- package/dist/utils/sandbox.d.ts +61 -1
- package/dist/utils/sandbox.js +299 -72
- package/dist/utils/tool-detection.d.ts +3 -2
- package/dist/utils/tool-detection.js +18 -4
- package/dist/utils/webhook-management.d.ts +24 -0
- package/dist/utils/webhook-management.js +256 -0
- package/package.json +1 -1
- package/template/README.md +30 -2
- package/template/env.example +5 -0
- package/template/lua.skill.yaml +47 -0
- package/template/package-lock.json +10505 -0
- package/template/package.json +2 -1
- package/template/src/index.ts +103 -2
- package/template/src/jobs/AbandonedBasketProcessorJob.ts +139 -0
- package/template/src/jobs/DailyCleanupJob.ts +100 -0
- package/template/src/jobs/DataMigrationJob.ts +133 -0
- package/template/src/jobs/HealthCheckJob.ts +87 -0
- package/template/src/tools/CreateInlineJob.ts +42 -0
- package/template/src/tools/GameScoreTrackerTool.ts +356 -0
- package/template/src/tools/SmartBasketTool.ts +188 -0
- package/template/src/webhooks/PaymentWebhook.ts +113 -0
- package/template/src/webhooks/UserEventWebhook.ts +77 -0
- package/API_REFERENCE.md +0 -1408
- package/CHANGELOG.md +0 -236
- package/CLI_REFERENCE.md +0 -908
- package/GETTING_STARTED.md +0 -1040
- package/INSTANCE_TYPES.md +0 -1158
- package/README.md +0 -865
- package/TEMPLATE_GUIDE.md +0 -1398
- package/USER_DATA_INSTANCE.md +0 -621
- package/template/TOOL_EXAMPLES.md +0 -655
package/dist/types/skill.js
CHANGED
|
@@ -143,3 +143,474 @@ 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
|
+
/**
|
|
288
|
+
* Lua Webhook class.
|
|
289
|
+
* Main class for building webhooks with validated inputs.
|
|
290
|
+
*
|
|
291
|
+
* A webhook is an HTTP endpoint that can receive requests with validated
|
|
292
|
+
* query parameters, headers, and body. The execute function processes the
|
|
293
|
+
* validated input and returns a response.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* import { LuaWebhook } from 'lua-cli';
|
|
298
|
+
* import { z } from 'zod';
|
|
299
|
+
*
|
|
300
|
+
* const webhook = new LuaWebhook({
|
|
301
|
+
* name: 'user-created',
|
|
302
|
+
* version: '1.0.0',
|
|
303
|
+
* 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
|
+
* querySchema: z.object({
|
|
307
|
+
* source: z.string().optional()
|
|
308
|
+
* }),
|
|
309
|
+
* headerSchema: z.object({
|
|
310
|
+
* 'x-api-key': z.string(),
|
|
311
|
+
* 'content-type': z.string().optional()
|
|
312
|
+
* }),
|
|
313
|
+
* bodySchema: z.object({
|
|
314
|
+
* userId: z.string(),
|
|
315
|
+
* email: z.string().email(),
|
|
316
|
+
* name: z.string()
|
|
317
|
+
* }),
|
|
318
|
+
* execute: async (query, headers, body) => {
|
|
319
|
+
* // Process the webhook...
|
|
320
|
+
* console.log('New user:', body.email);
|
|
321
|
+
* return { success: true, userId: body.userId };
|
|
322
|
+
* }
|
|
323
|
+
* });
|
|
324
|
+
*
|
|
325
|
+
* // Execute the webhook with validated inputs
|
|
326
|
+
* const result = await webhook.execute(
|
|
327
|
+
* { source: 'mobile' },
|
|
328
|
+
* { 'x-api-key': 'secret-key' },
|
|
329
|
+
* { userId: '123', email: 'user@example.com', name: 'John' }
|
|
330
|
+
* );
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
export class LuaWebhook {
|
|
334
|
+
/**
|
|
335
|
+
* Creates a new LuaWebhook instance.
|
|
336
|
+
*
|
|
337
|
+
* @param config - Configuration object containing webhook metadata
|
|
338
|
+
* @param config.name - Webhook name (optional, defaults to 'unnamed-webhook')
|
|
339
|
+
* @param config.version - Webhook version (optional, defaults to '1.0.0')
|
|
340
|
+
* @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
|
+
* @param config.querySchema - Optional Zod schema for query parameter validation
|
|
343
|
+
* @param config.headerSchema - Optional Zod schema for header validation
|
|
344
|
+
* @param config.bodySchema - Optional Zod schema for body validation
|
|
345
|
+
* @param config.execute - Function that processes the webhook request
|
|
346
|
+
*/
|
|
347
|
+
constructor(config) {
|
|
348
|
+
this.name = config.name || 'unnamed-webhook';
|
|
349
|
+
this.version = config.version || '1.0.0';
|
|
350
|
+
this.description = config.description;
|
|
351
|
+
this.context = config.context;
|
|
352
|
+
this.querySchema = config.querySchema;
|
|
353
|
+
this.headerSchema = config.headerSchema;
|
|
354
|
+
this.bodySchema = config.bodySchema;
|
|
355
|
+
this.executeFunction = config.execute;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Gets the webhook name.
|
|
359
|
+
*/
|
|
360
|
+
getName() {
|
|
361
|
+
return this.name;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Gets the webhook version.
|
|
365
|
+
*/
|
|
366
|
+
getVersion() {
|
|
367
|
+
return this.version;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Gets the webhook description.
|
|
371
|
+
*/
|
|
372
|
+
getDescription() {
|
|
373
|
+
return this.description;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Gets the webhook context.
|
|
377
|
+
*/
|
|
378
|
+
getContext() {
|
|
379
|
+
return this.context;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Executes the webhook with validated input.
|
|
383
|
+
* Validates query parameters, headers, and body against their respective schemas
|
|
384
|
+
* before executing the webhook function.
|
|
385
|
+
*
|
|
386
|
+
* @param query - Query parameters object
|
|
387
|
+
* @param headers - Headers object
|
|
388
|
+
* @param body - Request body
|
|
389
|
+
* @returns Promise resolving to webhook execution result
|
|
390
|
+
* @throws Error if validation fails for any input
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* const result = await webhook.execute(
|
|
395
|
+
* { limit: '10' },
|
|
396
|
+
* { 'x-api-key': 'secret' },
|
|
397
|
+
* { data: 'value' }
|
|
398
|
+
* );
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
async execute(query, headers, body) {
|
|
402
|
+
let validatedQuery = query;
|
|
403
|
+
let validatedHeaders = headers;
|
|
404
|
+
let validatedBody = body;
|
|
405
|
+
// Validate query parameters if schema is provided
|
|
406
|
+
if (this.querySchema) {
|
|
407
|
+
try {
|
|
408
|
+
validatedQuery = this.querySchema.parse(query || {});
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
throw new Error(`Query parameter validation failed: ${error}`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// Validate headers if schema is provided
|
|
415
|
+
if (this.headerSchema) {
|
|
416
|
+
try {
|
|
417
|
+
validatedHeaders = this.headerSchema.parse(headers || {});
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
throw new Error(`Header validation failed: ${error}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
// Validate body if schema is provided
|
|
424
|
+
if (this.bodySchema) {
|
|
425
|
+
try {
|
|
426
|
+
validatedBody = this.bodySchema.parse(body);
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
throw new Error(`Body validation failed: ${error}`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// Execute the webhook function with validated inputs as separate parameters
|
|
433
|
+
return this.executeFunction(validatedQuery, validatedHeaders, validatedBody);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* PreProcessor class.
|
|
438
|
+
* Processes user messages before they reach the agent.
|
|
439
|
+
* Can handle rich content (text, images, files).
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* const contentFilter = new PreProcessor({
|
|
444
|
+
* name: 'content-filter',
|
|
445
|
+
* version: '1.0.0',
|
|
446
|
+
* description: 'Filters and processes message content',
|
|
447
|
+
* context: 'Filters spam, validates images, and adds context',
|
|
448
|
+
* 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
|
+
* });
|
|
462
|
+
* }
|
|
463
|
+
* });
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
export class PreProcessor {
|
|
467
|
+
constructor(config) {
|
|
468
|
+
this.name = config.name || 'unnamed-preprocessor';
|
|
469
|
+
this.version = config.version || '1.0.0';
|
|
470
|
+
this.description = config.description;
|
|
471
|
+
this.context = config.context;
|
|
472
|
+
this.asyncMode = config.async ?? false; // Default to synchronous
|
|
473
|
+
this.executeFunction = config.execute;
|
|
474
|
+
}
|
|
475
|
+
getName() {
|
|
476
|
+
return this.name;
|
|
477
|
+
}
|
|
478
|
+
getVersion() {
|
|
479
|
+
return this.version;
|
|
480
|
+
}
|
|
481
|
+
getDescription() {
|
|
482
|
+
return this.description;
|
|
483
|
+
}
|
|
484
|
+
getContext() {
|
|
485
|
+
return this.context;
|
|
486
|
+
}
|
|
487
|
+
getAsync() {
|
|
488
|
+
return this.asyncMode;
|
|
489
|
+
}
|
|
490
|
+
async execute(user, messages, channel) {
|
|
491
|
+
return this.executeFunction(user, messages, channel);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* PostProcessor class.
|
|
496
|
+
* Processes agent responses before they reach the user.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```typescript
|
|
500
|
+
* const responseFormatter = new PostProcessor({
|
|
501
|
+
* name: 'response-formatter',
|
|
502
|
+
* version: '1.0.0',
|
|
503
|
+
* description: 'Formats responses with branding',
|
|
504
|
+
* context: 'Adds company signature to all responses',
|
|
505
|
+
* execute: async (user, message, response, channel) => {
|
|
506
|
+
* return response + '\n\n---\nPowered by Acme Corp';
|
|
507
|
+
* }
|
|
508
|
+
* });
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
export class PostProcessor {
|
|
512
|
+
constructor(config) {
|
|
513
|
+
this.name = config.name || 'unnamed-postprocessor';
|
|
514
|
+
this.version = config.version || '1.0.0';
|
|
515
|
+
this.description = config.description;
|
|
516
|
+
this.context = config.context;
|
|
517
|
+
this.asyncMode = config.async ?? false; // Default to synchronous
|
|
518
|
+
this.executeFunction = config.execute;
|
|
519
|
+
}
|
|
520
|
+
getName() {
|
|
521
|
+
return this.name;
|
|
522
|
+
}
|
|
523
|
+
getVersion() {
|
|
524
|
+
return this.version;
|
|
525
|
+
}
|
|
526
|
+
getDescription() {
|
|
527
|
+
return this.description;
|
|
528
|
+
}
|
|
529
|
+
getContext() {
|
|
530
|
+
return this.context;
|
|
531
|
+
}
|
|
532
|
+
getAsync() {
|
|
533
|
+
return this.asyncMode;
|
|
534
|
+
}
|
|
535
|
+
async execute(user, message, response, channel) {
|
|
536
|
+
return this.executeFunction(user, message, response, channel);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* LuaAgent class.
|
|
541
|
+
* Unified agent configuration that consolidates skills, webhooks, jobs, and processors.
|
|
542
|
+
*
|
|
543
|
+
* This is the simplest way to define an agent. Instead of exporting multiple separate
|
|
544
|
+
* components, you create one LuaAgent that contains everything.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```typescript
|
|
548
|
+
* import { LuaAgent, LuaSkill, LuaJob, LuaWebhook } from 'lua-cli';
|
|
549
|
+
*
|
|
550
|
+
* // Define your skills, jobs, webhooks in separate files
|
|
551
|
+
* import { userSkill } from './skills/user-skill';
|
|
552
|
+
* import { healthCheckJob } from './jobs/health-check';
|
|
553
|
+
* import { webhookHandler } from './webhooks/handler';
|
|
554
|
+
*
|
|
555
|
+
* // Create a single agent configuration
|
|
556
|
+
* export const agent = new LuaAgent({
|
|
557
|
+
* name: 'my-assistant',
|
|
558
|
+
* persona: 'You are a helpful AI assistant that can manage users and products.',
|
|
559
|
+
* welcomeMessage: 'Hello! How can I help you today?',
|
|
560
|
+
* skills: [userSkill],
|
|
561
|
+
* jobs: [healthCheckJob],
|
|
562
|
+
* webhooks: [webhookHandler],
|
|
563
|
+
* preProcessors: [],
|
|
564
|
+
* postProcessors: []
|
|
565
|
+
* });
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
export class LuaAgent {
|
|
569
|
+
/**
|
|
570
|
+
* Creates a new LuaAgent instance.
|
|
571
|
+
*
|
|
572
|
+
* @param config - Agent configuration
|
|
573
|
+
* @param config.name - Agent name
|
|
574
|
+
* @param config.persona - Agent persona (behavior and personality)
|
|
575
|
+
* @param config.welcomeMessage - Optional welcome message
|
|
576
|
+
* @param config.skills - Optional array of skills
|
|
577
|
+
* @param config.webhooks - Optional array of webhooks
|
|
578
|
+
* @param config.jobs - Optional array of jobs
|
|
579
|
+
* @param config.preProcessors - Optional array of preprocessors
|
|
580
|
+
* @param config.postProcessors - Optional array of postprocessors
|
|
581
|
+
*/
|
|
582
|
+
constructor(config) {
|
|
583
|
+
this.name = config.name;
|
|
584
|
+
this.persona = config.persona;
|
|
585
|
+
this.welcomeMessage = config.welcomeMessage;
|
|
586
|
+
this.skills = config.skills || [];
|
|
587
|
+
this.webhooks = config.webhooks || [];
|
|
588
|
+
this.jobs = config.jobs || [];
|
|
589
|
+
this.preProcessors = config.preProcessors || [];
|
|
590
|
+
this.postProcessors = config.postProcessors || [];
|
|
591
|
+
}
|
|
592
|
+
getName() {
|
|
593
|
+
return this.name;
|
|
594
|
+
}
|
|
595
|
+
getPersona() {
|
|
596
|
+
return this.persona;
|
|
597
|
+
}
|
|
598
|
+
getWelcomeMessage() {
|
|
599
|
+
return this.welcomeMessage;
|
|
600
|
+
}
|
|
601
|
+
getSkills() {
|
|
602
|
+
return this.skills;
|
|
603
|
+
}
|
|
604
|
+
getWebhooks() {
|
|
605
|
+
return this.webhooks;
|
|
606
|
+
}
|
|
607
|
+
getJobs() {
|
|
608
|
+
return this.jobs;
|
|
609
|
+
}
|
|
610
|
+
getPreProcessors() {
|
|
611
|
+
return this.preProcessors;
|
|
612
|
+
}
|
|
613
|
+
getPostProcessors() {
|
|
614
|
+
return this.postProcessors;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
@@ -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
|
+
}
|
package/dist/utils/bundling.d.ts
CHANGED
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
* Bundling Utilities
|
|
3
3
|
* Handles esbuild bundling of tools and main index
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { Plugin } from "esbuild";
|
|
6
6
|
import { Project } from "ts-morph";
|
|
7
|
+
import { ToolInfo } from '../interfaces/compile.js';
|
|
8
|
+
/**
|
|
9
|
+
* esbuild plugin to inject sandbox globals instead of requiring lua-cli
|
|
10
|
+
* This removes require("lua-cli") statements and injects the global API objects
|
|
11
|
+
* that are available in the sandbox (Products, User, Data, Baskets, Orders, Webhooks, Jobs)
|
|
12
|
+
*/
|
|
13
|
+
export declare const sandboxGlobalsPlugin: Plugin;
|
|
7
14
|
/**
|
|
8
15
|
* Bundles a tool's TypeScript code into a standalone JavaScript file.
|
|
9
16
|
* Uses esbuild to:
|
|
@@ -11,10 +18,12 @@ import { Project } from "ts-morph";
|
|
|
11
18
|
* - Minify code for production
|
|
12
19
|
* - Wrap for VM execution
|
|
13
20
|
*
|
|
21
|
+
* For inline tools (defined in index.ts), creates a temporary export file first.
|
|
22
|
+
*
|
|
14
23
|
* @param tool - The tool to bundle
|
|
15
24
|
* @param distDir - The distribution directory for output
|
|
16
25
|
*/
|
|
17
|
-
export declare function bundleTool(tool: ToolInfo, distDir: string): Promise<void>;
|
|
26
|
+
export declare function bundleTool(tool: ToolInfo, distDir: string, modifiedSource?: string): Promise<void>;
|
|
18
27
|
/**
|
|
19
28
|
* Bundles the main index.ts file into a standalone JavaScript file.
|
|
20
29
|
* This creates the entry point for the skill.
|
|
@@ -23,14 +32,44 @@ export declare function bundleTool(tool: ToolInfo, distDir: string): Promise<voi
|
|
|
23
32
|
* @param distDir - The distribution directory for output
|
|
24
33
|
*/
|
|
25
34
|
export declare function bundleMainIndex(indexPath: string, distDir: string): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts and bundles webhook execute function and schemas.
|
|
37
|
+
*
|
|
38
|
+
* @param webhook - Webhook metadata with name and version
|
|
39
|
+
* @param indexFile - The TypeScript source file containing the webhook
|
|
40
|
+
* @param distDir - Distribution directory for output
|
|
41
|
+
* @param project - Optional ts-morph Project for resolving imports
|
|
42
|
+
* @returns Webhook with bundled code and schemas
|
|
43
|
+
*/
|
|
44
|
+
export declare function bundleWebhook(webhook: any, indexFile: any, distDir: string, project?: any): Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Extracts and bundles job execute function.
|
|
47
|
+
*
|
|
48
|
+
* @param job - Job metadata with name and version
|
|
49
|
+
* @param indexFile - The TypeScript source file containing the job
|
|
50
|
+
* @param distDir - Distribution directory for output
|
|
51
|
+
* @param project - Optional ts-morph Project for resolving imports
|
|
52
|
+
* @returns Job with bundled code
|
|
53
|
+
*/
|
|
54
|
+
export declare function bundleJob(job: any, indexFile: any, distDir: string, project?: any): Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Bundles and compresses preprocessor execute function code.
|
|
57
|
+
*/
|
|
58
|
+
export declare function bundlePreProcessor(preprocessor: any, indexFile: any, distDir: string, project?: any): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Bundles and compresses postprocessor execute function code.
|
|
61
|
+
*/
|
|
62
|
+
export declare function bundlePostProcessor(postprocessor: any, indexFile: any, distDir: string, project?: any): Promise<any>;
|
|
26
63
|
/**
|
|
27
64
|
* Extracts execute code and input schema from a tool.
|
|
28
65
|
* This function:
|
|
29
66
|
* 1. Reads the bundled tool code
|
|
30
|
-
* 2.
|
|
31
|
-
* 3.
|
|
67
|
+
* 2. Detects and bundles any Jobs.create() calls within execute
|
|
68
|
+
* 3. Extracts the execute function
|
|
69
|
+
* 4. Converts Zod schema to JSON Schema format
|
|
32
70
|
*
|
|
33
71
|
* @param tool - The tool to extract metadata from (mutated with executeCode and inputSchema)
|
|
34
72
|
* @param project - The ts-morph Project instance for AST analysis
|
|
73
|
+
* @param distDir - Distribution directory for bundling nested jobs
|
|
35
74
|
*/
|
|
36
|
-
export declare function extractExecuteCode(tool: ToolInfo, project: Project): Promise<void>;
|
|
75
|
+
export declare function extractExecuteCode(tool: ToolInfo, project: Project, distDir?: string): Promise<void>;
|