lua-cli 3.1.0-alpha.2 → 3.1.0-alpha.4

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 (70) hide show
  1. package/README.md +0 -4
  2. package/dist/api/job.api.service.d.ts +23 -100
  3. package/dist/api/job.api.service.js +13 -11
  4. package/dist/api/lazy-instances.d.ts +8 -0
  5. package/dist/api/lazy-instances.js +16 -0
  6. package/dist/api/postprocessor.api.service.d.ts +1 -8
  7. package/dist/api/postprocessor.api.service.js +1 -2
  8. package/dist/api/preprocessor.api.service.d.ts +1 -8
  9. package/dist/api/preprocessor.api.service.js +1 -2
  10. package/dist/api/webhook.api.service.d.ts +1 -3
  11. package/dist/api/webhook.api.service.js +1 -1
  12. package/dist/api/whatsapp-templates.api.service.d.ts +40 -0
  13. package/dist/api/whatsapp-templates.api.service.js +78 -0
  14. package/dist/api-exports.d.ts +81 -2
  15. package/dist/api-exports.js +91 -15
  16. package/dist/commands/chat.js +2 -4
  17. package/dist/commands/init.js +11 -44
  18. package/dist/commands/jobs.js +5 -5
  19. package/dist/commands/push.js +2 -9
  20. package/dist/common/job.instance.d.ts +35 -7
  21. package/dist/common/job.instance.js +46 -19
  22. package/dist/config/constants.d.ts +1 -1
  23. package/dist/config/constants.js +1 -5
  24. package/dist/interfaces/agent.d.ts +0 -3
  25. package/dist/interfaces/index.d.ts +1 -1
  26. package/dist/interfaces/init.d.ts +0 -1
  27. package/dist/interfaces/jobs.d.ts +88 -132
  28. package/dist/interfaces/jobs.js +1 -1
  29. package/dist/interfaces/postprocessors.d.ts +0 -3
  30. package/dist/interfaces/preprocessors.d.ts +0 -3
  31. package/dist/interfaces/webhooks.d.ts +0 -5
  32. package/dist/interfaces/whatsapp-templates.d.ts +104 -0
  33. package/dist/interfaces/whatsapp-templates.js +5 -0
  34. package/dist/types/api-contracts.d.ts +32 -0
  35. package/dist/types/compile.types.d.ts +0 -6
  36. package/dist/types/index.d.ts +1 -1
  37. package/dist/types/skill.d.ts +61 -90
  38. package/dist/types/skill.js +28 -86
  39. package/dist/utils/agent-management.d.ts +3 -5
  40. package/dist/utils/agent-management.js +6 -8
  41. package/dist/utils/bundling.js +5 -6
  42. package/dist/utils/compile.d.ts +0 -1
  43. package/dist/utils/compile.js +1 -51
  44. package/dist/utils/deployment.js +0 -1
  45. package/dist/utils/dev-api.js +0 -2
  46. package/dist/utils/files.d.ts +3 -3
  47. package/dist/utils/files.js +4 -12
  48. package/dist/utils/init-agent.d.ts +1 -2
  49. package/dist/utils/init-agent.js +4 -6
  50. package/dist/utils/init-helpers.d.ts +2 -4
  51. package/dist/utils/init-helpers.js +4 -10
  52. package/dist/utils/job-management.js +0 -2
  53. package/dist/utils/postprocessor-management.js +2 -4
  54. package/dist/utils/preprocessor-management.js +2 -4
  55. package/dist/utils/sandbox.js +17 -7
  56. package/dist/utils/webhook-management.js +1 -3
  57. package/package.json +1 -1
  58. package/template/QUICKSTART.md +0 -13
  59. package/template/README.md +6 -7
  60. package/template/src/jobs/AbandonedBasketProcessorJob.ts +0 -3
  61. package/template/src/jobs/DailyCleanupJob.ts +0 -3
  62. package/template/src/jobs/DataMigrationJob.ts +0 -3
  63. package/template/src/jobs/HealthCheckJob.ts +0 -3
  64. package/template/src/postprocessors/modifyResponse.ts +0 -1
  65. package/template/src/preprocessors/messageMatching.ts +18 -5
  66. package/template/src/skills/basket.skill.ts +0 -1
  67. package/template/src/skills/product.skill.ts +0 -1
  68. package/template/src/skills/user.skill.ts +0 -1
  69. package/template/src/webhooks/PaymentWebhook.ts +12 -9
  70. package/template/src/webhooks/UserEventWebhook.ts +39 -11
@@ -0,0 +1,78 @@
1
+ import { HttpClient } from "../common/http.client.js";
2
+ /**
3
+ * WhatsApp Templates API Service
4
+ * Handles WhatsApp template operations
5
+ */
6
+ export default class WhatsAppTemplatesApiService extends HttpClient {
7
+ /**
8
+ * Creates an instance of WhatsAppTemplatesApiService
9
+ * @param baseUrl - The base URL for the API
10
+ * @param apiKey - The API key for authentication
11
+ * @param agentId - The unique identifier of the agent
12
+ */
13
+ constructor(baseUrl, apiKey, agentId) {
14
+ super(baseUrl);
15
+ this.apiKey = apiKey;
16
+ this.agentId = agentId;
17
+ }
18
+ /**
19
+ * Lists WhatsApp templates for a channel with optional pagination and search
20
+ * @param channelId - The WhatsApp channel identifier
21
+ * @param options - Optional pagination and search options
22
+ * @returns Promise resolving to paginated templates response
23
+ */
24
+ async list(channelId, options) {
25
+ const page = options?.page ?? 1;
26
+ const limit = options?.limit ?? 10;
27
+ const search = options?.search;
28
+ let url = `/admin/agents/${this.agentId}/channels/${channelId}/whatsapp-templates?page=${page}&limit=${limit}`;
29
+ if (search) {
30
+ url += `&search=${encodeURIComponent(search)}`;
31
+ }
32
+ const response = await this.httpGet(url, {
33
+ Authorization: `Bearer ${this.apiKey}`,
34
+ });
35
+ if (response.success) {
36
+ return response.data;
37
+ }
38
+ throw new Error(response.error?.message || 'Failed to list templates');
39
+ }
40
+ /**
41
+ * Gets a specific WhatsApp template by ID
42
+ * @param channelId - The WhatsApp channel identifier
43
+ * @param templateId - The template identifier
44
+ * @returns Promise resolving to the template
45
+ */
46
+ async get(channelId, templateId) {
47
+ const url = `/admin/agents/${this.agentId}/channels/${channelId}/whatsapp-templates/${templateId}`;
48
+ const response = await this.httpGet(url, {
49
+ Authorization: `Bearer ${this.apiKey}`,
50
+ });
51
+ if (response.success) {
52
+ return response.data;
53
+ }
54
+ throw new Error(response.error?.message || 'Failed to get template');
55
+ }
56
+ /**
57
+ * Sends a WhatsApp template message to one or more phone numbers
58
+ * @param channelId - The WhatsApp channel identifier
59
+ * @param templateId - The template identifier
60
+ * @param data - Send data including phone numbers and template values
61
+ * @returns Promise resolving to the send response with results and errors
62
+ */
63
+ async send(channelId, templateId, data) {
64
+ const url = `/admin/agents/${this.agentId}/channels/${channelId}/whatsapp-templates/${templateId}/trigger`;
65
+ // Transform to API format (phoneNumbers -> phone_numbers)
66
+ const body = {
67
+ phone_numbers: data.phoneNumbers,
68
+ values: data.values,
69
+ };
70
+ const response = await this.httpPost(url, body, {
71
+ Authorization: `Bearer ${this.apiKey}`,
72
+ });
73
+ if (response.success) {
74
+ return response.data;
75
+ }
76
+ throw new Error(response.error?.message || 'Failed to send template');
77
+ }
78
+ }
@@ -26,7 +26,7 @@
26
26
  * const products = await Products.search('laptop');
27
27
  * ```
28
28
  */
29
- import { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, PostProcessor, PostProcessorConfig, LuaAgent, LuaAgentConfig, env } from "./types/skill.js";
29
+ import { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, PreProcessorAction, PreProcessorResult, PreProcessorBlockResponse, PreProcessorProceedResponse, PostProcessor, PostProcessorConfig, LuaAgent, LuaAgentConfig, env } from "./types/skill.js";
30
30
  import { Basket, BasketStatus, UpdateBasketMetadataResponse } from "./interfaces/baskets.js";
31
31
  import { OrderResponse, OrderStatus } from "./interfaces/orders.js";
32
32
  import { ChatHistoryMessage, ChatHistoryContent, ChatMessage, TextMessage, ImageMessage, FileMessage, PreProcessorOverride, PostProcessorOverride } from "./interfaces/chat.js";
@@ -40,6 +40,7 @@ import { DeleteCustomDataResponse, GetCustomDataResponse, UpdateCustomDataRespon
40
40
  import UserDataInstance from "./common/user.instance.js";
41
41
  import BasketInstance from "./common/basket.instance.js";
42
42
  import OrderInstance from "./common/order.instance.js";
43
+ import { WhatsAppTemplate, PaginatedTemplatesResponse, ListTemplatesOptions, SendTemplateData, SendTemplateResponse } from "./interfaces/whatsapp-templates.js";
43
44
  export declare const User: {
44
45
  /**
45
46
  * Retrieves current user data.
@@ -401,6 +402,84 @@ export declare const AI: {
401
402
  */
402
403
  generate(context: string, messages: import("./interfaces/chat.js").ChatMessage[], agentId?: string): Promise<string>;
403
404
  };
404
- export { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, PostProcessor, PostProcessorConfig, LuaAgent, LuaAgentConfig, BasketStatus, OrderStatus, env };
405
+ /**
406
+ * Templates API
407
+ *
408
+ * Manage templates across different channel types.
409
+ * Use the appropriate namespace for your template type:
410
+ *
411
+ * - `Templates.whatsapp` - WhatsApp Business templates
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * // List WhatsApp templates
416
+ * const result = await Templates.whatsapp.list(channelId);
417
+ *
418
+ * // Send a WhatsApp template
419
+ * await Templates.whatsapp.send(channelId, templateId, {
420
+ * phoneNumbers: ['+447551166594'],
421
+ * values: { body: { name: 'John' } }
422
+ * });
423
+ * ```
424
+ */
425
+ export declare const Templates: {
426
+ /**
427
+ * WhatsApp Templates
428
+ *
429
+ * Pre-approved message formats for WhatsApp Business Accounts.
430
+ * Required for initiating conversations outside the 24-hour messaging window.
431
+ */
432
+ whatsapp: {
433
+ /**
434
+ * Lists WhatsApp templates for a channel with optional pagination and search.
435
+ *
436
+ * @param channelId - The WhatsApp channel identifier
437
+ * @param options - Optional pagination and search options
438
+ * @returns Promise resolving to paginated templates response
439
+ *
440
+ * @example
441
+ * ```typescript
442
+ * const result = await Templates.whatsapp.list(channelId);
443
+ * const filtered = await Templates.whatsapp.list(channelId, { search: 'order' });
444
+ * const paginated = await Templates.whatsapp.list(channelId, { page: 2, limit: 20 });
445
+ * ```
446
+ */
447
+ list(channelId: string, options?: ListTemplatesOptions): Promise<PaginatedTemplatesResponse>;
448
+ /**
449
+ * Gets a specific WhatsApp template by ID.
450
+ *
451
+ * @param channelId - The WhatsApp channel identifier
452
+ * @param templateId - The template identifier
453
+ * @returns Promise resolving to the template
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * const template = await Templates.whatsapp.get(channelId, 'template_123');
458
+ * ```
459
+ */
460
+ get(channelId: string, templateId: string): Promise<WhatsAppTemplate>;
461
+ /**
462
+ * Sends a WhatsApp template message to one or more phone numbers.
463
+ *
464
+ * @param channelId - The WhatsApp channel identifier
465
+ * @param templateId - The template identifier
466
+ * @param data - Send data including phone numbers and template values
467
+ * @returns Promise resolving to the send response with results and errors
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * const result = await Templates.whatsapp.send(channelId, 'template_123', {
472
+ * phoneNumbers: ['+447551166594'],
473
+ * values: {
474
+ * body: { first_name: 'John', order_number: '12345' }
475
+ * }
476
+ * });
477
+ * ```
478
+ */
479
+ send(channelId: string, templateId: string, data: SendTemplateData): Promise<SendTemplateResponse>;
480
+ };
481
+ };
482
+ export { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, PreProcessorAction, PreProcessorResult, PreProcessorBlockResponse, PreProcessorProceedResponse, PostProcessor, PostProcessorConfig, LuaAgent, LuaAgentConfig, BasketStatus, OrderStatus, env };
405
483
  export { JobInstance, UserDataInstance, DataEntryInstance, ProductInstance, BasketInstance, OrderInstance };
406
484
  export { ChatHistoryMessage, ChatHistoryContent, ChatMessage, TextMessage, ImageMessage, FileMessage, PreProcessorOverride, PostProcessorOverride };
485
+ export { WhatsAppTemplate, PaginatedTemplatesResponse, ListTemplatesOptions, SendTemplateData, SendTemplateResponse, WhatsAppTemplateCategory, WhatsAppTemplateStatus, WhatsAppTemplateComponent, SendTemplateValues } from "./interfaces/whatsapp-templates.js";
@@ -29,7 +29,7 @@
29
29
  import { LuaSkill, LuaWebhook, LuaJob, PreProcessor, PostProcessor, LuaAgent, env } from "./types/skill.js";
30
30
  import { BasketStatus } from "./interfaces/baskets.js";
31
31
  import { OrderStatus } from "./interfaces/orders.js";
32
- import { getUserInstance, getDataInstance, getProductsInstance, getBasketsInstance, getOrderInstance, getJobInstance, getChatInstance, } from "./api/lazy-instances.js";
32
+ import { getUserInstance, getDataInstance, getProductsInstance, getBasketsInstance, getOrderInstance, getJobInstance, getChatInstance, getWhatsAppTemplatesInstance, } from "./api/lazy-instances.js";
33
33
  import { JobInstance } from "./common/job.instance.js";
34
34
  import ProductInstance from "./common/product.instance.js";
35
35
  import DataEntryInstance from "./common/data.entry.instance.js";
@@ -436,11 +436,10 @@ export const Jobs = {
436
436
  const executeString = config.execute.toString();
437
437
  console.log('Creating Job');
438
438
  // Create the job with initial version and activation in one call
439
- const createResult = await instance.createJobInstance({
439
+ return await instance.createJobInstance({
440
440
  dynamic: true,
441
441
  name: config.name,
442
442
  description: config.description,
443
- context: config.description || '',
444
443
  schedule: config.schedule,
445
444
  timeout: config.timeout,
446
445
  retry: config.retry,
@@ -449,7 +448,6 @@ export const Jobs = {
449
448
  version: {
450
449
  version: '1.0.0',
451
450
  description: config.description,
452
- context: config.description || '',
453
451
  code: '', // Will be set by server
454
452
  executeFunction: executeString,
455
453
  timeout: config.timeout,
@@ -459,17 +457,6 @@ export const Jobs = {
459
457
  // Activate immediately
460
458
  activate: config.activate ?? true
461
459
  });
462
- const jobId = createResult.jobId;
463
- // Server has created the job, version, and activated it
464
- // Return a JobInstance for easy manipulation
465
- return new JobInstance(instance, {
466
- id: jobId,
467
- jobId: jobId,
468
- name: config.name,
469
- schedule: config.schedule,
470
- metadata: config.metadata || {},
471
- active: config.activate ?? true
472
- });
473
460
  },
474
461
  /**
475
462
  * Retrieves a job by its unique identifier
@@ -543,6 +530,95 @@ export const AI = {
543
530
  }
544
531
  };
545
532
  // ============================================================================
533
+ // TEMPLATES API
534
+ // ============================================================================
535
+ /**
536
+ * Templates API
537
+ *
538
+ * Manage templates across different channel types.
539
+ * Use the appropriate namespace for your template type:
540
+ *
541
+ * - `Templates.whatsapp` - WhatsApp Business templates
542
+ *
543
+ * @example
544
+ * ```typescript
545
+ * // List WhatsApp templates
546
+ * const result = await Templates.whatsapp.list(channelId);
547
+ *
548
+ * // Send a WhatsApp template
549
+ * await Templates.whatsapp.send(channelId, templateId, {
550
+ * phoneNumbers: ['+447551166594'],
551
+ * values: { body: { name: 'John' } }
552
+ * });
553
+ * ```
554
+ */
555
+ export const Templates = {
556
+ /**
557
+ * WhatsApp Templates
558
+ *
559
+ * Pre-approved message formats for WhatsApp Business Accounts.
560
+ * Required for initiating conversations outside the 24-hour messaging window.
561
+ */
562
+ whatsapp: {
563
+ /**
564
+ * Lists WhatsApp templates for a channel with optional pagination and search.
565
+ *
566
+ * @param channelId - The WhatsApp channel identifier
567
+ * @param options - Optional pagination and search options
568
+ * @returns Promise resolving to paginated templates response
569
+ *
570
+ * @example
571
+ * ```typescript
572
+ * const result = await Templates.whatsapp.list(channelId);
573
+ * const filtered = await Templates.whatsapp.list(channelId, { search: 'order' });
574
+ * const paginated = await Templates.whatsapp.list(channelId, { page: 2, limit: 20 });
575
+ * ```
576
+ */
577
+ async list(channelId, options) {
578
+ const instance = await getWhatsAppTemplatesInstance();
579
+ return instance.list(channelId, options);
580
+ },
581
+ /**
582
+ * Gets a specific WhatsApp template by ID.
583
+ *
584
+ * @param channelId - The WhatsApp channel identifier
585
+ * @param templateId - The template identifier
586
+ * @returns Promise resolving to the template
587
+ *
588
+ * @example
589
+ * ```typescript
590
+ * const template = await Templates.whatsapp.get(channelId, 'template_123');
591
+ * ```
592
+ */
593
+ async get(channelId, templateId) {
594
+ const instance = await getWhatsAppTemplatesInstance();
595
+ return instance.get(channelId, templateId);
596
+ },
597
+ /**
598
+ * Sends a WhatsApp template message to one or more phone numbers.
599
+ *
600
+ * @param channelId - The WhatsApp channel identifier
601
+ * @param templateId - The template identifier
602
+ * @param data - Send data including phone numbers and template values
603
+ * @returns Promise resolving to the send response with results and errors
604
+ *
605
+ * @example
606
+ * ```typescript
607
+ * const result = await Templates.whatsapp.send(channelId, 'template_123', {
608
+ * phoneNumbers: ['+447551166594'],
609
+ * values: {
610
+ * body: { first_name: 'John', order_number: '12345' }
611
+ * }
612
+ * });
613
+ * ```
614
+ */
615
+ async send(channelId, templateId, data) {
616
+ const instance = await getWhatsAppTemplatesInstance();
617
+ return instance.send(channelId, templateId, data);
618
+ }
619
+ }
620
+ };
621
+ // ============================================================================
546
622
  // EXPORTS
547
623
  // ============================================================================
548
624
  // Export skill classes and utilities
@@ -123,10 +123,8 @@ async function startChatLoop(chatEnv) {
123
123
  console.log(`Environment: ${chatEnv.type === 'sandbox' ? 'šŸ”§ Sandbox' : 'šŸš€ Production'}`);
124
124
  console.log("Press Ctrl+C to exit");
125
125
  console.log("=".repeat(60) + "\n");
126
- // Welcome message from config or default
127
- const config = readSkillConfig();
128
- const welcomeMessage = config?.agent?.welcomeMessage || "Hi there! How can I help you today?";
129
- console.log(`šŸŒ™ Assistant: ${welcomeMessage}\n`);
126
+ // Welcome message
127
+ console.log("šŸŒ™ Assistant: Hi there! How can I help you today?\n");
130
128
  // Create readline interface
131
129
  const rl = readline.createInterface({
132
130
  input: process.stdin,
@@ -111,7 +111,6 @@ export async function initCommand() {
111
111
  let selectedAgent;
112
112
  let selectedOrg;
113
113
  let persona;
114
- let welcomeMessage;
115
114
  let skipProjectInit = false;
116
115
  if (agentChoice === "existing") {
117
116
  // Step 4a: Select existing agent
@@ -119,7 +118,6 @@ export async function initCommand() {
119
118
  selectedAgent = result.agent;
120
119
  selectedOrg = result.org;
121
120
  persona = result.persona;
122
- welcomeMessage = result.welcomeMessage;
123
121
  }
124
122
  else {
125
123
  // Step 4b: Create new agent
@@ -127,22 +125,21 @@ export async function initCommand() {
127
125
  selectedAgent = result.agent;
128
126
  selectedOrg = result.org;
129
127
  persona = result.persona;
130
- welcomeMessage = result.welcomeMessage;
131
128
  }
132
129
  // Step 5: Initialize or update project
133
130
  if (yamlExists) {
134
131
  // Update existing YAML and LuaAgent in index.ts
135
132
  writeInfo("šŸ“ Updating existing lua.skill.yaml with new agent...");
136
- updateYamlAgent(selectedAgent.agentId, selectedOrg.id, persona, welcomeMessage);
133
+ updateYamlAgent(selectedAgent.agentId, selectedOrg.id, persona);
137
134
  // Also update LuaAgent in index.ts if it exists
138
135
  const { updateLuaAgentInIndexFile } = await import("../utils/init-helpers.js");
139
- updateLuaAgentInIndexFile(process.cwd(), selectedAgent.name, persona, welcomeMessage);
136
+ updateLuaAgentInIndexFile(process.cwd(), selectedAgent.name, persona);
140
137
  writeSuccess("āœ… lua.skill.yaml updated successfully!");
141
138
  writeSuccess("āœ… LuaAgent configuration updated!");
142
139
  }
143
140
  else {
144
141
  // Full project initialization
145
- const currentDir = initializeProject(selectedAgent.agentId, selectedOrg.id, persona, welcomeMessage, selectedAgent.name);
142
+ const currentDir = initializeProject(selectedAgent.agentId, selectedOrg.id, persona, selectedAgent.name);
146
143
  // Step 6: Install dependencies
147
144
  await installDependencies(currentDir);
148
145
  writeSuccess("āœ… Lua skill project initialized successfully!");
@@ -151,11 +148,11 @@ export async function initCommand() {
151
148
  }
152
149
  /**
153
150
  * Handles the flow for selecting an existing agent.
154
- * Fetches the agent details from the server to get persona and welcomeMessage.
151
+ * Fetches the agent details from the server to get persona.
155
152
  *
156
153
  * @param userData - User's data
157
154
  * @param apiKey - User's API key
158
- * @returns Selected agent, organization, and optional persona/welcome message
155
+ * @returns Selected agent, organization, and optional persona
159
156
  */
160
157
  async function selectExistingAgent(userData, apiKey) {
161
158
  // Extract organizations
@@ -167,13 +164,12 @@ async function selectExistingAgent(userData, apiKey) {
167
164
  const selectedOrg = await promptOrganizationSelection(orgs);
168
165
  // Select agent from organization
169
166
  const selectedAgent = await promptAgentSelection(selectedOrg);
170
- // Fetch agent details to get persona and welcomeMessage
167
+ // Fetch agent details to get persona
171
168
  const agentDetails = await fetchExistingAgentDetails(apiKey, selectedAgent.agentId);
172
169
  return {
173
170
  agent: selectedAgent,
174
171
  org: selectedOrg,
175
- persona: agentDetails.persona,
176
- welcomeMessage: agentDetails.welcomeMessage
172
+ persona: agentDetails.persona
177
173
  };
178
174
  }
179
175
  /**
@@ -181,7 +177,7 @@ async function selectExistingAgent(userData, apiKey) {
181
177
  *
182
178
  * @param apiKey - User's API key
183
179
  * @param userData - User data containing organizations
184
- * @returns Created agent, organization, and optional persona/welcome message
180
+ * @returns Created agent, organization, and optional persona
185
181
  */
186
182
  async function createNewAgentFlow(apiKey, userData) {
187
183
  // Fetch and select agent type
@@ -275,14 +271,12 @@ async function handleAgentSwitch(userData, apiKey, existingYaml) {
275
271
  let selectedAgent;
276
272
  let selectedOrg;
277
273
  let persona;
278
- let welcomeMessage;
279
274
  if (agentChoice === "existing") {
280
275
  // Select existing agent
281
276
  const result = await selectExistingAgent(userData, apiKey);
282
277
  selectedAgent = result.agent;
283
278
  selectedOrg = result.org;
284
279
  persona = result.persona;
285
- welcomeMessage = result.welcomeMessage;
286
280
  }
287
281
  else {
288
282
  // Create new agent
@@ -290,17 +284,15 @@ async function handleAgentSwitch(userData, apiKey, existingYaml) {
290
284
  selectedAgent = result.agent;
291
285
  selectedOrg = result.org;
292
286
  persona = result.persona;
293
- welcomeMessage = result.welcomeMessage;
294
287
  }
295
- // Ask about persona and welcome message
288
+ // Ask about persona
296
289
  const finalPersona = await promptPersonaReplacement(existingYaml, persona);
297
- const finalWelcomeMessage = await promptWelcomeMessageReplacement(existingYaml, welcomeMessage);
298
290
  // Update existing YAML file with new agent
299
291
  writeInfo("\nšŸ“ Updating lua.skill.yaml with new agent...");
300
- updateYamlAgent(selectedAgent.agentId, selectedOrg.id, finalPersona, finalWelcomeMessage);
292
+ updateYamlAgent(selectedAgent.agentId, selectedOrg.id, finalPersona);
301
293
  // Also update LuaAgent in index.ts if it exists
302
294
  const { updateLuaAgentInIndexFile } = await import("../utils/init-helpers.js");
303
- updateLuaAgentInIndexFile(process.cwd(), selectedAgent.name, finalPersona, finalWelcomeMessage);
295
+ updateLuaAgentInIndexFile(process.cwd(), selectedAgent.name, finalPersona);
304
296
  writeSuccess("āœ… lua.skill.yaml updated successfully!");
305
297
  writeSuccess("āœ… LuaAgent configuration updated!");
306
298
  writeInfo("\nšŸ’” Your project now uses the new agent. Run 'lua compile' to update your skills.\n");
@@ -331,28 +323,3 @@ async function promptPersonaReplacement(existingYaml, newPersona) {
331
323
  ]);
332
324
  return replacePersona ? newPersona : existingPersona;
333
325
  }
334
- /**
335
- * Prompt user about replacing existing welcome message
336
- */
337
- async function promptWelcomeMessageReplacement(existingYaml, newWelcomeMessage) {
338
- const existingWelcomeMessage = existingYaml?.agent?.welcomeMessage;
339
- // If no existing welcome message, use new one
340
- if (!existingWelcomeMessage) {
341
- return newWelcomeMessage;
342
- }
343
- // If no new welcome message, keep existing
344
- if (!newWelcomeMessage) {
345
- return existingWelcomeMessage;
346
- }
347
- // Both exist - ask user
348
- writeInfo(" Existing welcome message found in project");
349
- const { replaceWelcomeMessage } = await inquirer.prompt([
350
- {
351
- type: 'confirm',
352
- name: 'replaceWelcomeMessage',
353
- message: 'Replace existing welcome message with the new agent\'s welcome message?',
354
- default: false
355
- }
356
- ]);
357
- return replaceWelcomeMessage ? newWelcomeMessage : existingWelcomeMessage;
358
- }
@@ -203,8 +203,8 @@ async function viewJobVersions(context, config) {
203
203
  if (!response.success || !response.data) {
204
204
  throw new Error(response.error?.message || 'Failed to fetch versions');
205
205
  }
206
- const versions = response.data.versions || [];
207
- const activeVersionId = response.data.activeVersionId;
206
+ const versions = response.data;
207
+ const activeVersionId = selectedJob.activeVersionId;
208
208
  if (versions.length === 0) {
209
209
  console.log(`\nā„¹ļø No versions found for ${selectedJob.name}.\n`);
210
210
  console.log("šŸ’” Push a version first using 'lua push job'.\n");
@@ -270,8 +270,8 @@ async function deployJobVersion(context, config) {
270
270
  if (!response.success || !response.data) {
271
271
  throw new Error(response.error?.message || 'Failed to fetch versions');
272
272
  }
273
- const versions = response.data.versions || [];
274
- const activeVersionId = response.data.activeVersionId;
273
+ const versions = response.data;
274
+ const activeVersionId = selectedJob.activeVersionId;
275
275
  if (versions.length === 0) {
276
276
  console.log(`\nā„¹ļø No versions found for ${selectedJob.name}.\n`);
277
277
  console.log("šŸ’” Push a version first using 'lua push job'.\n");
@@ -434,7 +434,7 @@ async function triggerJob(context, config) {
434
434
  const response = await jobApi.triggerJob(jobAnswer.selectedJob.jobId);
435
435
  if (response.success && response.data) {
436
436
  writeSuccess(`āœ… Job "${jobAnswer.selectedJob.name}" triggered successfully`);
437
- writeInfo(`šŸ“‹ Execution ID: ${response.data.executionId || 'N/A'}`);
437
+ writeInfo(`šŸ“‹ Execution ID: ${response.data.id || 'N/A'}`);
438
438
  }
439
439
  else {
440
440
  console.error(`āŒ Failed to trigger job: ${response.error?.message || 'Unknown error'}`);
@@ -434,7 +434,6 @@ async function pushWebhookVersion() {
434
434
  name: selectedWebhook.name,
435
435
  version: versionToPush,
436
436
  description: bundledWebhookData.description || selectedWebhook.description || `Webhook: ${selectedWebhook.name}`,
437
- context: bundledWebhookData.context || selectedWebhook.context || '',
438
437
  webhookId: selectedWebhook.webhookId,
439
438
  querySchema: bundledWebhookData.querySchema,
440
439
  headerSchema: bundledWebhookData.headerSchema,
@@ -459,7 +458,8 @@ async function pushWebhookVersion() {
459
458
  }
460
459
  const result = await response.json();
461
460
  writeSuccess(`\nāœ… Successfully pushed ${selectedWebhook.name} v${versionToPush}\n`);
462
- writeInfo(`šŸ“¦ Webhook URL: ${BASE_URLS.WEBHOOK}/${config.agent.agentId}/${selectedWebhook.webhookId}`);
461
+ writeInfo(`šŸ“¦ Webhook URL (id): ${BASE_URLS.WEBHOOK}/${config.agent.agentId}/${selectedWebhook.webhookId}`);
462
+ writeInfo(`šŸ”— Webhook URL (name): ${BASE_URLS.WEBHOOK}/${config.agent.agentId}/${selectedWebhook.name}`);
463
463
  // Step 8: Ask if user wants to deploy now
464
464
  const deployAnswer = await safePrompt([
465
465
  {
@@ -633,7 +633,6 @@ async function pushJobVersion() {
633
633
  name: selectedJob.name,
634
634
  version: versionToPush,
635
635
  description: bundledJobData.description || selectedJob.description || `Job: ${selectedJob.name}`,
636
- context: bundledJobData.context || selectedJob.context || '',
637
636
  jobId: selectedJob.jobId,
638
637
  schedule: bundledJobData.schedule || selectedJob.schedule,
639
638
  timeout: bundledJobData.timeout,
@@ -780,7 +779,6 @@ async function pushPreProcessorVersion() {
780
779
  name: selected.name,
781
780
  version: confirmedVersion,
782
781
  description: bundledData.description || selected.description,
783
- context: bundledData.context || selected.context,
784
782
  preprocessorId: selected.preprocessorId,
785
783
  code: bundledData.code,
786
784
  executeFunction: bundledData.executeFunction,
@@ -912,7 +910,6 @@ async function pushPostProcessorVersion() {
912
910
  name: selected.name,
913
911
  version: confirmedVersion,
914
912
  description: bundledData.description || selected.description,
915
- context: bundledData.context || selected.context,
916
913
  postprocessorId: selected.postprocessorId,
917
914
  code: bundledData.code,
918
915
  executeFunction: bundledData.executeFunction,
@@ -1193,7 +1190,6 @@ async function pushAllCommand(options) {
1193
1190
  name: webhookConfig.name,
1194
1191
  version: newVersion,
1195
1192
  description: webhookData.description || webhookConfig.description || '',
1196
- context: webhookData.context || webhookConfig.context || '',
1197
1193
  webhookId: webhookConfig.webhookId,
1198
1194
  querySchema: webhookData.querySchema,
1199
1195
  headerSchema: webhookData.headerSchema,
@@ -1254,7 +1250,6 @@ async function pushAllCommand(options) {
1254
1250
  name: jobConfig.name,
1255
1251
  version: newVersion,
1256
1252
  description: jobData.description || jobConfig.description || '',
1257
- context: jobData.context || jobConfig.context || '',
1258
1253
  jobId: jobConfig.jobId,
1259
1254
  schedule: jobData.schedule || jobConfig.schedule,
1260
1255
  timeout: jobData.timeout,
@@ -1319,7 +1314,6 @@ async function pushAllCommand(options) {
1319
1314
  name: processorConfig.name,
1320
1315
  version: newVersion,
1321
1316
  description: processorData.description || processorConfig.description || '',
1322
- context: processorData.context || processorConfig.context || '',
1323
1317
  preprocessorId: preprocessorId,
1324
1318
  code: processorData.code,
1325
1319
  executeFunction: processorData.executeFunction,
@@ -1374,7 +1368,6 @@ async function pushAllCommand(options) {
1374
1368
  name: processorConfig.name,
1375
1369
  version: newVersion,
1376
1370
  description: processorData.description || processorConfig.description || '',
1377
- context: processorData.context || processorConfig.context || '',
1378
1371
  postprocessorId: postprocessorId,
1379
1372
  code: processorData.code,
1380
1373
  executeFunction: processorData.executeFunction,
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import JobApi from '../api/job.api.service.js';
6
6
  import UserDataInstance from './user.instance.js';
7
+ import { Job, JobVersion, JobExecution } from '../interfaces/jobs.js';
7
8
  /**
8
9
  * Job Instance class.
9
10
  * Represents a single job with helper methods for common operations.
@@ -36,15 +37,15 @@ export declare class JobInstance {
36
37
  private _data;
37
38
  readonly id: string;
38
39
  readonly name: string;
39
- readonly jobId: string;
40
- readonly schedule: any;
40
+ /** The active version of the job (if one exists) */
41
+ readonly activeVersion?: JobVersion;
41
42
  metadata: Record<string, any>;
42
- private userApi;
43
- constructor(jobApi: JobApi, jobData: any);
43
+ private userApi?;
44
+ constructor(jobApi: JobApi, jobData: Job);
44
45
  /**
45
46
  * Gets the full job data.
46
47
  */
47
- get data(): any;
48
+ get data(): Job;
48
49
  /**
49
50
  * Updates the job's metadata.
50
51
  *
@@ -61,7 +62,7 @@ export declare class JobInstance {
61
62
  */
62
63
  updateMetadata(metadata: Record<string, any>): Promise<void>;
63
64
  /**
64
- * Deletes the job from the backend.
65
+ * Deletes the job from the backend (or deactivates if it has versions).
65
66
  *
66
67
  * @returns Promise resolving when deletion is complete
67
68
  *
@@ -72,9 +73,36 @@ export declare class JobInstance {
72
73
  * ```
73
74
  */
74
75
  delete(): Promise<void>;
76
+ /**
77
+ * Gets the user data associated with this job's agent.
78
+ * Provides access to user information and custom data storage.
79
+ *
80
+ * @returns Promise resolving to UserDataInstance with user information
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const user = await job.user();
85
+ * console.log('User email:', user.email);
86
+ * console.log('User data:', user.data);
87
+ * ```
88
+ */
75
89
  user(): Promise<UserDataInstance>;
90
+ /**
91
+ * Manually triggers the job execution (ignores schedule).
92
+ * Uses activeVersion by default.
93
+ *
94
+ * @param versionId - Optional version to execute (defaults to activeVersion)
95
+ * @returns Promise resolving to execution result
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const result = await job.trigger();
100
+ * console.log('Execution result:', result);
101
+ * ```
102
+ */
103
+ trigger(versionId?: string): Promise<JobExecution>;
76
104
  /**
77
105
  * Converts the job instance to JSON.
78
106
  */
79
- toJSON(): any;
107
+ toJSON(): Job;
80
108
  }