lua-cli 3.0.0-alpha.1 → 3.0.0-alpha.11

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 (66) hide show
  1. package/dist/api/chat.api.service.d.ts +8 -0
  2. package/dist/api/chat.api.service.js +55 -0
  3. package/dist/api/job.api.service.d.ts +16 -7
  4. package/dist/api/job.api.service.js +21 -5
  5. package/dist/api/postprocessor.api.service.d.ts +61 -1
  6. package/dist/api/postprocessor.api.service.js +35 -0
  7. package/dist/api/preprocessor.api.service.d.ts +61 -1
  8. package/dist/api/preprocessor.api.service.js +35 -0
  9. package/dist/api-exports.d.ts +27 -7
  10. package/dist/api-exports.js +48 -30
  11. package/dist/cli/command-definitions.js +13 -6
  12. package/dist/commands/chat.js +71 -39
  13. package/dist/commands/compile.js +16 -2
  14. package/dist/commands/dev.js +23 -2
  15. package/dist/commands/push.d.ts +3 -2
  16. package/dist/commands/push.js +536 -6
  17. package/dist/commands/test.js +18 -2
  18. package/dist/common/job.instance.d.ts +3 -0
  19. package/dist/common/job.instance.js +8 -0
  20. package/dist/config/constants.d.ts +6 -5
  21. package/dist/config/constants.js +12 -10
  22. package/dist/interfaces/chat.d.ts +30 -1
  23. package/dist/interfaces/jobs.d.ts +21 -0
  24. package/dist/services/auth.d.ts +8 -2
  25. package/dist/services/auth.js +35 -3
  26. package/dist/types/skill.d.ts +75 -56
  27. package/dist/types/skill.js +53 -59
  28. package/dist/utils/bundling.d.ts +13 -4
  29. package/dist/utils/bundling.js +83 -26
  30. package/dist/utils/compile.js +27 -6
  31. package/dist/utils/dev-api.d.ts +42 -2
  32. package/dist/utils/dev-api.js +177 -4
  33. package/dist/utils/dev-server.d.ts +1 -1
  34. package/dist/utils/dev-server.js +4 -4
  35. package/dist/utils/dynamic-job-bundler.d.ts +17 -0
  36. package/dist/utils/dynamic-job-bundler.js +143 -0
  37. package/dist/utils/pre-bundle-jobs.d.ts +26 -0
  38. package/dist/utils/pre-bundle-jobs.js +176 -0
  39. package/dist/utils/sandbox-storage.d.ts +48 -0
  40. package/dist/utils/sandbox-storage.js +114 -0
  41. package/dist/utils/sandbox.d.ts +2 -2
  42. package/dist/utils/sandbox.js +23 -8
  43. package/package.json +1 -1
  44. package/template/env.example +5 -0
  45. package/template/lua.skill.yaml +47 -0
  46. package/template/package-lock.json +10505 -0
  47. package/template/package.json +2 -1
  48. package/template/src/index.ts +65 -3
  49. package/template/src/tools/CreateInlineJob.ts +42 -0
  50. package/API_REFERENCE.md +0 -1408
  51. package/CHANGELOG.md +0 -236
  52. package/CLI_REFERENCE.md +0 -908
  53. package/GETTING_STARTED.md +0 -1040
  54. package/INSTANCE_TYPES.md +0 -1158
  55. package/README.md +0 -865
  56. package/TEMPLATE_GUIDE.md +0 -1398
  57. package/USER_DATA_INSTANCE.md +0 -621
  58. package/template/AGENT_CONFIGURATION.md +0 -251
  59. package/template/COMPLEX_JOB_EXAMPLES.md +0 -795
  60. package/template/DYNAMIC_JOB_CREATION.md +0 -371
  61. package/template/TOOL_EXAMPLES.md +0 -655
  62. package/template/WEBHOOKS_JOBS_QUICKSTART.md +0 -318
  63. package/template/WEBHOOK_JOB_EXAMPLES.md +0 -817
  64. package/template/src/index-agent-example.ts +0 -201
  65. package/template/src/postprocessors/ResponseFormatter.ts +0 -151
  66. package/template/src/preprocessors/MessageFilter.ts +0 -91
@@ -18,4 +18,12 @@ export default class ChatApi extends HttpClient {
18
18
  * @throws Error if the agent is not found or the chat request fails
19
19
  */
20
20
  sendMessage(agentId: string, chatData: ChatRequest): Promise<ApiResponse<ChatResponse>>;
21
+ /**
22
+ * Streams a message to an agent and receives chunked responses
23
+ * @param agentId - The unique identifier of the agent to chat with
24
+ * @param chatData - The chat request data including message, conversation history, and context
25
+ * @param onChunk - Callback function to handle each text chunk as it arrives
26
+ * @returns Promise resolving when stream completes
27
+ */
28
+ sendMessageStream(agentId: string, chatData: ChatRequest, onChunk: (text: string) => void): Promise<void>;
21
29
  }
@@ -21,4 +21,59 @@ export default class ChatApi extends HttpClient {
21
21
  Authorization: `Bearer ${this.apiKey}`,
22
22
  });
23
23
  }
24
+ /**
25
+ * Streams a message to an agent and receives chunked responses
26
+ * @param agentId - The unique identifier of the agent to chat with
27
+ * @param chatData - The chat request data including message, conversation history, and context
28
+ * @param onChunk - Callback function to handle each text chunk as it arrives
29
+ * @returns Promise resolving when stream completes
30
+ */
31
+ async sendMessageStream(agentId, chatData, onChunk) {
32
+ const response = await fetch(`${this.baseUrl}/chat/stream/${agentId}?channel=dev`, {
33
+ method: 'POST',
34
+ headers: {
35
+ 'Authorization': `Bearer ${this.apiKey}`,
36
+ 'Content-Type': 'application/json',
37
+ },
38
+ body: JSON.stringify(chatData)
39
+ });
40
+ if (!response.ok) {
41
+ throw new Error(`HTTP error! status: ${response.status}`);
42
+ }
43
+ if (!response.body) {
44
+ throw new Error('Response body is not readable');
45
+ }
46
+ const reader = response.body.getReader();
47
+ const decoder = new TextDecoder();
48
+ let buffer = '';
49
+ try {
50
+ while (true) {
51
+ const { done, value } = await reader.read();
52
+ if (done)
53
+ break;
54
+ // Decode the chunk and add to buffer
55
+ buffer += decoder.decode(value, { stream: true });
56
+ // Process complete lines (chunks are separated by newlines)
57
+ const lines = buffer.split('\n');
58
+ buffer = lines.pop() || ''; // Keep incomplete line in buffer
59
+ for (const line of lines) {
60
+ if (!line.trim())
61
+ continue;
62
+ try {
63
+ const chunk = JSON.parse(line);
64
+ // Only process text-delta chunks and call onChunk immediately
65
+ if (chunk.type === 'text-delta' && chunk.textDelta) {
66
+ onChunk(chunk.textDelta);
67
+ }
68
+ }
69
+ catch (error) {
70
+ // Skip invalid JSON lines
71
+ }
72
+ }
73
+ }
74
+ }
75
+ finally {
76
+ reader.releaseLock();
77
+ }
78
+ }
24
79
  }
@@ -69,8 +69,8 @@ export interface JobExecutionResponse {
69
69
  * Handles all job-related API calls
70
70
  */
71
71
  export default class JobApi extends HttpClient {
72
- private apiKey;
73
- private agentId;
72
+ apiKey: string;
73
+ agentId: string;
74
74
  /**
75
75
  * Creates an instance of JobApi
76
76
  * @param baseUrl - The base URL for the API
@@ -92,19 +92,28 @@ export default class JobApi extends HttpClient {
92
92
  */
93
93
  getJob(jobId: string): Promise<JobInstance>;
94
94
  /**
95
- * Creates a new job for the agent
96
- * @param jobData - The job data including name, description, and optional context
95
+ * Creates a new job for the agent.
96
+ * Optionally creates initial version and activates the job in one call.
97
+ *
98
+ * @param jobData - The job data including name, description, schedule, and optional version
99
+ * @param jobData.version - If provided, creates first version automatically
100
+ * @param jobData.activate - If true, activates the job immediately
97
101
  * @returns Promise resolving to an ApiResponse containing the created job details
98
102
  * @throws Error if the job creation fails or validation errors occur
99
103
  */
100
104
  createJob(jobData: CreateJobDTO): Promise<ApiResponse<CreateJobResponse>>;
101
105
  /**
102
- * Creates a new job for the agent
103
- * @param jobData - The job data including name, description, and optional context
104
- * @returns Promise resolving to an JobInstance containing the created job details
106
+ * Creates a new job for the agent and returns a JobInstance.
107
+ * Supports automatic version creation and activation.
108
+ *
109
+ * @param jobData - The job data including name, description, schedule, and optional version
110
+ * @param jobData.version - If provided, creates first version automatically
111
+ * @param jobData.activate - If true, activates the job immediately
112
+ * @returns Promise resolving to a JobInstance containing the created job details
105
113
  * @throws Error if the job creation fails or validation errors occur
106
114
  */
107
115
  createJobInstance(jobData: CreateJobDTO): Promise<JobInstance>;
116
+ private compressCode;
108
117
  /**
109
118
  * Pushes a new version of a job to production
110
119
  * @param jobId - The unique identifier of the job
@@ -1,5 +1,6 @@
1
1
  import { HttpClient } from "../common/http.client.js";
2
2
  import { JobInstance } from "../common/job.instance.js";
3
+ import { gzipSync } from "zlib";
3
4
  /**
4
5
  * Job API Service
5
6
  * Handles all job-related API calls
@@ -42,8 +43,12 @@ export default class JobApi extends HttpClient {
42
43
  throw new Error(response.error?.message || 'Failed to get job');
43
44
  }
44
45
  /**
45
- * Creates a new job for the agent
46
- * @param jobData - The job data including name, description, and optional context
46
+ * Creates a new job for the agent.
47
+ * Optionally creates initial version and activates the job in one call.
48
+ *
49
+ * @param jobData - The job data including name, description, schedule, and optional version
50
+ * @param jobData.version - If provided, creates first version automatically
51
+ * @param jobData.activate - If true, activates the job immediately
47
52
  * @returns Promise resolving to an ApiResponse containing the created job details
48
53
  * @throws Error if the job creation fails or validation errors occur
49
54
  */
@@ -53,12 +58,19 @@ export default class JobApi extends HttpClient {
53
58
  });
54
59
  }
55
60
  /**
56
- * Creates a new job for the agent
57
- * @param jobData - The job data including name, description, and optional context
58
- * @returns Promise resolving to an JobInstance containing the created job details
61
+ * Creates a new job for the agent and returns a JobInstance.
62
+ * Supports automatic version creation and activation.
63
+ *
64
+ * @param jobData - The job data including name, description, schedule, and optional version
65
+ * @param jobData.version - If provided, creates first version automatically
66
+ * @param jobData.activate - If true, activates the job immediately
67
+ * @returns Promise resolving to a JobInstance containing the created job details
59
68
  * @throws Error if the job creation fails or validation errors occur
60
69
  */
61
70
  async createJobInstance(jobData) {
71
+ if (jobData.version?.executeFunction && jobData.version?.executeFunction.length > 0) {
72
+ jobData.version.code = this.compressCode(jobData.version.executeFunction);
73
+ }
62
74
  const response = await this.httpPost(`/developer/jobs/${this.agentId}`, jobData, {
63
75
  Authorization: `Bearer ${this.apiKey}`,
64
76
  });
@@ -67,6 +79,10 @@ export default class JobApi extends HttpClient {
67
79
  }
68
80
  throw new Error(response.error?.message || 'Failed to create job');
69
81
  }
82
+ compressCode(code) {
83
+ const compressed = gzipSync(code);
84
+ return compressed.toString('base64');
85
+ }
70
86
  /**
71
87
  * Pushes a new version of a job to production
72
88
  * @param jobId - The unique identifier of the job
@@ -59,8 +59,26 @@ export default class PostProcessorApi extends HttpClient {
59
59
  }): Promise<ApiResponse<CreatePostProcessorResponse>>;
60
60
  /**
61
61
  * Pushes a new version of a postprocessor
62
+ *
63
+ * @param postprocessorId - The postprocessor ID
64
+ * @param versionData - Version data including code, description, context, and async flag
65
+ * @param versionData.version - Version number
66
+ * @param versionData.code - Compressed execute function code
67
+ * @param versionData.executeFunction - Raw execute function code
68
+ * @param versionData.description - Postprocessor description
69
+ * @param versionData.context - Postprocessor context
70
+ * @param versionData.async - Async execution flag (true = background, false = blocking)
62
71
  */
63
- pushPostProcessor(postprocessorId: string, versionData: any): Promise<ApiResponse<PostProcessorVersionResponse>>;
72
+ pushPostProcessor(postprocessorId: string, versionData: {
73
+ name: string;
74
+ version: string;
75
+ description?: string;
76
+ context?: string;
77
+ postprocessorId: string;
78
+ code: string;
79
+ executeFunction: string;
80
+ async?: boolean;
81
+ }): Promise<ApiResponse<PostProcessorVersionResponse>>;
64
82
  /**
65
83
  * Retrieves all versions of a specific postprocessor
66
84
  */
@@ -95,4 +113,46 @@ export default class PostProcessorApi extends HttpClient {
95
113
  * Deletes a postprocessor
96
114
  */
97
115
  deletePostProcessor(postprocessorId: string): Promise<ApiResponse<DeletePostProcessorResponse>>;
116
+ /**
117
+ * Pushes a new sandbox (dev) version of a postprocessor
118
+ * Creates a new sandbox version for testing without affecting production
119
+ *
120
+ * @param postprocessorId - The postprocessor ID
121
+ * @param versionData - Version data including code and async flag
122
+ * @returns Sandbox version response with sandboxId
123
+ */
124
+ pushDevPostProcessor(postprocessorId: string, versionData: {
125
+ name: string;
126
+ version?: string;
127
+ description?: string;
128
+ context?: string;
129
+ code: string;
130
+ executeFunction: string;
131
+ async?: boolean;
132
+ }): Promise<ApiResponse<{
133
+ versionId: string;
134
+ postprocessorId: string;
135
+ version: string;
136
+ createdAt: string;
137
+ }>>;
138
+ /**
139
+ * Updates an existing sandbox version of a postprocessor
140
+ *
141
+ * @param postprocessorId - The postprocessor ID
142
+ * @param sandboxVersionId - The sandbox version ID to update
143
+ * @param versionData - Updated version data
144
+ * @returns Update response
145
+ */
146
+ updateDevPostProcessor(postprocessorId: string, sandboxVersionId: string, versionData: {
147
+ name: string;
148
+ version?: string;
149
+ description?: string;
150
+ context?: string;
151
+ code: string;
152
+ executeFunction: string;
153
+ async?: boolean;
154
+ }): Promise<ApiResponse<{
155
+ message: string;
156
+ versionId: string;
157
+ }>>;
98
158
  }
@@ -27,6 +27,15 @@ export default class PostProcessorApi extends HttpClient {
27
27
  }
28
28
  /**
29
29
  * Pushes a new version of a postprocessor
30
+ *
31
+ * @param postprocessorId - The postprocessor ID
32
+ * @param versionData - Version data including code, description, context, and async flag
33
+ * @param versionData.version - Version number
34
+ * @param versionData.code - Compressed execute function code
35
+ * @param versionData.executeFunction - Raw execute function code
36
+ * @param versionData.description - Postprocessor description
37
+ * @param versionData.context - Postprocessor context
38
+ * @param versionData.async - Async execution flag (true = background, false = blocking)
30
39
  */
31
40
  async pushPostProcessor(postprocessorId, versionData) {
32
41
  return this.httpPost(`/developer/postprocessors/${this.agentId}/${postprocessorId}/version`, versionData, {
@@ -73,4 +82,30 @@ export default class PostProcessorApi extends HttpClient {
73
82
  Authorization: `Bearer ${this.apiKey}`,
74
83
  });
75
84
  }
85
+ /**
86
+ * Pushes a new sandbox (dev) version of a postprocessor
87
+ * Creates a new sandbox version for testing without affecting production
88
+ *
89
+ * @param postprocessorId - The postprocessor ID
90
+ * @param versionData - Version data including code and async flag
91
+ * @returns Sandbox version response with sandboxId
92
+ */
93
+ async pushDevPostProcessor(postprocessorId, versionData) {
94
+ return this.httpPost(`/developer/postprocessors/${this.agentId}/${postprocessorId}/version/sandbox`, versionData, {
95
+ Authorization: `Bearer ${this.apiKey}`,
96
+ });
97
+ }
98
+ /**
99
+ * Updates an existing sandbox version of a postprocessor
100
+ *
101
+ * @param postprocessorId - The postprocessor ID
102
+ * @param sandboxVersionId - The sandbox version ID to update
103
+ * @param versionData - Updated version data
104
+ * @returns Update response
105
+ */
106
+ async updateDevPostProcessor(postprocessorId, sandboxVersionId, versionData) {
107
+ return this.httpPut(`/developer/postprocessors/${this.agentId}/${postprocessorId}/version/sandbox/${sandboxVersionId}`, versionData, {
108
+ Authorization: `Bearer ${this.apiKey}`,
109
+ });
110
+ }
76
111
  }
@@ -59,8 +59,26 @@ export default class PreProcessorApi extends HttpClient {
59
59
  }): Promise<ApiResponse<CreatePreProcessorResponse>>;
60
60
  /**
61
61
  * Pushes a new version of a preprocessor
62
+ *
63
+ * @param preprocessorId - The preprocessor ID
64
+ * @param versionData - Version data including code, description, context, and async flag
65
+ * @param versionData.version - Version number
66
+ * @param versionData.code - Compressed execute function code
67
+ * @param versionData.executeFunction - Raw execute function code
68
+ * @param versionData.description - Preprocessor description
69
+ * @param versionData.context - Preprocessor context
70
+ * @param versionData.async - Async execution flag (true = background, false = blocking)
62
71
  */
63
- pushPreProcessor(preprocessorId: string, versionData: any): Promise<ApiResponse<PreProcessorVersionResponse>>;
72
+ pushPreProcessor(preprocessorId: string, versionData: {
73
+ name: string;
74
+ version: string;
75
+ description?: string;
76
+ context?: string;
77
+ preprocessorId: string;
78
+ code: string;
79
+ executeFunction: string;
80
+ async?: boolean;
81
+ }): Promise<ApiResponse<PreProcessorVersionResponse>>;
64
82
  /**
65
83
  * Retrieves all versions of a specific preprocessor
66
84
  */
@@ -95,4 +113,46 @@ export default class PreProcessorApi extends HttpClient {
95
113
  * Deletes a preprocessor
96
114
  */
97
115
  deletePreProcessor(preprocessorId: string): Promise<ApiResponse<DeletePreProcessorResponse>>;
116
+ /**
117
+ * Pushes a new sandbox (dev) version of a preprocessor
118
+ * Creates a new sandbox version for testing without affecting production
119
+ *
120
+ * @param preprocessorId - The preprocessor ID
121
+ * @param versionData - Version data including code and async flag
122
+ * @returns Sandbox version response with sandboxId
123
+ */
124
+ pushDevPreProcessor(preprocessorId: string, versionData: {
125
+ name: string;
126
+ version?: string;
127
+ description?: string;
128
+ context?: string;
129
+ code: string;
130
+ executeFunction: string;
131
+ async?: boolean;
132
+ }): Promise<ApiResponse<{
133
+ versionId: string;
134
+ preprocessorId: string;
135
+ version: string;
136
+ createdAt: string;
137
+ }>>;
138
+ /**
139
+ * Updates an existing sandbox version of a preprocessor
140
+ *
141
+ * @param preprocessorId - The preprocessor ID
142
+ * @param sandboxVersionId - The sandbox version ID to update
143
+ * @param versionData - Updated version data
144
+ * @returns Update response
145
+ */
146
+ updateDevPreProcessor(preprocessorId: string, sandboxVersionId: string, versionData: {
147
+ name: string;
148
+ version?: string;
149
+ description?: string;
150
+ context?: string;
151
+ code: string;
152
+ executeFunction: string;
153
+ async?: boolean;
154
+ }): Promise<ApiResponse<{
155
+ message: string;
156
+ versionId: string;
157
+ }>>;
98
158
  }
@@ -27,6 +27,15 @@ export default class PreProcessorApi extends HttpClient {
27
27
  }
28
28
  /**
29
29
  * Pushes a new version of a preprocessor
30
+ *
31
+ * @param preprocessorId - The preprocessor ID
32
+ * @param versionData - Version data including code, description, context, and async flag
33
+ * @param versionData.version - Version number
34
+ * @param versionData.code - Compressed execute function code
35
+ * @param versionData.executeFunction - Raw execute function code
36
+ * @param versionData.description - Preprocessor description
37
+ * @param versionData.context - Preprocessor context
38
+ * @param versionData.async - Async execution flag (true = background, false = blocking)
30
39
  */
31
40
  async pushPreProcessor(preprocessorId, versionData) {
32
41
  return this.httpPost(`/developer/preprocessors/${this.agentId}/${preprocessorId}/version`, versionData, {
@@ -73,4 +82,30 @@ export default class PreProcessorApi extends HttpClient {
73
82
  Authorization: `Bearer ${this.apiKey}`,
74
83
  });
75
84
  }
85
+ /**
86
+ * Pushes a new sandbox (dev) version of a preprocessor
87
+ * Creates a new sandbox version for testing without affecting production
88
+ *
89
+ * @param preprocessorId - The preprocessor ID
90
+ * @param versionData - Version data including code and async flag
91
+ * @returns Sandbox version response with sandboxId
92
+ */
93
+ async pushDevPreProcessor(preprocessorId, versionData) {
94
+ return this.httpPost(`/developer/preprocessors/${this.agentId}/${preprocessorId}/version/sandbox`, versionData, {
95
+ Authorization: `Bearer ${this.apiKey}`,
96
+ });
97
+ }
98
+ /**
99
+ * Updates an existing sandbox version of a preprocessor
100
+ *
101
+ * @param preprocessorId - The preprocessor ID
102
+ * @param sandboxVersionId - The sandbox version ID to update
103
+ * @param versionData - Updated version data
104
+ * @returns Update response
105
+ */
106
+ async updateDevPreProcessor(preprocessorId, sandboxVersionId, versionData) {
107
+ return this.httpPut(`/developer/preprocessors/${this.agentId}/${preprocessorId}/version/sandbox/${sandboxVersionId}`, versionData, {
108
+ Authorization: `Bearer ${this.apiKey}`,
109
+ });
110
+ }
76
111
  }
@@ -29,7 +29,7 @@
29
29
  import { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, 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
- import { ChatHistoryMessage, ChatHistoryContent } from "./interfaces/chat.js";
32
+ import { ChatHistoryMessage, ChatHistoryContent, ChatMessage, TextMessage, ImageMessage, FileMessage, PreProcessorOverride, PostProcessorOverride } from "./interfaces/chat.js";
33
33
  import { JobInstance } from "./common/job.instance.js";
34
34
  import { DeleteProductResponse, Product } from "./interfaces/product.js";
35
35
  import ProductInstance from "./common/product.instance.js";
@@ -291,6 +291,13 @@ export declare const Jobs: {
291
291
  * Creates a new job dynamically from within a tool.
292
292
  * This allows tools to schedule one-time or recurring jobs programmatically.
293
293
  *
294
+ * **What this does:**
295
+ * The server handles everything in ONE API call:
296
+ * 1. Creates the job
297
+ * 2. Creates version 1.0.0 with your execute function
298
+ * 3. Optionally activates the job (if activate: true)
299
+ * 4. Returns a JobInstance for manipulation
300
+ *
294
301
  * @param config - Job configuration
295
302
  * @param config.name - Unique job name
296
303
  * @param config.description - Job description
@@ -298,26 +305,37 @@ export declare const Jobs: {
298
305
  * @param config.execute - Async function to execute
299
306
  * @param config.timeout - Optional timeout in seconds
300
307
  * @param config.retry - Optional retry configuration
301
- * @returns Promise resolving to created job details
308
+ * @param config.metadata - Optional metadata
309
+ * @returns Promise resolving to JobInstance (already created, versioned, and activated)
302
310
  *
303
311
  * @example
304
312
  * ```typescript
305
313
  * // Create a one-time job to check basket in 3 hours
306
- * await Jobs.create({
314
+ * const job = await Jobs.create({
307
315
  * name: `check-basket-${basketId}`,
308
316
  * description: 'Check if basket was abandoned',
309
317
  * schedule: {
310
318
  * type: 'once',
311
319
  * executeAt: new Date(Date.now() + 3 * 60 * 60 * 1000)
312
320
  * },
313
- * execute: async () => {
314
- * const basket = await Baskets.getById(basketId);
321
+ * metadata: {
322
+ * basketId: basketId,
323
+ * checkType: 'abandoned-cart'
324
+ * },
325
+ * execute: async (job, user) => {
326
+ * // Access user context and metadata
327
+ * console.log('Checking basket for user:', user.name);
328
+ * console.log('Basket ID from metadata:', metadata?.basketId);
329
+ *
330
+ * const basket = await Baskets.getById(metadata.basketId);
315
331
  * if (basket.status === 'active') {
316
332
  * // Send reminder
317
333
  * }
318
334
  * return { checked: true };
319
335
  * }
320
336
  * });
337
+ * // Job is now created, versioned as 1.0.0, and activated!
338
+ * console.log(`Job ${job.jobId} is active: ${job.active}`);
321
339
  * ```
322
340
  */
323
341
  create(config: {
@@ -331,6 +349,8 @@ export declare const Jobs: {
331
349
  backoffSeconds?: number;
332
350
  };
333
351
  metadata?: Record<string, any>;
352
+ /** Auto-activate the job after creation (default: true) */
353
+ activate?: boolean;
334
354
  }): Promise<JobInstance>;
335
355
  /**
336
356
  * Retrieves a job by its unique identifier
@@ -382,5 +402,5 @@ export declare const AI: {
382
402
  generate(context: string, messages: import("./interfaces/chat.js").ChatMessage[], agentId?: string): Promise<string>;
383
403
  };
384
404
  export { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, PostProcessor, PostProcessorConfig, LuaAgent, LuaAgentConfig, BasketStatus, OrderStatus, env };
385
- export { JobInstance };
386
- export { ChatHistoryMessage, ChatHistoryContent };
405
+ export { JobInstance, UserDataInstance, DataEntryInstance, ProductInstance, BasketInstance, OrderInstance };
406
+ export { ChatHistoryMessage, ChatHistoryContent, ChatMessage, TextMessage, ImageMessage, FileMessage, PreProcessorOverride, PostProcessorOverride };
@@ -31,6 +31,11 @@ import { BasketStatus } from "./interfaces/baskets.js";
31
31
  import { OrderStatus } from "./interfaces/orders.js";
32
32
  import { getUserInstance, getDataInstance, getProductsInstance, getBasketsInstance, getOrderInstance, getJobInstance, getChatInstance, } from "./api/lazy-instances.js";
33
33
  import { JobInstance } from "./common/job.instance.js";
34
+ import ProductInstance from "./common/product.instance.js";
35
+ import DataEntryInstance from "./common/data.entry.instance.js";
36
+ import UserDataInstance from "./common/user.instance.js";
37
+ import BasketInstance from "./common/basket.instance.js";
38
+ import OrderInstance from "./common/order.instance.js";
34
39
  export const User = {
35
40
  /**
36
41
  * Retrieves current user data.
@@ -378,6 +383,13 @@ export const Jobs = {
378
383
  * Creates a new job dynamically from within a tool.
379
384
  * This allows tools to schedule one-time or recurring jobs programmatically.
380
385
  *
386
+ * **What this does:**
387
+ * The server handles everything in ONE API call:
388
+ * 1. Creates the job
389
+ * 2. Creates version 1.0.0 with your execute function
390
+ * 3. Optionally activates the job (if activate: true)
391
+ * 4. Returns a JobInstance for manipulation
392
+ *
381
393
  * @param config - Job configuration
382
394
  * @param config.name - Unique job name
383
395
  * @param config.description - Job description
@@ -385,72 +397,78 @@ export const Jobs = {
385
397
  * @param config.execute - Async function to execute
386
398
  * @param config.timeout - Optional timeout in seconds
387
399
  * @param config.retry - Optional retry configuration
388
- * @returns Promise resolving to created job details
400
+ * @param config.metadata - Optional metadata
401
+ * @returns Promise resolving to JobInstance (already created, versioned, and activated)
389
402
  *
390
403
  * @example
391
404
  * ```typescript
392
405
  * // Create a one-time job to check basket in 3 hours
393
- * await Jobs.create({
406
+ * const job = await Jobs.create({
394
407
  * name: `check-basket-${basketId}`,
395
408
  * description: 'Check if basket was abandoned',
396
409
  * schedule: {
397
410
  * type: 'once',
398
411
  * executeAt: new Date(Date.now() + 3 * 60 * 60 * 1000)
399
412
  * },
400
- * execute: async () => {
401
- * const basket = await Baskets.getById(basketId);
413
+ * metadata: {
414
+ * basketId: basketId,
415
+ * checkType: 'abandoned-cart'
416
+ * },
417
+ * execute: async (job, user) => {
418
+ * // Access user context and metadata
419
+ * console.log('Checking basket for user:', user.name);
420
+ * console.log('Basket ID from metadata:', metadata?.basketId);
421
+ *
422
+ * const basket = await Baskets.getById(metadata.basketId);
402
423
  * if (basket.status === 'active') {
403
424
  * // Send reminder
404
425
  * }
405
426
  * return { checked: true };
406
427
  * }
407
428
  * });
429
+ * // Job is now created, versioned as 1.0.0, and activated!
430
+ * console.log(`Job ${job.jobId} is active: ${job.active}`);
408
431
  * ```
409
432
  */
410
433
  async create(config) {
411
434
  const instance = await getJobInstance();
412
435
  // Convert the execute function to a string
413
436
  const executeString = config.execute.toString();
414
- // Step 1: Create the job
437
+ console.log('Creating Job');
438
+ // Create the job with initial version and activation in one call
415
439
  const createResult = await instance.createJobInstance({
440
+ dynamic: true,
416
441
  name: config.name,
417
442
  description: config.description,
418
443
  context: config.description || '',
419
444
  schedule: config.schedule,
420
445
  timeout: config.timeout,
421
446
  retry: config.retry,
422
- metadata: config.metadata
447
+ metadata: config.metadata,
448
+ // Include initial version data for automatic version creation
449
+ version: {
450
+ version: '1.0.0',
451
+ description: config.description,
452
+ context: config.description || '',
453
+ code: '', // Will be set by server
454
+ executeFunction: executeString,
455
+ timeout: config.timeout,
456
+ retry: config.retry,
457
+ metadata: config.metadata
458
+ },
459
+ // Activate immediately
460
+ activate: config.activate ?? true
423
461
  });
424
462
  const jobId = createResult.jobId;
425
- // Step 2: Push the initial version with execute function
426
- const pushResult = await instance.pushJob(jobId, {
427
- name: config.name,
428
- version: '1.0.0',
429
- description: config.description,
430
- context: config.description || '',
431
- jobId: jobId,
432
- schedule: config.schedule,
433
- timeout: config.timeout,
434
- retry: config.retry,
435
- executeFunction: executeString,
436
- metadata: config.metadata
437
- });
438
- if (!pushResult.success) {
439
- throw new Error(`Failed to push job version: ${pushResult.error?.message}`);
440
- }
441
- // Step 3: Activate the job so it starts running
442
- const activateResult = await instance.activateJob(jobId);
443
- if (!activateResult.success) {
444
- console.warn(`Job created but activation failed: ${activateResult.error?.message}`);
445
- }
446
- // Step 4: Return a JobInstance for easy manipulation
463
+ // Server has created the job, version, and activated it
464
+ // Return a JobInstance for easy manipulation
447
465
  return new JobInstance(instance, {
448
466
  id: jobId,
449
467
  jobId: jobId,
450
468
  name: config.name,
451
469
  schedule: config.schedule,
452
470
  metadata: config.metadata || {},
453
- active: activateResult.success
471
+ active: config.activate ?? true
454
472
  });
455
473
  },
456
474
  /**
@@ -530,4 +548,4 @@ export const AI = {
530
548
  // Export skill classes and utilities
531
549
  export { LuaSkill, LuaWebhook, LuaJob, PreProcessor, PostProcessor, LuaAgent, BasketStatus, OrderStatus, env };
532
550
  // Export instance classes
533
- export { JobInstance };
551
+ export { JobInstance, UserDataInstance, DataEntryInstance, ProductInstance, BasketInstance, OrderInstance };