lua-cli 2.5.8 → 3.0.0-alpha.1

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 (98) hide show
  1. package/dist/api/job.api.service.d.ts +210 -0
  2. package/dist/api/job.api.service.js +200 -0
  3. package/dist/api/lazy-instances.d.ts +24 -0
  4. package/dist/api/lazy-instances.js +48 -0
  5. package/dist/api/postprocessor.api.service.d.ts +98 -0
  6. package/dist/api/postprocessor.api.service.js +76 -0
  7. package/dist/api/preprocessor.api.service.d.ts +98 -0
  8. package/dist/api/preprocessor.api.service.js +76 -0
  9. package/dist/api/user.data.api.service.d.ts +13 -0
  10. package/dist/api/user.data.api.service.js +20 -0
  11. package/dist/api/webhook.api.service.d.ts +151 -0
  12. package/dist/api/webhook.api.service.js +134 -0
  13. package/dist/api-exports.d.ts +156 -41
  14. package/dist/api-exports.js +182 -21
  15. package/dist/cli/command-definitions.js +75 -5
  16. package/dist/commands/compile.js +124 -5
  17. package/dist/commands/index.d.ts +4 -0
  18. package/dist/commands/index.js +4 -0
  19. package/dist/commands/init.js +53 -7
  20. package/dist/commands/jobs.d.ts +20 -0
  21. package/dist/commands/jobs.js +533 -0
  22. package/dist/commands/logs.js +2 -5
  23. package/dist/commands/postprocessors.d.ts +8 -0
  24. package/dist/commands/postprocessors.js +431 -0
  25. package/dist/commands/preprocessors.d.ts +8 -0
  26. package/dist/commands/preprocessors.js +431 -0
  27. package/dist/commands/push.js +684 -5
  28. package/dist/commands/test.d.ts +9 -18
  29. package/dist/commands/test.js +558 -82
  30. package/dist/commands/webhooks.d.ts +18 -0
  31. package/dist/commands/webhooks.js +424 -0
  32. package/dist/common/job.instance.d.ts +77 -0
  33. package/dist/common/job.instance.js +108 -0
  34. package/dist/common/user.instance.d.ts +1 -0
  35. package/dist/common/user.instance.js +9 -0
  36. package/dist/config/constants.d.ts +2 -2
  37. package/dist/config/constants.js +4 -4
  38. package/dist/interfaces/agent.d.ts +2 -1
  39. package/dist/interfaces/chat.d.ts +22 -0
  40. package/dist/interfaces/index.d.ts +10 -0
  41. package/dist/interfaces/index.js +7 -0
  42. package/dist/interfaces/jobs.d.ts +172 -0
  43. package/dist/interfaces/jobs.js +5 -0
  44. package/dist/interfaces/postprocessors.d.ts +35 -0
  45. package/dist/interfaces/postprocessors.js +4 -0
  46. package/dist/interfaces/preprocessors.d.ts +35 -0
  47. package/dist/interfaces/preprocessors.js +4 -0
  48. package/dist/interfaces/webhooks.d.ts +104 -0
  49. package/dist/interfaces/webhooks.js +5 -0
  50. package/dist/types/api-contracts.d.ts +5 -0
  51. package/dist/types/compile.types.d.ts +49 -0
  52. package/dist/types/index.d.ts +1 -1
  53. package/dist/types/index.js +1 -1
  54. package/dist/types/skill.d.ts +502 -0
  55. package/dist/types/skill.js +477 -0
  56. package/dist/utils/agent-management.d.ts +25 -0
  57. package/dist/utils/agent-management.js +67 -0
  58. package/dist/utils/bundling.d.ts +31 -1
  59. package/dist/utils/bundling.js +653 -10
  60. package/dist/utils/compile.d.ts +63 -0
  61. package/dist/utils/compile.js +691 -36
  62. package/dist/utils/deployment.d.ts +2 -1
  63. package/dist/utils/deployment.js +16 -2
  64. package/dist/utils/init-agent.d.ts +3 -1
  65. package/dist/utils/init-agent.js +6 -4
  66. package/dist/utils/init-prompts.d.ts +2 -1
  67. package/dist/utils/init-prompts.js +14 -9
  68. package/dist/utils/job-management.d.ts +24 -0
  69. package/dist/utils/job-management.js +264 -0
  70. package/dist/utils/postprocessor-management.d.ts +9 -0
  71. package/dist/utils/postprocessor-management.js +118 -0
  72. package/dist/utils/preprocessor-management.d.ts +9 -0
  73. package/dist/utils/preprocessor-management.js +118 -0
  74. package/dist/utils/sandbox.d.ts +61 -1
  75. package/dist/utils/sandbox.js +283 -72
  76. package/dist/utils/tool-detection.d.ts +3 -2
  77. package/dist/utils/tool-detection.js +18 -4
  78. package/dist/utils/webhook-management.d.ts +24 -0
  79. package/dist/utils/webhook-management.js +256 -0
  80. package/package.json +1 -1
  81. package/template/AGENT_CONFIGURATION.md +251 -0
  82. package/template/COMPLEX_JOB_EXAMPLES.md +795 -0
  83. package/template/DYNAMIC_JOB_CREATION.md +371 -0
  84. package/template/README.md +30 -2
  85. package/template/WEBHOOKS_JOBS_QUICKSTART.md +318 -0
  86. package/template/WEBHOOK_JOB_EXAMPLES.md +817 -0
  87. package/template/src/index-agent-example.ts +201 -0
  88. package/template/src/index.ts +39 -0
  89. package/template/src/jobs/AbandonedBasketProcessorJob.ts +139 -0
  90. package/template/src/jobs/DailyCleanupJob.ts +100 -0
  91. package/template/src/jobs/DataMigrationJob.ts +133 -0
  92. package/template/src/jobs/HealthCheckJob.ts +87 -0
  93. package/template/src/postprocessors/ResponseFormatter.ts +151 -0
  94. package/template/src/preprocessors/MessageFilter.ts +91 -0
  95. package/template/src/tools/GameScoreTrackerTool.ts +356 -0
  96. package/template/src/tools/SmartBasketTool.ts +188 -0
  97. package/template/src/webhooks/PaymentWebhook.ts +113 -0
  98. package/template/src/webhooks/UserEventWebhook.ts +77 -0
@@ -26,20 +26,42 @@
26
26
  * const products = await Products.search('laptop');
27
27
  * ```
28
28
  */
29
- import { LuaSkill, LuaTool, env } from "./types/skill.js";
30
- import { BasketStatus } from "./interfaces/baskets.js";
31
- import { OrderStatus } from "./interfaces/orders.js";
32
- /**
33
- * User Data API
34
- * Access user information and preferences
35
- */
29
+ import { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, PostProcessor, PostProcessorConfig, LuaAgent, LuaAgentConfig, env } from "./types/skill.js";
30
+ import { Basket, BasketStatus, UpdateBasketMetadataResponse } from "./interfaces/baskets.js";
31
+ import { OrderResponse, OrderStatus } from "./interfaces/orders.js";
32
+ import { ChatHistoryMessage, ChatHistoryContent } from "./interfaces/chat.js";
33
+ import { JobInstance } from "./common/job.instance.js";
34
+ import { DeleteProductResponse, Product } from "./interfaces/product.js";
35
+ import ProductInstance from "./common/product.instance.js";
36
+ import ProductPaginationInstance from "./common/product.pagination.instance.js";
37
+ import ProductSearchInstance from "./common/product.search.instance.js";
38
+ import DataEntryInstance from "./common/data.entry.instance.js";
39
+ import { DeleteCustomDataResponse, GetCustomDataResponse, UpdateCustomDataResponse } from "./interfaces/custom.data.js";
40
+ import UserDataInstance from "./common/user.instance.js";
41
+ import BasketInstance from "./common/basket.instance.js";
42
+ import OrderInstance from "./common/order.instance.js";
36
43
  export declare const User: {
37
44
  /**
38
45
  * Retrieves current user data.
39
46
  *
40
47
  * @returns Promise resolving to user data
41
48
  */
42
- get(): Promise<import("./common/user.instance.js").default>;
49
+ get(): Promise<UserDataInstance>;
50
+ /**
51
+ * Gets the chat history for the current user.
52
+ *
53
+ * @returns Promise resolving to array of chat messages
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const history = await User.getChatHistory();
58
+ * // Returns: [
59
+ * // { role: 'user', content: [{type: 'text', text: 'hello'}], createdAt: '...', id: '...', threadId: '...' },
60
+ * // { role: 'assistant', content: [{type: 'text', text: 'hi'}], createdAt: '...', id: '...', threadId: '...' }
61
+ * // ]
62
+ * ```
63
+ */
64
+ getChatHistory(): Promise<import("./interfaces/chat.js").ChatHistoryMessage[]>;
43
65
  };
44
66
  /**
45
67
  * Custom Data API
@@ -54,7 +76,7 @@ export declare const Data: {
54
76
  * @param searchText - Optional text for vector search indexing
55
77
  * @returns Promise resolving to created entry
56
78
  */
57
- create(collectionName: string, data: any, searchText?: string): Promise<import("./common/data.entry.instance.js").default>;
79
+ create(collectionName: string, data: any, searchText?: string): Promise<DataEntryInstance>;
58
80
  /**
59
81
  * Retrieves entries from a collection with optional filtering and pagination.
60
82
  *
@@ -64,7 +86,7 @@ export declare const Data: {
64
86
  * @param limit - Items per page (default: 10)
65
87
  * @returns Promise resolving to array of entries
66
88
  */
67
- get(collectionName: string, filter?: any, page?: number, limit?: number): Promise<import("./interfaces/custom.data.js").GetCustomDataResponse>;
89
+ get(collectionName: string, filter?: any, page?: number, limit?: number): Promise<GetCustomDataResponse>;
68
90
  /**
69
91
  * Retrieves a specific entry by ID.
70
92
  *
@@ -72,7 +94,7 @@ export declare const Data: {
72
94
  * @param entryId - ID of the entry
73
95
  * @returns Promise resolving to entry data
74
96
  */
75
- getEntry(collectionName: string, entryId: string): Promise<import("./common/data.entry.instance.js").default>;
97
+ getEntry(collectionName: string, entryId: string): Promise<DataEntryInstance>;
76
98
  /**
77
99
  * Updates an existing entry.
78
100
  *
@@ -81,7 +103,7 @@ export declare const Data: {
81
103
  * @param data - Updated data
82
104
  * @returns Promise resolving to updated entry
83
105
  */
84
- update(collectionName: string, entryId: string, data: any): Promise<import("./interfaces/custom.data.js").UpdateCustomDataResponse>;
106
+ update(collectionName: string, entryId: string, data: any): Promise<UpdateCustomDataResponse>;
85
107
  /**
86
108
  * Performs vector search on a collection.
87
109
  *
@@ -91,7 +113,7 @@ export declare const Data: {
91
113
  * @param scoreThreshold - Minimum similarity score (0-1)
92
114
  * @returns Promise resolving to search results
93
115
  */
94
- search(collectionName: string, searchText: string, limit?: number, scoreThreshold?: number): Promise<import("./common/data.entry.instance.js").default[]>;
116
+ search(collectionName: string, searchText: string, limit?: number, scoreThreshold?: number): Promise<DataEntryInstance[]>;
95
117
  /**
96
118
  * Deletes an entry from a collection.
97
119
  *
@@ -99,7 +121,7 @@ export declare const Data: {
99
121
  * @param entryId - ID of the entry to delete
100
122
  * @returns Promise resolving when deletion is complete
101
123
  */
102
- delete(collectionName: string, entryId: string): Promise<import("./interfaces/custom.data.js").DeleteCustomDataResponse>;
124
+ delete(collectionName: string, entryId: string): Promise<DeleteCustomDataResponse>;
103
125
  };
104
126
  /**
105
127
  * Products API
@@ -113,43 +135,35 @@ export declare const Products: {
113
135
  * @param page - Page number
114
136
  * @returns Promise resolving to product list
115
137
  */
116
- get(limit?: number, page?: number): Promise<import("./common/product.pagination.instance.js").default>;
138
+ get(limit?: number, page?: number): Promise<ProductPaginationInstance>;
117
139
  /**
118
140
  * Creates a new product.
119
141
  *
120
142
  * @param product - Product data
121
143
  * @returns Promise resolving to created product
122
144
  */
123
- create(product: any): Promise<import("./common/product.instance.js").default>;
124
- /**
125
- * Updates an existing product.
126
- *
127
- * @param data - Updated product data
128
- * @param id - Product ID
129
- * @returns Promise resolving to updated product
130
- */
131
- update(data: any, id: string): Promise<import("./interfaces/product.js").UpdateProductResponse>;
145
+ create(product: Product): Promise<ProductInstance>;
132
146
  /**
133
147
  * Deletes a product.
134
148
  *
135
149
  * @param id - Product ID
136
150
  * @returns Promise resolving when deletion is complete
137
151
  */
138
- delete(id: string): Promise<import("./interfaces/product.js").DeleteProductResponse>;
152
+ delete(id: string): Promise<DeleteProductResponse>;
139
153
  /**
140
154
  * Searches products by query string.
141
155
  *
142
156
  * @param query - Search query
143
157
  * @returns Promise resolving to search results
144
158
  */
145
- search(query: string): Promise<import("./common/product.search.instance.js").default>;
159
+ search(query: string): Promise<ProductSearchInstance>;
146
160
  /**
147
161
  * Retrieves a specific product by ID.
148
162
  *
149
163
  * @param id - Product ID
150
164
  * @returns Promise resolving to product data
151
165
  */
152
- getById(id: string): Promise<import("./common/product.instance.js").default>;
166
+ getById(id: string): Promise<ProductInstance>;
153
167
  };
154
168
  /**
155
169
  * Baskets API
@@ -162,14 +176,14 @@ export declare const Baskets: {
162
176
  * @param basketData - Basket initialization data
163
177
  * @returns Promise resolving to created basket
164
178
  */
165
- create(basketData: any): Promise<import("./common/basket.instance.js").default>;
179
+ create(basketData: any): Promise<BasketInstance>;
166
180
  /**
167
181
  * Retrieves baskets, optionally filtered by status.
168
182
  *
169
183
  * @param status - Optional basket status filter
170
184
  * @returns Promise resolving to basket list
171
185
  */
172
- get(status?: any): Promise<import("./common/basket.instance.js").default[]>;
186
+ get(status?: any): Promise<BasketInstance[]>;
173
187
  /**
174
188
  * Adds an item to a basket.
175
189
  *
@@ -177,7 +191,7 @@ export declare const Baskets: {
177
191
  * @param itemData - Item data to add
178
192
  * @returns Promise resolving to updated basket
179
193
  */
180
- addItem(basketId: string, itemData: any): Promise<import("./interfaces/baskets.js").Basket>;
194
+ addItem(basketId: string, itemData: any): Promise<Basket>;
181
195
  /**
182
196
  * Removes an item from a basket.
183
197
  *
@@ -185,14 +199,14 @@ export declare const Baskets: {
185
199
  * @param itemId - Item ID to remove
186
200
  * @returns Promise resolving to updated basket
187
201
  */
188
- removeItem(basketId: string, itemId: string): Promise<import("./interfaces/baskets.js").Basket>;
202
+ removeItem(basketId: string, itemId: string): Promise<Basket>;
189
203
  /**
190
204
  * Clears all items from a basket.
191
205
  *
192
206
  * @param basketId - Basket ID
193
207
  * @returns Promise resolving to cleared basket
194
208
  */
195
- clear(basketId: string): Promise<import("./interfaces/baskets.js").Basket>;
209
+ clear(basketId: string): Promise<Basket>;
196
210
  /**
197
211
  * Updates basket status.
198
212
  *
@@ -208,7 +222,7 @@ export declare const Baskets: {
208
222
  * @param metadata - Metadata to update
209
223
  * @returns Promise resolving to updated basket
210
224
  */
211
- updateMetadata(basketId: string, metadata: any): Promise<import("./interfaces/baskets.js").UpdateBasketMetadataResponse>;
225
+ updateMetadata(basketId: string, metadata: any): Promise<UpdateBasketMetadataResponse>;
212
226
  /**
213
227
  * Converts basket to order.
214
228
  *
@@ -216,14 +230,14 @@ export declare const Baskets: {
216
230
  * @param basketId - Basket ID to convert
217
231
  * @returns Promise resolving to created order
218
232
  */
219
- placeOrder(data: Record<string, any>, basketId: string): Promise<import("./common/order.instance.js").default>;
233
+ placeOrder(data: Record<string, any>, basketId: string): Promise<OrderInstance>;
220
234
  /**
221
235
  * Retrieves a specific basket by ID.
222
236
  *
223
237
  * @param basketId - Basket ID
224
238
  * @returns Promise resolving to basket data
225
239
  */
226
- getById(basketId: string): Promise<import("./common/basket.instance.js").default>;
240
+ getById(basketId: string): Promise<BasketInstance>;
227
241
  };
228
242
  /**
229
243
  * Orders API
@@ -236,7 +250,7 @@ export declare const Orders: {
236
250
  * @param orderData - Order data
237
251
  * @returns Promise resolving to created order
238
252
  */
239
- create(orderData: any): Promise<import("./common/order.instance.js").default>;
253
+ create(orderData: any): Promise<OrderInstance>;
240
254
  /**
241
255
  * Updates order status.
242
256
  *
@@ -244,7 +258,7 @@ export declare const Orders: {
244
258
  * @param orderId - Order ID
245
259
  * @returns Promise resolving to updated order
246
260
  */
247
- updateStatus(status: any, orderId: string): Promise<import("./interfaces/orders.js").OrderResponse>;
261
+ updateStatus(status: any, orderId: string): Promise<OrderResponse>;
248
262
  /**
249
263
  * Updates order data.
250
264
  *
@@ -252,20 +266,121 @@ export declare const Orders: {
252
266
  * @param orderId - Order ID
253
267
  * @returns Promise resolving to updated order
254
268
  */
255
- updateData(data: Record<string, any>, orderId: string): Promise<import("./interfaces/orders.js").OrderResponse>;
269
+ updateData(data: Record<string, any>, orderId: string): Promise<OrderResponse>;
256
270
  /**
257
271
  * Retrieves orders, optionally filtered by status.
258
272
  *
259
273
  * @param status - Optional order status filter
260
274
  * @returns Promise resolving to order list
261
275
  */
262
- get(status?: any): Promise<import("./common/order.instance.js").default[]>;
276
+ get(status?: any): Promise<OrderInstance[]>;
263
277
  /**
264
278
  * Retrieves a specific order by ID.
265
279
  *
266
280
  * @param orderId - Order ID
267
281
  * @returns Promise resolving to order data
268
282
  */
269
- getById(orderId: string): Promise<import("./common/order.instance.js").default>;
283
+ getById(orderId: string): Promise<OrderInstance>;
284
+ };
285
+ /**
286
+ * Jobs API
287
+ * Manage and trigger scheduled jobs from within your tools
288
+ */
289
+ export declare const Jobs: {
290
+ /**
291
+ * Creates a new job dynamically from within a tool.
292
+ * This allows tools to schedule one-time or recurring jobs programmatically.
293
+ *
294
+ * @param config - Job configuration
295
+ * @param config.name - Unique job name
296
+ * @param config.description - Job description
297
+ * @param config.schedule - Schedule configuration (cron, once, or interval)
298
+ * @param config.execute - Async function to execute
299
+ * @param config.timeout - Optional timeout in seconds
300
+ * @param config.retry - Optional retry configuration
301
+ * @returns Promise resolving to created job details
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * // Create a one-time job to check basket in 3 hours
306
+ * await Jobs.create({
307
+ * name: `check-basket-${basketId}`,
308
+ * description: 'Check if basket was abandoned',
309
+ * schedule: {
310
+ * type: 'once',
311
+ * executeAt: new Date(Date.now() + 3 * 60 * 60 * 1000)
312
+ * },
313
+ * execute: async () => {
314
+ * const basket = await Baskets.getById(basketId);
315
+ * if (basket.status === 'active') {
316
+ * // Send reminder
317
+ * }
318
+ * return { checked: true };
319
+ * }
320
+ * });
321
+ * ```
322
+ */
323
+ create(config: {
324
+ name: string;
325
+ description?: string;
326
+ schedule: any;
327
+ execute: (job: JobInstance) => Promise<any>;
328
+ timeout?: number;
329
+ retry?: {
330
+ maxAttempts: number;
331
+ backoffSeconds?: number;
332
+ };
333
+ metadata?: Record<string, any>;
334
+ }): Promise<JobInstance>;
335
+ /**
336
+ * Retrieves a job by its unique identifier
337
+ * @param jobId - The unique identifier of the job to retrieve
338
+ * @returns Promise resolving to an JobInstance representing the job
339
+ * @throws Error if the job is not found or the request fails
340
+ */
341
+ getJob(jobId: string): Promise<JobInstance>;
342
+ };
343
+ /**
344
+ * AI API
345
+ * Generate AI responses with custom context
346
+ */
347
+ export declare const AI: {
348
+ /**
349
+ * Generates an AI response with custom runtime context.
350
+ *
351
+ * @param context - Runtime context to provide to the AI
352
+ * @param messages - Array of messages (text, image, file, etc.)
353
+ * @param agentId - Optional agent ID to use (defaults to current agent)
354
+ * @returns Promise resolving to AI response text
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * // Simple text message with current agent
359
+ * const response = await AI.generate(
360
+ * 'You are a helpful sales assistant for our e-commerce store.',
361
+ * [{ type: 'text', text: 'What products do you recommend for beginners?' }]
362
+ * );
363
+ * console.log(response); // AI-generated recommendation
364
+ *
365
+ * // Multiple messages with images
366
+ * const response2 = await AI.generate(
367
+ * 'You are an image analysis expert.',
368
+ * [
369
+ * { type: 'text', text: 'What do you see in this image?' },
370
+ * { type: 'image', url: 'https://example.com/image.jpg' }
371
+ * ]
372
+ * );
373
+ *
374
+ * // Use a different agent
375
+ * const response3 = await AI.generate(
376
+ * 'You are a specialized assistant.',
377
+ * [{ type: 'text', text: 'Help me with this task' }],
378
+ * 'agent_different_123'
379
+ * );
380
+ * ```
381
+ */
382
+ generate(context: string, messages: import("./interfaces/chat.js").ChatMessage[], agentId?: string): Promise<string>;
270
383
  };
271
- export { LuaSkill, LuaTool, BasketStatus, OrderStatus, env };
384
+ export { LuaSkill, LuaTool, LuaWebhook, LuaWebhookConfig, LuaJob, LuaJobConfig, JobSchedule, PreProcessor, PreProcessorConfig, PostProcessor, PostProcessorConfig, LuaAgent, LuaAgentConfig, BasketStatus, OrderStatus, env };
385
+ export { JobInstance };
386
+ export { ChatHistoryMessage, ChatHistoryContent };
@@ -26,17 +26,11 @@
26
26
  * const products = await Products.search('laptop');
27
27
  * ```
28
28
  */
29
- import { LuaSkill, env } from "./types/skill.js";
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, } from "./api/lazy-instances.js";
33
- // ============================================================================
34
- // USER DATA API
35
- // ============================================================================
36
- /**
37
- * User Data API
38
- * Access user information and preferences
39
- */
32
+ import { getUserInstance, getDataInstance, getProductsInstance, getBasketsInstance, getOrderInstance, getJobInstance, getChatInstance, } from "./api/lazy-instances.js";
33
+ import { JobInstance } from "./common/job.instance.js";
40
34
  export const User = {
41
35
  /**
42
36
  * Retrieves current user data.
@@ -46,6 +40,24 @@ export const User = {
46
40
  async get() {
47
41
  const instance = await getUserInstance();
48
42
  return instance.get();
43
+ },
44
+ /**
45
+ * Gets the chat history for the current user.
46
+ *
47
+ * @returns Promise resolving to array of chat messages
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const history = await User.getChatHistory();
52
+ * // Returns: [
53
+ * // { role: 'user', content: [{type: 'text', text: 'hello'}], createdAt: '...', id: '...', threadId: '...' },
54
+ * // { role: 'assistant', content: [{type: 'text', text: 'hi'}], createdAt: '...', id: '...', threadId: '...' }
55
+ * // ]
56
+ * ```
57
+ */
58
+ async getChatHistory() {
59
+ const instance = await getUserInstance();
60
+ return instance.getChatHistory();
49
61
  }
50
62
  };
51
63
  // ============================================================================
@@ -158,17 +170,6 @@ export const Products = {
158
170
  const instance = await getProductsInstance();
159
171
  return instance.create(product);
160
172
  },
161
- /**
162
- * Updates an existing product.
163
- *
164
- * @param data - Updated product data
165
- * @param id - Product ID
166
- * @returns Promise resolving to updated product
167
- */
168
- async update(data, id) {
169
- const instance = await getProductsInstance();
170
- return instance.update(data, id);
171
- },
172
173
  /**
173
174
  * Deletes a product.
174
175
  *
@@ -366,7 +367,167 @@ export const Orders = {
366
367
  }
367
368
  };
368
369
  // ============================================================================
370
+ // JOBS API
371
+ // ============================================================================
372
+ /**
373
+ * Jobs API
374
+ * Manage and trigger scheduled jobs from within your tools
375
+ */
376
+ export const Jobs = {
377
+ /**
378
+ * Creates a new job dynamically from within a tool.
379
+ * This allows tools to schedule one-time or recurring jobs programmatically.
380
+ *
381
+ * @param config - Job configuration
382
+ * @param config.name - Unique job name
383
+ * @param config.description - Job description
384
+ * @param config.schedule - Schedule configuration (cron, once, or interval)
385
+ * @param config.execute - Async function to execute
386
+ * @param config.timeout - Optional timeout in seconds
387
+ * @param config.retry - Optional retry configuration
388
+ * @returns Promise resolving to created job details
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * // Create a one-time job to check basket in 3 hours
393
+ * await Jobs.create({
394
+ * name: `check-basket-${basketId}`,
395
+ * description: 'Check if basket was abandoned',
396
+ * schedule: {
397
+ * type: 'once',
398
+ * executeAt: new Date(Date.now() + 3 * 60 * 60 * 1000)
399
+ * },
400
+ * execute: async () => {
401
+ * const basket = await Baskets.getById(basketId);
402
+ * if (basket.status === 'active') {
403
+ * // Send reminder
404
+ * }
405
+ * return { checked: true };
406
+ * }
407
+ * });
408
+ * ```
409
+ */
410
+ async create(config) {
411
+ const instance = await getJobInstance();
412
+ // Convert the execute function to a string
413
+ const executeString = config.execute.toString();
414
+ // Step 1: Create the job
415
+ const createResult = await instance.createJobInstance({
416
+ name: config.name,
417
+ description: config.description,
418
+ context: config.description || '',
419
+ schedule: config.schedule,
420
+ timeout: config.timeout,
421
+ retry: config.retry,
422
+ metadata: config.metadata
423
+ });
424
+ 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
447
+ return new JobInstance(instance, {
448
+ id: jobId,
449
+ jobId: jobId,
450
+ name: config.name,
451
+ schedule: config.schedule,
452
+ metadata: config.metadata || {},
453
+ active: activateResult.success
454
+ });
455
+ },
456
+ /**
457
+ * Retrieves a job by its unique identifier
458
+ * @param jobId - The unique identifier of the job to retrieve
459
+ * @returns Promise resolving to an JobInstance representing the job
460
+ * @throws Error if the job is not found or the request fails
461
+ */
462
+ async getJob(jobId) {
463
+ const instance = await getJobInstance();
464
+ return instance.getJob(jobId);
465
+ }
466
+ };
467
+ // ============================================================================
468
+ // AI GENERATION API
469
+ // ============================================================================
470
+ /**
471
+ * AI API
472
+ * Generate AI responses with custom context
473
+ */
474
+ export const AI = {
475
+ /**
476
+ * Generates an AI response with custom runtime context.
477
+ *
478
+ * @param context - Runtime context to provide to the AI
479
+ * @param messages - Array of messages (text, image, file, etc.)
480
+ * @param agentId - Optional agent ID to use (defaults to current agent)
481
+ * @returns Promise resolving to AI response text
482
+ *
483
+ * @example
484
+ * ```typescript
485
+ * // Simple text message with current agent
486
+ * const response = await AI.generate(
487
+ * 'You are a helpful sales assistant for our e-commerce store.',
488
+ * [{ type: 'text', text: 'What products do you recommend for beginners?' }]
489
+ * );
490
+ * console.log(response); // AI-generated recommendation
491
+ *
492
+ * // Multiple messages with images
493
+ * const response2 = await AI.generate(
494
+ * 'You are an image analysis expert.',
495
+ * [
496
+ * { type: 'text', text: 'What do you see in this image?' },
497
+ * { type: 'image', url: 'https://example.com/image.jpg' }
498
+ * ]
499
+ * );
500
+ *
501
+ * // Use a different agent
502
+ * const response3 = await AI.generate(
503
+ * 'You are a specialized assistant.',
504
+ * [{ type: 'text', text: 'Help me with this task' }],
505
+ * 'agent_different_123'
506
+ * );
507
+ * ```
508
+ */
509
+ async generate(context, messages, agentId) {
510
+ const chatInstance = await getChatInstance();
511
+ const { getCredentials } = await import('./api/credentials.js');
512
+ const credentials = await getCredentials();
513
+ // Use provided agentId or default to current agent
514
+ const targetAgentId = agentId || 'luaAgent';
515
+ const result = await chatInstance.sendMessage(targetAgentId, {
516
+ messages,
517
+ navigate: false,
518
+ skillOverride: [],
519
+ runtimeContext: context
520
+ });
521
+ if (!result.success) {
522
+ throw new Error(result.error?.message || 'AI generation failed');
523
+ }
524
+ return result.data?.text || '';
525
+ }
526
+ };
527
+ // ============================================================================
369
528
  // EXPORTS
370
529
  // ============================================================================
371
530
  // Export skill classes and utilities
372
- export { LuaSkill, BasketStatus, OrderStatus, env };
531
+ export { LuaSkill, LuaWebhook, LuaJob, PreProcessor, PostProcessor, LuaAgent, BasketStatus, OrderStatus, env };
532
+ // Export instance classes
533
+ export { JobInstance };