lua-cli 2.2.8-alpha.1 → 2.3.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 (191) hide show
  1. package/API_REFERENCE.md +1408 -0
  2. package/CLI_REFERENCE.md +818 -0
  3. package/GETTING_STARTED.md +1040 -0
  4. package/README.md +738 -424
  5. package/TEMPLATE_GUIDE.md +1398 -0
  6. package/dist/api/agent.api.service.d.ts +45 -0
  7. package/dist/api/agent.api.service.js +57 -0
  8. package/dist/api/auth.api.service.d.ts +48 -0
  9. package/dist/api/auth.api.service.js +54 -0
  10. package/dist/api/basket.api.service.d.ts +85 -0
  11. package/dist/api/basket.api.service.js +164 -0
  12. package/dist/api/chat.api.service.d.ts +21 -0
  13. package/dist/api/chat.api.service.js +24 -0
  14. package/dist/api/credentials.d.ts +24 -0
  15. package/dist/api/credentials.js +46 -0
  16. package/dist/api/custom.data.api.service.d.ts +69 -0
  17. package/dist/api/custom.data.api.service.js +125 -0
  18. package/dist/api/lazy-instances.d.ts +49 -0
  19. package/dist/api/lazy-instances.js +95 -0
  20. package/dist/api/order.api.service.d.ts +53 -0
  21. package/dist/api/order.api.service.js +95 -0
  22. package/dist/api/products.api.service.d.ts +66 -0
  23. package/dist/api/products.api.service.js +112 -0
  24. package/dist/api/skills.api.service.d.ts +77 -0
  25. package/dist/api/skills.api.service.js +88 -0
  26. package/dist/api/tool.api.service.d.ts +52 -0
  27. package/dist/api/tool.api.service.js +73 -0
  28. package/dist/api/user.data.api.service.d.ts +33 -0
  29. package/dist/api/user.data.api.service.js +59 -0
  30. package/dist/api-exports.d.ts +271 -0
  31. package/dist/api-exports.js +372 -0
  32. package/dist/cli/command-definitions.d.ts +30 -0
  33. package/dist/cli/command-definitions.js +71 -0
  34. package/dist/commands/agents.d.ts +20 -0
  35. package/dist/commands/agents.js +24 -2
  36. package/dist/commands/apiKey.d.ts +23 -0
  37. package/dist/commands/apiKey.js +23 -0
  38. package/dist/commands/compile.d.ts +24 -0
  39. package/dist/commands/compile.js +67 -759
  40. package/dist/commands/configure.d.ts +24 -0
  41. package/dist/commands/configure.js +31 -96
  42. package/dist/commands/deploy.d.ts +31 -19
  43. package/dist/commands/deploy.js +45 -74
  44. package/dist/commands/destroy.d.ts +27 -0
  45. package/dist/commands/destroy.js +27 -1
  46. package/dist/commands/dev.d.ts +25 -62
  47. package/dist/commands/dev.js +58 -873
  48. package/dist/commands/init.d.ts +27 -0
  49. package/dist/commands/init.js +98 -260
  50. package/dist/commands/push.d.ts +24 -21
  51. package/dist/commands/push.js +39 -92
  52. package/dist/commands/test.d.ts +26 -0
  53. package/dist/commands/test.js +41 -188
  54. package/dist/common/basket.instance.d.ts +78 -0
  55. package/dist/common/basket.instance.js +132 -0
  56. package/dist/common/data.entry.instance.d.ts +39 -0
  57. package/dist/common/data.entry.instance.js +76 -0
  58. package/dist/common/http.client.d.ts +64 -0
  59. package/dist/common/http.client.js +133 -0
  60. package/dist/common/order.instance.d.ts +40 -0
  61. package/dist/common/order.instance.js +79 -0
  62. package/dist/common/product.instance.d.ts +33 -0
  63. package/dist/common/product.instance.js +63 -0
  64. package/dist/common/product.pagination.instance.d.ts +43 -0
  65. package/dist/common/product.pagination.instance.js +74 -0
  66. package/dist/common/product.search.instance.d.ts +22 -0
  67. package/dist/common/product.search.instance.js +40 -0
  68. package/dist/common/user.instance.d.ts +41 -0
  69. package/dist/common/user.instance.js +84 -0
  70. package/dist/config/auth.constants.d.ts +11 -0
  71. package/dist/config/auth.constants.js +11 -0
  72. package/dist/config/compile.constants.d.ts +67 -0
  73. package/dist/config/compile.constants.js +99 -0
  74. package/dist/config/constants.d.ts +5 -0
  75. package/dist/config/constants.js +5 -0
  76. package/dist/config/dev.constants.d.ts +65 -0
  77. package/dist/config/dev.constants.js +79 -0
  78. package/dist/config/init.constants.d.ts +23 -0
  79. package/dist/config/init.constants.js +41 -0
  80. package/dist/index.d.ts +19 -3
  81. package/dist/index.js +28 -44
  82. package/dist/interfaces/admin.d.ts +101 -0
  83. package/dist/interfaces/admin.js +5 -0
  84. package/dist/interfaces/agent.d.ts +107 -0
  85. package/dist/interfaces/agent.js +5 -0
  86. package/dist/interfaces/baskets.d.ts +135 -0
  87. package/dist/interfaces/baskets.js +19 -0
  88. package/dist/interfaces/chat.d.ts +61 -0
  89. package/dist/interfaces/chat.js +5 -0
  90. package/dist/interfaces/common.d.ts +62 -0
  91. package/dist/interfaces/common.js +8 -0
  92. package/dist/interfaces/compile.d.ts +11 -0
  93. package/dist/interfaces/compile.js +4 -0
  94. package/dist/interfaces/custom.data.d.ts +82 -0
  95. package/dist/interfaces/custom.data.js +5 -0
  96. package/dist/interfaces/deploy.d.ts +29 -0
  97. package/dist/interfaces/deploy.js +4 -0
  98. package/dist/interfaces/dev.d.ts +53 -0
  99. package/dist/interfaces/dev.js +5 -0
  100. package/dist/interfaces/init.d.ts +60 -0
  101. package/dist/interfaces/init.js +4 -0
  102. package/dist/interfaces/orders.d.ts +91 -0
  103. package/dist/interfaces/orders.js +19 -0
  104. package/dist/interfaces/product.d.ts +65 -0
  105. package/dist/interfaces/product.js +5 -0
  106. package/dist/interfaces/push.d.ts +26 -0
  107. package/dist/interfaces/push.js +4 -0
  108. package/dist/interfaces/test.d.ts +36 -0
  109. package/dist/interfaces/test.js +4 -0
  110. package/dist/services/auth.d.ts +54 -99
  111. package/dist/services/auth.js +76 -12
  112. package/dist/types/api-contracts.d.ts +211 -0
  113. package/dist/types/api-contracts.js +8 -0
  114. package/dist/types/compile.types.d.ts +76 -0
  115. package/dist/types/compile.types.js +4 -0
  116. package/dist/types/index.d.ts +23 -85
  117. package/dist/types/index.js +25 -14
  118. package/dist/types/skill.d.ts +142 -0
  119. package/dist/{skill.js → types/skill.js} +66 -19
  120. package/dist/types/tool-validation.d.ts +34 -0
  121. package/dist/types/tool-validation.js +42 -0
  122. package/dist/utils/auth-flows.d.ts +26 -0
  123. package/dist/utils/auth-flows.js +141 -0
  124. package/dist/utils/bundling.d.ts +36 -0
  125. package/dist/utils/bundling.js +137 -0
  126. package/dist/utils/compile.d.ts +37 -0
  127. package/dist/utils/compile.js +242 -0
  128. package/dist/utils/deploy-api.d.ts +26 -0
  129. package/dist/utils/deploy-api.js +53 -0
  130. package/dist/utils/deploy-helpers.d.ts +46 -0
  131. package/dist/utils/deploy-helpers.js +86 -0
  132. package/dist/utils/deployment.d.ts +25 -0
  133. package/dist/utils/deployment.js +161 -0
  134. package/dist/utils/dev-api.d.ts +61 -0
  135. package/dist/utils/dev-api.js +262 -0
  136. package/dist/utils/dev-helpers.d.ts +46 -0
  137. package/dist/utils/dev-helpers.js +83 -0
  138. package/dist/utils/dev-server.d.ts +24 -0
  139. package/dist/utils/dev-server.js +555 -0
  140. package/dist/utils/dev-watcher.d.ts +31 -0
  141. package/dist/utils/dev-watcher.js +110 -0
  142. package/dist/utils/files.js +0 -5
  143. package/dist/utils/init-agent.d.ts +34 -0
  144. package/dist/utils/init-agent.js +129 -0
  145. package/dist/utils/init-helpers.d.ts +41 -0
  146. package/dist/utils/init-helpers.js +73 -0
  147. package/dist/utils/init-prompts.d.ts +47 -0
  148. package/dist/utils/init-prompts.js +168 -0
  149. package/dist/utils/push-api.d.ts +15 -0
  150. package/dist/utils/push-api.js +48 -0
  151. package/dist/utils/push-helpers.d.ts +38 -0
  152. package/dist/utils/push-helpers.js +84 -0
  153. package/dist/utils/sandbox-storage.d.ts +27 -0
  154. package/dist/utils/sandbox-storage.js +71 -0
  155. package/dist/utils/sandbox.js +78 -118
  156. package/dist/utils/skill-management.d.ts +14 -0
  157. package/dist/utils/skill-management.js +148 -0
  158. package/dist/utils/test-helpers.d.ts +40 -0
  159. package/dist/utils/test-helpers.js +92 -0
  160. package/dist/utils/test-prompts.d.ts +23 -0
  161. package/dist/utils/test-prompts.js +186 -0
  162. package/dist/utils/tool-detection.d.ts +18 -0
  163. package/dist/utils/tool-detection.js +110 -0
  164. package/dist/web/app.css +14 -9
  165. package/package.json +11 -12
  166. package/template/QUICKSTART.md +299 -144
  167. package/template/README.md +928 -349
  168. package/template/TOOL_EXAMPLES.md +655 -0
  169. package/template/package-lock.json +3781 -0
  170. package/template/package.json +1 -1
  171. package/template/src/index.ts +81 -40
  172. package/template/src/tools/BasketTool.ts +128 -0
  173. package/template/src/tools/CustomDataTool.ts +7 -13
  174. package/template/src/tools/OrderTool.ts +54 -0
  175. package/template/src/tools/PaymentTool.ts +1 -1
  176. package/template/src/tools/ProductsTool.ts +56 -118
  177. package/template/src/tools/UserDataTool.ts +4 -27
  178. package/dist/custom-data-api.d.ts +0 -72
  179. package/dist/custom-data-api.js +0 -174
  180. package/dist/product-api.d.ts +0 -197
  181. package/dist/product-api.js +0 -152
  182. package/dist/services/api.d.ts +0 -569
  183. package/dist/services/api.js +0 -625
  184. package/dist/skill.d.ts +0 -50
  185. package/dist/types.d.ts +0 -1
  186. package/dist/types.js +0 -2
  187. package/dist/user-data-api.d.ts +0 -39
  188. package/dist/user-data-api.js +0 -50
  189. package/template/API.md +0 -604
  190. package/template/DEVELOPER.md +0 -771
  191. package/template/lua.skill.yaml +0 -16
@@ -0,0 +1,45 @@
1
+ import { HttpClient } from "../common/http.client.js";
2
+ import { ApiResponse } from "../interfaces/common.js";
3
+ import { Organization } from "../interfaces/admin.js";
4
+ import { AgentType } from "../interfaces/agent.js";
5
+ import { CreateAgentRequest } from "../interfaces/agent.js";
6
+ import { CreateAgentResponse } from "../interfaces/agent.js";
7
+ import { Agent } from "../interfaces/agent.js";
8
+ /**
9
+ * Agent API calls
10
+ */
11
+ export default class AgentApi extends HttpClient {
12
+ private apiKey;
13
+ /**
14
+ * Creates an instance of AgentApi
15
+ * @param baseUrl - The base URL for the API
16
+ * @param apiKey - The API key for authentication
17
+ */
18
+ constructor(baseUrl: string, apiKey: string);
19
+ /**
20
+ * Retrieves all organizations associated with the authenticated user
21
+ * @returns Promise resolving to an ApiResponse containing an array of Organization objects
22
+ * @throws Error if the API request fails
23
+ */
24
+ getOrganizations(): Promise<ApiResponse<Organization[]>>;
25
+ /**
26
+ * Retrieves all available agent types that can be created
27
+ * @returns Promise resolving to an ApiResponse containing an array of AgentType objects
28
+ * @throws Error if the API request fails
29
+ */
30
+ getAgentTypes(): Promise<ApiResponse<AgentType[]>>;
31
+ /**
32
+ * Creates a new agent with the provided configuration
33
+ * @param agentData - The agent configuration data including name, type, and other settings
34
+ * @returns Promise resolving to an ApiResponse containing the created agent details
35
+ * @throws Error if the API request fails or agent creation is unsuccessful
36
+ */
37
+ createAgent(agentData: CreateAgentRequest): Promise<ApiResponse<CreateAgentResponse>>;
38
+ /**
39
+ * Retrieves detailed information about a specific agent
40
+ * @param agentId - The unique identifier of the agent to retrieve
41
+ * @returns Promise resolving to an ApiResponse containing the Agent details
42
+ * @throws Error if the API request fails or the agent is not found
43
+ */
44
+ getAgent(agentId: string): Promise<ApiResponse<Agent>>;
45
+ }
@@ -0,0 +1,57 @@
1
+ import { HttpClient } from "../common/http.client.js";
2
+ /**
3
+ * Agent API calls
4
+ */
5
+ export default class AgentApi extends HttpClient {
6
+ /**
7
+ * Creates an instance of AgentApi
8
+ * @param baseUrl - The base URL for the API
9
+ * @param apiKey - The API key for authentication
10
+ */
11
+ constructor(baseUrl, apiKey) {
12
+ super(baseUrl);
13
+ this.apiKey = apiKey;
14
+ }
15
+ /**
16
+ * Retrieves all organizations associated with the authenticated user
17
+ * @returns Promise resolving to an ApiResponse containing an array of Organization objects
18
+ * @throws Error if the API request fails
19
+ */
20
+ async getOrganizations() {
21
+ return this.httpGet(`/admin`, {
22
+ Authorization: `Bearer ${this.apiKey}`,
23
+ });
24
+ }
25
+ /**
26
+ * Retrieves all available agent types that can be created
27
+ * @returns Promise resolving to an ApiResponse containing an array of AgentType objects
28
+ * @throws Error if the API request fails
29
+ */
30
+ async getAgentTypes() {
31
+ return this.httpGet(`/agents/self-serve/types`, {
32
+ Authorization: `Bearer ${this.apiKey}`,
33
+ });
34
+ }
35
+ /**
36
+ * Creates a new agent with the provided configuration
37
+ * @param agentData - The agent configuration data including name, type, and other settings
38
+ * @returns Promise resolving to an ApiResponse containing the created agent details
39
+ * @throws Error if the API request fails or agent creation is unsuccessful
40
+ */
41
+ async createAgent(agentData) {
42
+ return this.httpPost(`/agents/self-serve/create`, agentData, {
43
+ Authorization: `Bearer ${this.apiKey}`,
44
+ });
45
+ }
46
+ /**
47
+ * Retrieves detailed information about a specific agent
48
+ * @param agentId - The unique identifier of the agent to retrieve
49
+ * @returns Promise resolving to an ApiResponse containing the Agent details
50
+ * @throws Error if the API request fails or the agent is not found
51
+ */
52
+ async getAgent(agentId) {
53
+ return this.httpGet(`/admin/agents/${agentId}`, {
54
+ Authorization: `Bearer ${this.apiKey}`,
55
+ });
56
+ }
57
+ }
@@ -0,0 +1,48 @@
1
+ import { HttpClient } from "../common/http.client.js";
2
+ import { ApiResponse } from "../interfaces/common.js";
3
+ import { UserData } from "../interfaces/admin.js";
4
+ /**
5
+ * Authentication API calls
6
+ */
7
+ export default class AuthApi extends HttpClient {
8
+ /**
9
+ * Creates an instance of AuthApi
10
+ * @param baseUrl - The base URL for the API
11
+ */
12
+ constructor(baseUrl: string);
13
+ /**
14
+ * Validates an API key and retrieves associated user data
15
+ * @param apiKey - The API key to validate
16
+ * @returns Promise resolving to an ApiResponse containing UserData if the key is valid
17
+ * @throws Error if the API key is invalid or the request fails
18
+ */
19
+ checkApiKey(apiKey: string): Promise<ApiResponse<UserData>>;
20
+ /**
21
+ * Sends a one-time password (OTP) to the specified email address
22
+ * @param email - The email address to send the OTP to
23
+ * @returns Promise resolving to an ApiResponse with a success message
24
+ * @throws Error if the email is invalid or the request fails
25
+ */
26
+ sendOtp(email: string): Promise<ApiResponse<{
27
+ message: string;
28
+ }>>;
29
+ /**
30
+ * Verifies the OTP sent to the user's email and returns a sign-in token
31
+ * @param email - The email address the OTP was sent to
32
+ * @param otp - The one-time password received via email
33
+ * @returns Promise resolving to an ApiResponse containing a signInToken for authentication
34
+ * @throws Error if the OTP is invalid, expired, or the request fails
35
+ */
36
+ verifyOtp(email: string, otp: string): Promise<ApiResponse<{
37
+ signInToken: string;
38
+ }>>;
39
+ /**
40
+ * Exchanges a sign-in token for an API key
41
+ * @param signInToken - The temporary sign-in token obtained from OTP verification
42
+ * @returns Promise resolving to an ApiResponse containing the API key
43
+ * @throws Error if the sign-in token is invalid or the request fails
44
+ */
45
+ getApiKey(signInToken: string): Promise<ApiResponse<{
46
+ apiKey: string;
47
+ }>>;
48
+ }
@@ -0,0 +1,54 @@
1
+ import { HttpClient } from "../common/http.client.js";
2
+ /**
3
+ * Authentication API calls
4
+ */
5
+ export default class AuthApi extends HttpClient {
6
+ /**
7
+ * Creates an instance of AuthApi
8
+ * @param baseUrl - The base URL for the API
9
+ */
10
+ constructor(baseUrl) {
11
+ super(baseUrl);
12
+ }
13
+ /**
14
+ * Validates an API key and retrieves associated user data
15
+ * @param apiKey - The API key to validate
16
+ * @returns Promise resolving to an ApiResponse containing UserData if the key is valid
17
+ * @throws Error if the API key is invalid or the request fails
18
+ */
19
+ async checkApiKey(apiKey) {
20
+ return this.httpGet(`/admin`, {
21
+ Authorization: `Bearer ${apiKey}`,
22
+ });
23
+ }
24
+ /**
25
+ * Sends a one-time password (OTP) to the specified email address
26
+ * @param email - The email address to send the OTP to
27
+ * @returns Promise resolving to an ApiResponse with a success message
28
+ * @throws Error if the email is invalid or the request fails
29
+ */
30
+ async sendOtp(email) {
31
+ return this.httpPost(`/otp`, { email, type: 'email' });
32
+ }
33
+ /**
34
+ * Verifies the OTP sent to the user's email and returns a sign-in token
35
+ * @param email - The email address the OTP was sent to
36
+ * @param otp - The one-time password received via email
37
+ * @returns Promise resolving to an ApiResponse containing a signInToken for authentication
38
+ * @throws Error if the OTP is invalid, expired, or the request fails
39
+ */
40
+ async verifyOtp(email, otp) {
41
+ return this.httpPost(`/otp/verify`, { email, pin: otp, type: 'email' });
42
+ }
43
+ /**
44
+ * Exchanges a sign-in token for an API key
45
+ * @param signInToken - The temporary sign-in token obtained from OTP verification
46
+ * @returns Promise resolving to an ApiResponse containing the API key
47
+ * @throws Error if the sign-in token is invalid or the request fails
48
+ */
49
+ async getApiKey(signInToken) {
50
+ return this.httpPost(`/profile/apiKey`, undefined, {
51
+ Authorization: `Bearer ${signInToken}`,
52
+ });
53
+ }
54
+ }
@@ -0,0 +1,85 @@
1
+ import BasketInstance from "../common/basket.instance.js";
2
+ import { HttpClient } from "../common/http.client.js";
3
+ import OrderInstance from "../common/order.instance.js";
4
+ import { BasketStatus, CreateBasketRequest, AddItemToBasketRequest, Basket } from "../interfaces/baskets.js";
5
+ import { UpdateBasketMetadataResponse } from "../interfaces/baskets.js";
6
+ import { BasketAPI } from "../types/index.js";
7
+ export default class BasketApi extends HttpClient implements BasketAPI {
8
+ private apiKey;
9
+ private agentId;
10
+ /**
11
+ * Creates an instance of BasketApi
12
+ * @param baseUrl - The base URL for the API
13
+ * @param apiKey - The API key for authentication
14
+ * @param agentId - The unique identifier of the agent
15
+ */
16
+ constructor(baseUrl: string, apiKey: string, agentId: string);
17
+ /**
18
+ * Creates a new user basket
19
+ * @param basketData - The basket creation request data containing user ID and optional metadata
20
+ * @returns Promise resolving to a BasketInstance representing the created basket
21
+ * @throws Error if the basket creation fails or the API request is unsuccessful
22
+ */
23
+ create(basketData: CreateBasketRequest): Promise<BasketInstance>;
24
+ /**
25
+ * Retrieves all user baskets with optional status filtering
26
+ * @param status - Optional basket status to filter by (e.g., 'active', 'completed', 'abandoned')
27
+ * @returns Promise resolving to an array of BasketInstance objects
28
+ * @throws Error if the request fails or baskets cannot be retrieved
29
+ */
30
+ get(status?: BasketStatus): Promise<BasketInstance[]>;
31
+ /**
32
+ * Retrieves a single basket by its unique identifier
33
+ * @param basketId - The unique identifier of the basket to retrieve
34
+ * @returns Promise resolving to a BasketInstance representing the basket
35
+ * @throws Error if the basket is not found or the request fails
36
+ */
37
+ getById(basketId: string): Promise<BasketInstance>;
38
+ /**
39
+ * Adds an item to a specific basket
40
+ * @param basketId - The unique identifier of the basket
41
+ * @param itemData - The item data including product ID, quantity, and optional metadata
42
+ * @returns Promise resolving to the updated Basket object
43
+ * @throws Error if the basket is not found or the item cannot be added
44
+ */
45
+ addItem(basketId: string, itemData: AddItemToBasketRequest): Promise<Basket>;
46
+ /**
47
+ * Removes a specific item from a basket
48
+ * @param basketId - The unique identifier of the basket
49
+ * @param itemId - The unique identifier of the item to remove
50
+ * @returns Promise resolving to the updated Basket object
51
+ * @throws Error if the basket or item is not found or the removal fails
52
+ */
53
+ removeItem(basketId: string, itemId: string): Promise<Basket>;
54
+ /**
55
+ * Clears all items from a basket
56
+ * @param basketId - The unique identifier of the basket to clear
57
+ * @returns Promise resolving to the updated empty Basket object
58
+ * @throws Error if the basket is not found or the clear operation fails
59
+ */
60
+ clear(basketId: string): Promise<Basket>;
61
+ /**
62
+ * Updates the status of a basket
63
+ * @param basketId - The unique identifier of the basket
64
+ * @param status - The new status to set for the basket
65
+ * @returns Promise resolving to the updated BasketStatus
66
+ * @throws Error if the basket is not found or the status update fails
67
+ */
68
+ updateStatus(basketId: string, status: BasketStatus): Promise<BasketStatus>;
69
+ /**
70
+ * Updates the metadata of a basket
71
+ * @param basketId - The unique identifier of the basket
72
+ * @param metadata - The metadata object to update or merge with existing metadata
73
+ * @returns Promise resolving to the updated metadata
74
+ * @throws Error if the basket is not found or the metadata update fails
75
+ */
76
+ updateMetadata(basketId: string, metadata: any): Promise<UpdateBasketMetadataResponse>;
77
+ /**
78
+ * Creates an order from a basket
79
+ * @param data - Additional order data (shipping info, payment details, etc.)
80
+ * @param basketId - The unique identifier of the basket to convert to an order
81
+ * @returns Promise resolving to an OrderInstance representing the created order
82
+ * @throws Error if the basket is not found or the order creation fails
83
+ */
84
+ placeOrder(data: Record<string, any>, basketId: string): Promise<OrderInstance>;
85
+ }
@@ -0,0 +1,164 @@
1
+ import BasketInstance from "../common/basket.instance.js";
2
+ import { HttpClient } from "../common/http.client.js";
3
+ import OrderInstance from "../common/order.instance.js";
4
+ import OrderApi from "./order.api.service.js";
5
+ export default class BasketApi extends HttpClient {
6
+ /**
7
+ * Creates an instance of BasketApi
8
+ * @param baseUrl - The base URL for the API
9
+ * @param apiKey - The API key for authentication
10
+ * @param agentId - The unique identifier of the agent
11
+ */
12
+ constructor(baseUrl, apiKey, agentId) {
13
+ super(baseUrl);
14
+ this.apiKey = apiKey;
15
+ this.agentId = agentId;
16
+ }
17
+ /**
18
+ * Creates a new user basket
19
+ * @param basketData - The basket creation request data containing user ID and optional metadata
20
+ * @returns Promise resolving to a BasketInstance representing the created basket
21
+ * @throws Error if the basket creation fails or the API request is unsuccessful
22
+ */
23
+ async create(basketData) {
24
+ const response = await this.httpPost(`/developer/agents/${this.agentId}/basket`, basketData, {
25
+ Authorization: `Bearer ${this.apiKey}`,
26
+ });
27
+ if (response.success && response.data) {
28
+ return new BasketInstance(this, response.data);
29
+ }
30
+ throw new Error(response.error?.message || 'Failed to create basket');
31
+ }
32
+ /**
33
+ * Retrieves all user baskets with optional status filtering
34
+ * @param status - Optional basket status to filter by (e.g., 'active', 'completed', 'abandoned')
35
+ * @returns Promise resolving to an array of BasketInstance objects
36
+ * @throws Error if the request fails or baskets cannot be retrieved
37
+ */
38
+ async get(status) {
39
+ const statusParam = status ? `?status=${status}` : '';
40
+ const response = await this.httpGet(`/developer/agents/${this.agentId}/basket/user${statusParam}`, {
41
+ Authorization: `Bearer ${this.apiKey}`,
42
+ });
43
+ if (response.success) {
44
+ const baskets = response.data;
45
+ return baskets.map((basket) => {
46
+ return new BasketInstance(this, basket);
47
+ });
48
+ }
49
+ throw new Error(response.error?.message || 'Failed to get user baskets');
50
+ }
51
+ /**
52
+ * Retrieves a single basket by its unique identifier
53
+ * @param basketId - The unique identifier of the basket to retrieve
54
+ * @returns Promise resolving to a BasketInstance representing the basket
55
+ * @throws Error if the basket is not found or the request fails
56
+ */
57
+ async getById(basketId) {
58
+ const response = await this.httpGet(`/developer/agents/${this.agentId}/basket/${basketId}`, {
59
+ Authorization: `Bearer ${this.apiKey}`,
60
+ });
61
+ if (response.success && response.data) {
62
+ return new BasketInstance(this, response.data);
63
+ }
64
+ throw new Error(response.error?.message || 'Failed to get basket');
65
+ }
66
+ /**
67
+ * Adds an item to a specific basket
68
+ * @param basketId - The unique identifier of the basket
69
+ * @param itemData - The item data including product ID, quantity, and optional metadata
70
+ * @returns Promise resolving to the updated Basket object
71
+ * @throws Error if the basket is not found or the item cannot be added
72
+ */
73
+ async addItem(basketId, itemData) {
74
+ const response = await this.httpPost(`/developer/agents/${this.agentId}/basket/${basketId}/item`, itemData, {
75
+ Authorization: `Bearer ${this.apiKey}`,
76
+ });
77
+ if (response.success) {
78
+ return response.data;
79
+ }
80
+ throw new Error(response.error?.message || 'Failed to add item to basket');
81
+ }
82
+ /**
83
+ * Removes a specific item from a basket
84
+ * @param basketId - The unique identifier of the basket
85
+ * @param itemId - The unique identifier of the item to remove
86
+ * @returns Promise resolving to the updated Basket object
87
+ * @throws Error if the basket or item is not found or the removal fails
88
+ */
89
+ async removeItem(basketId, itemId) {
90
+ const response = await this.httpDelete(`/developer/agents/${this.agentId}/basket/${basketId}/item/${itemId}`, {
91
+ Authorization: `Bearer ${this.apiKey}`,
92
+ });
93
+ if (response.success) {
94
+ return response.data;
95
+ }
96
+ throw new Error(response.error?.message || 'Failed to remove item from basket');
97
+ }
98
+ /**
99
+ * Clears all items from a basket
100
+ * @param basketId - The unique identifier of the basket to clear
101
+ * @returns Promise resolving to the updated empty Basket object
102
+ * @throws Error if the basket is not found or the clear operation fails
103
+ */
104
+ async clear(basketId) {
105
+ const response = await this.httpDelete(`/developer/agents/${this.agentId}/basket/${basketId}/clear`, {
106
+ Authorization: `Bearer ${this.apiKey}`,
107
+ });
108
+ if (response.success) {
109
+ return response.data;
110
+ }
111
+ throw new Error(response.message || 'Failed to clear basket');
112
+ }
113
+ /**
114
+ * Updates the status of a basket
115
+ * @param basketId - The unique identifier of the basket
116
+ * @param status - The new status to set for the basket
117
+ * @returns Promise resolving to the updated BasketStatus
118
+ * @throws Error if the basket is not found or the status update fails
119
+ */
120
+ async updateStatus(basketId, status) {
121
+ const response = await this.httpPut(`/developer/agents/${this.agentId}/basket/${basketId}/${status}`, undefined, {
122
+ Authorization: `Bearer ${this.apiKey}`,
123
+ });
124
+ if (response.success) {
125
+ return status;
126
+ }
127
+ throw new Error(response.message || 'Failed to update basket status');
128
+ }
129
+ /**
130
+ * Updates the metadata of a basket
131
+ * @param basketId - The unique identifier of the basket
132
+ * @param metadata - The metadata object to update or merge with existing metadata
133
+ * @returns Promise resolving to the updated metadata
134
+ * @throws Error if the basket is not found or the metadata update fails
135
+ */
136
+ async updateMetadata(basketId, metadata) {
137
+ const response = await this.httpPut(`/developer/agents/${this.agentId}/basket/${basketId}/metadata`, metadata, {
138
+ Authorization: `Bearer ${this.apiKey}`,
139
+ });
140
+ if (response.success) {
141
+ return metadata;
142
+ }
143
+ throw new Error(response.message || 'Failed to update basket metadata');
144
+ }
145
+ /**
146
+ * Creates an order from a basket
147
+ * @param data - Additional order data (shipping info, payment details, etc.)
148
+ * @param basketId - The unique identifier of the basket to convert to an order
149
+ * @returns Promise resolving to an OrderInstance representing the created order
150
+ * @throws Error if the basket is not found or the order creation fails
151
+ */
152
+ async placeOrder(data, basketId) {
153
+ const response = await this.httpPost(`/developer/agents/${this.agentId}/order`, { basketId, data }, {
154
+ Authorization: `Bearer ${this.apiKey}`,
155
+ });
156
+ if (response.success && response.data) {
157
+ //create order api instance
158
+ const orderApi = new OrderApi(this.baseUrl, this.apiKey, this.agentId);
159
+ const orderInstance = new OrderInstance(orderApi, response.data);
160
+ return orderInstance;
161
+ }
162
+ throw new Error(response.message || 'Failed to create order');
163
+ }
164
+ }
@@ -0,0 +1,21 @@
1
+ import { ChatResponse } from "../interfaces/chat.js";
2
+ import { HttpClient } from "../common/http.client.js";
3
+ import { ApiResponse } from "../interfaces/common.js";
4
+ import { ChatRequest } from "../interfaces/chat.js";
5
+ export default class ChatApi extends HttpClient {
6
+ private apiKey;
7
+ /**
8
+ * Creates an instance of ChatApi
9
+ * @param baseUrl - The base URL for the API
10
+ * @param apiKey - The API key for authentication
11
+ */
12
+ constructor(baseUrl: string, apiKey: string);
13
+ /**
14
+ * Sends a message to an agent and receives a response
15
+ * @param agentId - The unique identifier of the agent to chat with
16
+ * @param chatData - The chat request data including message, conversation history, and context
17
+ * @returns Promise resolving to an ApiResponse containing the agent's chat response
18
+ * @throws Error if the agent is not found or the chat request fails
19
+ */
20
+ sendMessage(agentId: string, chatData: ChatRequest): Promise<ApiResponse<ChatResponse>>;
21
+ }
@@ -0,0 +1,24 @@
1
+ import { HttpClient } from "../common/http.client.js";
2
+ export default class ChatApi extends HttpClient {
3
+ /**
4
+ * Creates an instance of ChatApi
5
+ * @param baseUrl - The base URL for the API
6
+ * @param apiKey - The API key for authentication
7
+ */
8
+ constructor(baseUrl, apiKey) {
9
+ super(baseUrl);
10
+ this.apiKey = apiKey;
11
+ }
12
+ /**
13
+ * Sends a message to an agent and receives a response
14
+ * @param agentId - The unique identifier of the agent to chat with
15
+ * @param chatData - The chat request data including message, conversation history, and context
16
+ * @returns Promise resolving to an ApiResponse containing the agent's chat response
17
+ * @throws Error if the agent is not found or the chat request fails
18
+ */
19
+ async sendMessage(agentId, chatData) {
20
+ return this.httpPost(`/chat/generate/${agentId}?channel=dev`, chatData, {
21
+ Authorization: `Bearer ${this.apiKey}`,
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * API Credentials Management
3
+ * Handles loading and caching of API credentials for skill execution
4
+ */
5
+ /**
6
+ * API credentials structure
7
+ */
8
+ export interface ApiCredentials {
9
+ apiKey: string;
10
+ agentId: string;
11
+ }
12
+ /**
13
+ * Gets API credentials from keystore and configuration.
14
+ * Results are cached for subsequent calls.
15
+ *
16
+ * @returns API key and agent ID
17
+ * @throws Error if credentials are not found or incomplete
18
+ */
19
+ export declare function getCredentials(): Promise<ApiCredentials>;
20
+ /**
21
+ * Clears the cached credentials.
22
+ * Useful for testing or when credentials change.
23
+ */
24
+ export declare function clearCredentialsCache(): void;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * API Credentials Management
3
+ * Handles loading and caching of API credentials for skill execution
4
+ */
5
+ import { loadApiKey } from "../services/auth.js";
6
+ import { readSkillConfig } from "../utils/files.js";
7
+ /**
8
+ * Cached credentials to avoid repeated file/keychain access
9
+ */
10
+ let cachedCredentials = null;
11
+ /**
12
+ * Gets API credentials from keystore and configuration.
13
+ * Results are cached for subsequent calls.
14
+ *
15
+ * @returns API key and agent ID
16
+ * @throws Error if credentials are not found or incomplete
17
+ */
18
+ export async function getCredentials() {
19
+ // Return cached credentials if available
20
+ if (cachedCredentials) {
21
+ return cachedCredentials;
22
+ }
23
+ // Load API key from keystore
24
+ const apiKey = await loadApiKey();
25
+ if (!apiKey) {
26
+ throw new Error('No API key found. Please run "lua auth configure" first.');
27
+ }
28
+ // Load agent ID from YAML file
29
+ const config = readSkillConfig();
30
+ if (!config?.agent?.agentId) {
31
+ throw new Error('No agent ID found in lua.skill.yaml. Please run "lua init" first.');
32
+ }
33
+ // Cache and return credentials
34
+ cachedCredentials = {
35
+ apiKey,
36
+ agentId: config.agent.agentId
37
+ };
38
+ return cachedCredentials;
39
+ }
40
+ /**
41
+ * Clears the cached credentials.
42
+ * Useful for testing or when credentials change.
43
+ */
44
+ export function clearCredentialsCache() {
45
+ cachedCredentials = null;
46
+ }
@@ -0,0 +1,69 @@
1
+ import { HttpClient } from "../common/http.client.js";
2
+ import { CustomDataAPI } from "../types/index.js";
3
+ import { GetCustomDataResponse, UpdateCustomDataRequest, UpdateCustomDataResponse, DeleteCustomDataResponse } from "../interfaces/custom.data.js";
4
+ import DataEntryInstance from "../common/data.entry.instance.js";
5
+ export default class CustomDataApi extends HttpClient implements CustomDataAPI {
6
+ private apiKey;
7
+ private agentId;
8
+ /**
9
+ * Creates an instance of CustomDataApi
10
+ * @param baseUrl - The base URL for the API
11
+ * @param apiKey - The API key for authentication
12
+ * @param agentId - The unique identifier of the agent
13
+ */
14
+ constructor(baseUrl: string, apiKey: string, agentId: string);
15
+ /**
16
+ * Creates a new custom data entry in a specified collection
17
+ * @param collectionName - The name of the collection to create the entry in
18
+ * @param data - The data object to store in the entry
19
+ * @param searchText - Optional text to be used for semantic search indexing
20
+ * @returns Promise resolving to a DataEntryInstance representing the created entry
21
+ * @throws Error if the entry creation fails or the API request is unsuccessful
22
+ */
23
+ create(collectionName: string, data: Record<string, any>, searchText?: string): Promise<DataEntryInstance>;
24
+ /**
25
+ * Retrieves custom data entries from a collection with optional filtering and pagination
26
+ * @param collectionName - The name of the collection to query
27
+ * @param filter - Optional filter object to apply to the query (JSON-serializable)
28
+ * @param page - The page number for pagination (default: 1)
29
+ * @param limit - The number of entries per page (default: 10)
30
+ * @returns Promise resolving to a GetCustomDataResponse containing the entries and pagination info
31
+ * @throws Error if the query fails or the API request is unsuccessful
32
+ */
33
+ get(collectionName: string, filter?: any, page?: number, limit?: number): Promise<GetCustomDataResponse>;
34
+ /**
35
+ * Retrieves a single custom data entry by its ID
36
+ * @param collectionName - The name of the collection containing the entry
37
+ * @param entryId - The unique identifier of the entry to retrieve
38
+ * @returns Promise resolving to a DataEntryInstance representing the entry
39
+ * @throws Error if the entry is not found or the API request is unsuccessful
40
+ */
41
+ getEntry(collectionName: string, entryId: string): Promise<DataEntryInstance>;
42
+ /**
43
+ * Updates an existing custom data entry
44
+ * @param collectionName - The name of the collection containing the entry
45
+ * @param entryId - The unique identifier of the entry to update
46
+ * @param data - The update data containing fields to modify (data and/or searchText)
47
+ * @returns Promise resolving to an UpdateCustomDataResponse with the updated entry details
48
+ * @throws Error if the entry is not found or the update fails
49
+ */
50
+ update(collectionName: string, entryId: string, data: UpdateCustomDataRequest): Promise<UpdateCustomDataResponse>;
51
+ /**
52
+ * Performs semantic search on custom data entries using text similarity
53
+ * @param collectionName - The name of the collection to search within
54
+ * @param searchText - The text query to search for
55
+ * @param limit - Maximum number of results to return (default: 10)
56
+ * @param scoreThreshold - Minimum similarity score threshold 0-1 (default: 0.6)
57
+ * @returns Promise resolving to an array of DataEntryInstance objects matching the search
58
+ * @throws Error if the search fails or the API request is unsuccessful
59
+ */
60
+ search(collectionName: string, searchText: string, limit?: number, scoreThreshold?: number): Promise<DataEntryInstance[]>;
61
+ /**
62
+ * Deletes a custom data entry from a collection
63
+ * @param collectionName - The name of the collection containing the entry
64
+ * @param entryId - The unique identifier of the entry to delete
65
+ * @returns Promise resolving to a DeleteCustomDataResponse confirming deletion
66
+ * @throws Error if the entry is not found or the deletion fails
67
+ */
68
+ delete(collectionName: string, entryId: string): Promise<DeleteCustomDataResponse>;
69
+ }