lua-cli 2.2.8-alpha.2 → 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 (193) 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 +33 -6
  7. package/dist/api/agent.api.service.js +27 -0
  8. package/dist/api/auth.api.service.d.ts +31 -2
  9. package/dist/api/auth.api.service.js +29 -0
  10. package/dist/api/basket.api.service.d.ts +53 -11
  11. package/dist/api/basket.api.service.js +63 -14
  12. package/dist/api/chat.api.service.d.ts +15 -3
  13. package/dist/api/chat.api.service.js +12 -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 +45 -9
  17. package/dist/api/custom.data.api.service.js +43 -9
  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 +34 -4
  21. package/dist/api/order.api.service.js +41 -3
  22. package/dist/api/products.api.service.d.ts +39 -9
  23. package/dist/api/products.api.service.js +43 -5
  24. package/dist/api/skills.api.service.d.ts +49 -2
  25. package/dist/api/skills.api.service.js +47 -1
  26. package/dist/api/tool.api.service.d.ts +39 -1
  27. package/dist/api/tool.api.service.js +38 -0
  28. package/dist/api/user.data.api.service.d.ts +23 -1
  29. package/dist/api/user.data.api.service.js +22 -0
  30. package/dist/api-exports.d.ts +236 -5
  31. package/dist/api-exports.js +264 -81
  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 -878
  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 +54 -3
  55. package/dist/common/basket.instance.js +56 -3
  56. package/dist/common/data.entry.instance.d.ts +25 -2
  57. package/dist/common/data.entry.instance.js +24 -0
  58. package/dist/common/http.client.d.ts +51 -1
  59. package/dist/common/http.client.js +50 -0
  60. package/dist/common/order.instance.d.ts +22 -0
  61. package/dist/common/order.instance.js +31 -4
  62. package/dist/common/product.instance.d.ts +22 -1
  63. package/dist/common/product.instance.js +24 -6
  64. package/dist/common/product.pagination.instance.d.ts +22 -2
  65. package/dist/common/product.pagination.instance.js +22 -1
  66. package/dist/common/product.search.instance.d.ts +13 -3
  67. package/dist/common/product.search.instance.js +12 -1
  68. package/dist/common/user.instance.d.ts +27 -3
  69. package/dist/common/user.instance.js +28 -7
  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 +56 -50
  83. package/dist/interfaces/admin.js +4 -0
  84. package/dist/interfaces/agent.d.ts +21 -0
  85. package/dist/interfaces/agent.js +4 -0
  86. package/dist/interfaces/baskets.d.ts +60 -0
  87. package/dist/interfaces/baskets.js +12 -0
  88. package/dist/interfaces/chat.d.ts +48 -4
  89. package/dist/interfaces/chat.js +4 -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 +49 -19
  95. package/dist/interfaces/custom.data.js +4 -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 +37 -0
  103. package/dist/interfaces/orders.js +12 -0
  104. package/dist/interfaces/product.d.ts +38 -10
  105. package/dist/interfaces/product.js +4 -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 -121
  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 -17
  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 -114
  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 +7 -4
  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 +5 -5
  170. package/template/package.json +1 -1
  171. package/template/src/index.ts +147 -207
  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 -26
  178. package/dist/common/config.d.ts +0 -5
  179. package/dist/common/config.js +0 -5
  180. package/dist/custom-data-api.d.ts +0 -72
  181. package/dist/custom-data-api.js +0 -174
  182. package/dist/product-api.d.ts +0 -189
  183. package/dist/product-api.js +0 -141
  184. package/dist/services/api.d.ts +0 -549
  185. package/dist/services/api.js +0 -596
  186. package/dist/skill.d.ts +0 -50
  187. package/dist/types.d.ts +0 -1
  188. package/dist/types.js +0 -2
  189. package/dist/user-data-api.d.ts +0 -39
  190. package/dist/user-data-api.js +0 -50
  191. package/template/API.md +0 -604
  192. package/template/DEVELOPER.md +0 -771
  193. package/template/lua.skill.yaml +0 -7
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Type definitions for compile command
3
+ */
4
+ import { SourceFile } from "ts-morph";
5
+ /**
6
+ * Represents a TypeScript source file from ts-morph
7
+ */
8
+ export type TypeScriptSourceFile = SourceFile;
9
+ /**
10
+ * Represents an AST node from ts-morph
11
+ */
12
+ export type ASTNode = any;
13
+ /**
14
+ * Skill metadata extracted from source code
15
+ */
16
+ export interface SkillMetadata {
17
+ name: string;
18
+ version: string;
19
+ description: string;
20
+ context: string;
21
+ constructorTools: string[];
22
+ }
23
+ /**
24
+ * Configuration from lua.skill.yaml
25
+ */
26
+ export interface SkillConfig {
27
+ skill?: {
28
+ name?: string;
29
+ version?: string;
30
+ skillId?: string;
31
+ description?: string;
32
+ context?: string;
33
+ };
34
+ agent?: {
35
+ agentId?: string;
36
+ };
37
+ skills?: Array<{
38
+ name: string;
39
+ version: string;
40
+ skillId: string;
41
+ }>;
42
+ }
43
+ /**
44
+ * Deployment data format for new deployment system
45
+ */
46
+ export interface DeploymentData {
47
+ name: string;
48
+ version: string;
49
+ skillId: string;
50
+ description: string;
51
+ context: string;
52
+ tools: Array<{
53
+ name: string;
54
+ className: string;
55
+ description: string;
56
+ filePath: string;
57
+ }>;
58
+ }
59
+ /**
60
+ * Legacy deployment data format
61
+ */
62
+ export interface LegacyDeployData {
63
+ skills: Array<{
64
+ name: string;
65
+ version: string;
66
+ description: string;
67
+ context: string;
68
+ skillId?: string;
69
+ tools: Array<{
70
+ name: string;
71
+ description: string;
72
+ inputSchema: any;
73
+ execute: string;
74
+ }>;
75
+ }>;
76
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Type definitions for compile command
3
+ */
4
+ export {};
@@ -1,123 +1,25 @@
1
- export interface UserData {
2
- uid: string;
3
- email: string;
4
- emailVerified: boolean;
5
- fullName: string;
6
- mobileNumbers: any[];
7
- emailAddresses: EmailAddress[];
8
- country: Country;
9
- admin: Admin;
10
- channels: Record<string, any>;
11
- rights: Record<string, any>;
12
- setupPersona: Record<string, any>;
13
- notifications: Record<string, any>;
14
- }
15
- export interface EmailAddress {
16
- address: string;
17
- validated: boolean;
18
- validatedAt: number;
19
- _id: string;
20
- }
21
- export interface Country {
22
- code: string;
23
- name: string;
24
- }
25
- export interface Admin {
26
- userId: string;
27
- orgs: Organization[];
28
- id: string;
29
- createdAt: number;
30
- __v: number;
31
- }
32
- export interface Organization {
33
- id: string;
34
- rights?: string[];
35
- agents: Agent[];
36
- registeredName: string;
37
- country: string;
38
- phoneNumber?: string | null;
39
- type: string;
40
- }
41
- export interface Agent {
42
- agentId: string;
43
- rights: string[];
44
- name: string;
45
- }
46
- export interface OTPResponse {
47
- signInToken: string;
48
- }
49
- export interface ApiKeyResponse {
50
- message: string;
51
- userId: string;
52
- apiKey: string;
53
- apiId: string;
54
- }
55
- import { ZodType } from "zod";
56
1
  /**
57
- * Validates that a tool name contains only alphanumeric characters, hyphens, and underscores.
58
- * No spaces or other special characters are allowed.
2
+ * Types Module - Barrel Export
3
+ *
4
+ * This file serves as the main entry point for all type definitions.
5
+ * It re-exports types from various modules for convenient importing.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * // Import from types module
10
+ * import { LuaSkill, LuaTool, env } from './types/index.js';
11
+ *
12
+ * // Or import specific type groups
13
+ * import { UserDataAPI, ProductAPI } from './types/api-contracts.js';
14
+ * import { validateToolName } from './types/tool-validation.js';
15
+ * ```
59
16
  */
60
- export declare function validateToolName(name: string): boolean;
61
- /**
62
- * Throws an error if the tool name is invalid
63
- */
64
- export declare function assertValidToolName(name: string): void;
65
- export interface LuaTool<TInput extends ZodType = ZodType> {
66
- name: string;
67
- description: string;
68
- inputSchema: TInput;
69
- execute: (input: any) => Promise<any>;
70
- }
71
- export interface LuaSkillConfig {
72
- name: string;
73
- version: string;
74
- description: string;
75
- context: string;
76
- }
77
- export declare class LuaSkill {
78
- private readonly tools;
79
- private readonly name;
80
- private readonly version;
81
- private readonly description;
82
- private readonly context;
83
- constructor(config: LuaSkillConfig);
84
- addTool<TInput extends ZodType>(tool: LuaTool<TInput>): void;
85
- addTools(tools: LuaTool<any>[]): void;
86
- run(input: Record<string, any>): Promise<any>;
87
- }
88
- export interface UserDataAPI {
89
- get(): Promise<any>;
90
- update(data: Record<string, any>): Promise<any>;
91
- clear(): Promise<any>;
92
- }
93
- export interface ProductAPI {
94
- get(limit?: number, page?: number): Promise<any>;
95
- create(product: any): Promise<any>;
96
- update(data: any, id: string): Promise<any>;
97
- delete(id: string): Promise<any>;
98
- search(query: string): Promise<any>;
99
- }
100
- export interface BasketAPI {
101
- create(basketData: any): Promise<any>;
102
- get(status?: any): Promise<any>;
103
- addItem(basketId: string, itemData: any): Promise<any>;
104
- removeItem(basketId: string, itemId: string): Promise<any>;
105
- clear(basketId: string): Promise<any>;
106
- updateStatus(basketId: string, status: any): Promise<any>;
107
- updateMetadata(basketId: string, metadata: any): Promise<any>;
108
- placeOrder(data: Record<string, any>, basketId: string): Promise<any>;
109
- }
110
- export interface OrderAPI {
111
- create(orderData: any): Promise<any>;
112
- updateStatus(status: any, orderId: string): Promise<any>;
113
- updateData(data: Record<string, any>, orderId: string): Promise<any>;
114
- get(status?: any): Promise<any>;
115
- }
116
- export interface CustomDataAPI {
117
- create(collectionName: string, data: any): Promise<any>;
118
- get(collectionName: string, filter?: any, page?: number, limit?: number): Promise<any>;
119
- getEntry(collectionName: string, entryId: string): Promise<any>;
120
- update(collectionName: string, entryId: string, data: any): Promise<any>;
121
- search(collectionName: string, searchText: string, limit?: number, scoreThreshold?: number): Promise<any>;
122
- delete(collectionName: string, entryId: string): Promise<any>;
123
- }
17
+ export { LuaSkill, LuaTool, LuaSkillConfig, env } from './skill.js';
18
+ export { validateToolName, assertValidToolName } from './tool-validation.js';
19
+ export { UserDataAPI, ProductAPI, BasketAPI, OrderAPI, CustomDataAPI } from './api-contracts.js';
20
+ export { UserData, EmailAddress, Country, Admin, Organization, AgentAuth, OTPResponse, ApiKeyResponse } from '../interfaces/admin.js';
21
+ export { Agent, AgentType, CreateAgentRequest, CreateAgentResponse, AgentDetailsResponse } from '../interfaces/agent.js';
22
+ export { BasketStatus, BasketItem, Basket } from '../interfaces/baskets.js';
23
+ export { OrderStatus, OrderResponse } from '../interfaces/orders.js';
24
+ export { Product } from '../interfaces/product.js';
25
+ export { ApiResponse, Pagination } from '../interfaces/common.js';
@@ -1,16 +1,27 @@
1
1
  /**
2
- * Validates that a tool name contains only alphanumeric characters, hyphens, and underscores.
3
- * No spaces or other special characters are allowed.
2
+ * Types Module - Barrel Export
3
+ *
4
+ * This file serves as the main entry point for all type definitions.
5
+ * It re-exports types from various modules for convenient importing.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * // Import from types module
10
+ * import { LuaSkill, LuaTool, env } from './types/index.js';
11
+ *
12
+ * // Or import specific type groups
13
+ * import { UserDataAPI, ProductAPI } from './types/api-contracts.js';
14
+ * import { validateToolName } from './types/tool-validation.js';
15
+ * ```
4
16
  */
5
- export function validateToolName(name) {
6
- const validNameRegex = /^[a-zA-Z0-9_-]+$/;
7
- return validNameRegex.test(name);
8
- }
9
- /**
10
- * Throws an error if the tool name is invalid
11
- */
12
- export function assertValidToolName(name) {
13
- if (!validateToolName(name)) {
14
- throw new Error(`Invalid tool name "${name}". Tool names can only contain alphanumeric characters, hyphens (-), and underscores (_). No spaces or other special characters are allowed.`);
15
- }
16
- }
17
+ // ============================================================================
18
+ // SKILL SYSTEM EXPORTS
19
+ // ============================================================================
20
+ // Core skill classes and utilities
21
+ export { LuaSkill, env } from './skill.js';
22
+ // Tool validation utilities
23
+ export { validateToolName, assertValidToolName } from './tool-validation.js';
24
+ // Basket types
25
+ export { BasketStatus } from '../interfaces/baskets.js';
26
+ // Order types
27
+ export { OrderStatus } from '../interfaces/orders.js';
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Lua Skill System
3
+ * Core types and classes for building Lua AI skills
4
+ */
5
+ import { ZodType } from "zod";
6
+ /**
7
+ * Safe environment variable access function.
8
+ * Gets injected at runtime with skill-specific environment variables.
9
+ *
10
+ * Checks in order:
11
+ * 1. Process environment variables (.env file)
12
+ * 2. lua.skill.yaml configuration
13
+ *
14
+ * @param key - The environment variable key to retrieve
15
+ * @returns The environment variable value or undefined if not found
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const baseUrl = env('BASE_URL');
20
+ * const apiKey = env('API_KEY');
21
+ * ```
22
+ */
23
+ export declare const env: (key: string) => string | undefined;
24
+ /**
25
+ * Lua Tool interface.
26
+ * Defines the structure of a tool that can be added to a LuaSkill.
27
+ *
28
+ * @template TInput - Zod schema type for input validation
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { z } from 'zod';
33
+ * import { LuaTool } from 'lua-cli';
34
+ *
35
+ * const weatherTool: LuaTool = {
36
+ * name: 'get_weather',
37
+ * description: 'Gets current weather for a city',
38
+ * inputSchema: z.object({
39
+ * city: z.string(),
40
+ * units: z.enum(['metric', 'imperial']).optional()
41
+ * }),
42
+ * execute: async (input) => {
43
+ * // Fetch weather data...
44
+ * return { temperature: 72, condition: 'sunny' };
45
+ * }
46
+ * };
47
+ * ```
48
+ */
49
+ export interface LuaTool<TInput extends ZodType = ZodType> {
50
+ /** Unique tool name (alphanumeric, hyphens, underscores only) */
51
+ name: string;
52
+ /** Description of what the tool does */
53
+ description: string;
54
+ /** Zod schema for input validation */
55
+ inputSchema: TInput;
56
+ /** Async function that executes the tool logic */
57
+ execute: (input: any) => Promise<any>;
58
+ }
59
+ /**
60
+ * Lua Skill configuration.
61
+ * Used to initialize a new LuaSkill instance.
62
+ */
63
+ export interface LuaSkillConfig {
64
+ /** Skill name (optional, defaults to 'unnamed-skill') */
65
+ name?: string;
66
+ /** Skill version (optional, defaults to '1.0.0') */
67
+ version?: string;
68
+ /** Short description of the skill (1-2 sentences) */
69
+ description: string;
70
+ /** Detailed context for how the agent should use the tools */
71
+ context: string;
72
+ /** Optional array of tools to add during construction */
73
+ tools?: LuaTool<any>[];
74
+ }
75
+ /**
76
+ * Lua Skill class.
77
+ * Main class for building AI skills with tools.
78
+ *
79
+ * A skill is a collection of tools that the AI agent can use to accomplish tasks.
80
+ * Tools are functions with validated inputs and well-defined outputs.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { LuaSkill } from 'lua-cli';
85
+ *
86
+ * const skill = new LuaSkill({
87
+ * name: 'weather-skill',
88
+ * version: '1.0.0',
89
+ * description: "Weather and calculator utilities",
90
+ * context: "This skill provides weather information and math operations. " +
91
+ * "Use get_weather for current conditions and calculator for arithmetic.",
92
+ * tools: [weatherTool, calculatorTool]
93
+ * });
94
+ *
95
+ * // Or add tools after construction
96
+ * skill.addTool(anotherTool);
97
+ * ```
98
+ */
99
+ export declare class LuaSkill {
100
+ private readonly tools;
101
+ private readonly name;
102
+ private readonly version;
103
+ private readonly description;
104
+ private readonly context;
105
+ /**
106
+ * Creates a new LuaSkill instance.
107
+ *
108
+ * @param config - Configuration object containing skill metadata
109
+ * @param config.name - Skill name (optional, defaults to 'unnamed-skill')
110
+ * @param config.version - Skill version (optional, defaults to '1.0.0')
111
+ * @param config.description - Short description of what the skill does (1-2 sentences)
112
+ * @param config.context - Detailed explanation of how the agent should use the tools
113
+ * @param config.tools - Optional array of tools to add immediately
114
+ */
115
+ constructor(config: LuaSkillConfig);
116
+ /**
117
+ * Adds a single tool to the skill.
118
+ * Tool name is validated before being added.
119
+ *
120
+ * @param tool - Tool to add
121
+ * @throws Error if tool name is invalid
122
+ */
123
+ addTool<TInput extends ZodType>(tool: LuaTool<TInput>): void;
124
+ /**
125
+ * Adds multiple tools to the skill.
126
+ * All tool names are validated before being added.
127
+ *
128
+ * @param tools - Array of tools to add
129
+ * @throws Error if any tool name is invalid
130
+ */
131
+ addTools(tools: LuaTool<any>[]): void;
132
+ /**
133
+ * Executes a tool by name with provided input.
134
+ * Input is validated against the tool's Zod schema.
135
+ *
136
+ * @param input - Input object containing tool name and parameters
137
+ * @param input.tool - Name of the tool to execute
138
+ * @returns Promise resolving to tool execution result
139
+ * @throws Error if tool not found or input validation fails
140
+ */
141
+ run(input: Record<string, any>): Promise<any>;
142
+ }
@@ -1,10 +1,18 @@
1
- import { assertValidToolName } from "./types/index.js";
1
+ /**
2
+ * Lua Skill System
3
+ * Core types and classes for building Lua AI skills
4
+ */
5
+ import { assertValidToolName } from "./tool-validation.js";
2
6
  import fs from "fs";
3
7
  import path from "path";
4
8
  import yaml from "js-yaml";
5
9
  /**
6
- * Safe environment variable access function
7
- * Gets injected at runtime with skill-specific environment variables
10
+ * Safe environment variable access function.
11
+ * Gets injected at runtime with skill-specific environment variables.
12
+ *
13
+ * Checks in order:
14
+ * 1. Process environment variables (.env file)
15
+ * 2. lua.skill.yaml configuration
8
16
  *
9
17
  * @param key - The environment variable key to retrieve
10
18
  * @returns The environment variable value or undefined if not found
@@ -18,13 +26,13 @@ import yaml from "js-yaml";
18
26
  export const env = (key) => {
19
27
  // Try to load environment variables from lua.skill.yaml
20
28
  try {
21
- // Look for lua.skill.yaml in current directory and parent directories
22
- let currentDir = process.cwd();
23
- let yamlPath = null;
24
- //check if in .env file
29
+ // Check process.env first (.env file)
25
30
  if (process.env[key]) {
26
31
  return process.env[key];
27
32
  }
33
+ // Look for lua.skill.yaml in current directory and parent directories
34
+ let currentDir = process.cwd();
35
+ let yamlPath = null;
28
36
  while (currentDir !== path.dirname(currentDir)) {
29
37
  const potentialPath = path.join(currentDir, 'lua.skill.yaml');
30
38
  if (fs.existsSync(potentialPath)) {
@@ -45,21 +53,40 @@ export const env = (key) => {
45
53
  }
46
54
  return undefined;
47
55
  };
56
+ /**
57
+ * Lua Skill class.
58
+ * Main class for building AI skills with tools.
59
+ *
60
+ * A skill is a collection of tools that the AI agent can use to accomplish tasks.
61
+ * Tools are functions with validated inputs and well-defined outputs.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * import { LuaSkill } from 'lua-cli';
66
+ *
67
+ * const skill = new LuaSkill({
68
+ * name: 'weather-skill',
69
+ * version: '1.0.0',
70
+ * description: "Weather and calculator utilities",
71
+ * context: "This skill provides weather information and math operations. " +
72
+ * "Use get_weather for current conditions and calculator for arithmetic.",
73
+ * tools: [weatherTool, calculatorTool]
74
+ * });
75
+ *
76
+ * // Or add tools after construction
77
+ * skill.addTool(anotherTool);
78
+ * ```
79
+ */
48
80
  export class LuaSkill {
49
81
  /**
50
- * Creates a new LuaSkill instance
82
+ * Creates a new LuaSkill instance.
51
83
  *
52
84
  * @param config - Configuration object containing skill metadata
85
+ * @param config.name - Skill name (optional, defaults to 'unnamed-skill')
86
+ * @param config.version - Skill version (optional, defaults to '1.0.0')
53
87
  * @param config.description - Short description of what the skill does (1-2 sentences)
54
88
  * @param config.context - Detailed explanation of how the agent should use the tools
55
- *
56
- * @example
57
- * ```typescript
58
- * const skill = new LuaSkill({
59
- * description: "Weather and calculator utilities",
60
- * context: "This skill provides weather information for any city and basic mathematical operations. Use get_weather for current conditions and calculator for arithmetic operations."
61
- * });
62
- * ```
89
+ * @param config.tools - Optional array of tools to add immediately
63
90
  */
64
91
  constructor(config) {
65
92
  this.tools = [];
@@ -72,11 +99,24 @@ export class LuaSkill {
72
99
  this.addTools(config.tools);
73
100
  }
74
101
  }
102
+ /**
103
+ * Adds a single tool to the skill.
104
+ * Tool name is validated before being added.
105
+ *
106
+ * @param tool - Tool to add
107
+ * @throws Error if tool name is invalid
108
+ */
75
109
  addTool(tool) {
76
- // Validate the tool name before adding it
77
110
  assertValidToolName(tool.name);
78
111
  this.tools.push(tool);
79
112
  }
113
+ /**
114
+ * Adds multiple tools to the skill.
115
+ * All tool names are validated before being added.
116
+ *
117
+ * @param tools - Array of tools to add
118
+ * @throws Error if any tool name is invalid
119
+ */
80
120
  addTools(tools) {
81
121
  // Validate all tool names before adding them
82
122
  for (const tool of tools) {
@@ -84,6 +124,15 @@ export class LuaSkill {
84
124
  }
85
125
  this.tools.push(...tools);
86
126
  }
127
+ /**
128
+ * Executes a tool by name with provided input.
129
+ * Input is validated against the tool's Zod schema.
130
+ *
131
+ * @param input - Input object containing tool name and parameters
132
+ * @param input.tool - Name of the tool to execute
133
+ * @returns Promise resolving to tool execution result
134
+ * @throws Error if tool not found or input validation fails
135
+ */
87
136
  async run(input) {
88
137
  const tool = this.tools.find(tool => tool.name === input.tool);
89
138
  if (!tool) {
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Tool Validation Utilities
3
+ * Validates tool names and other tool-related constraints
4
+ */
5
+ /**
6
+ * Validates that a tool name contains only alphanumeric characters, hyphens, and underscores.
7
+ * No spaces or other special characters are allowed.
8
+ *
9
+ * This restriction ensures tool names:
10
+ * - Are compatible with all systems
11
+ * - Can be used in URLs and file paths
12
+ * - Are easy to reference in code
13
+ *
14
+ * Valid examples: "my-tool", "calculate_sum", "getTodo123"
15
+ * Invalid examples: "my tool", "calc@sum", "get.todo"
16
+ *
17
+ * @param name - Tool name to validate
18
+ * @returns True if name is valid, false otherwise
19
+ */
20
+ export declare function validateToolName(name: string): boolean;
21
+ /**
22
+ * Asserts that a tool name is valid, throwing an error if not.
23
+ * Use this when adding tools to ensure names are valid.
24
+ *
25
+ * @param name - Tool name to validate
26
+ * @throws Error if tool name is invalid
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * assertValidToolName('my-tool'); // OK
31
+ * assertValidToolName('my tool'); // Throws error
32
+ * ```
33
+ */
34
+ export declare function assertValidToolName(name: string): void;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Tool Validation Utilities
3
+ * Validates tool names and other tool-related constraints
4
+ */
5
+ /**
6
+ * Validates that a tool name contains only alphanumeric characters, hyphens, and underscores.
7
+ * No spaces or other special characters are allowed.
8
+ *
9
+ * This restriction ensures tool names:
10
+ * - Are compatible with all systems
11
+ * - Can be used in URLs and file paths
12
+ * - Are easy to reference in code
13
+ *
14
+ * Valid examples: "my-tool", "calculate_sum", "getTodo123"
15
+ * Invalid examples: "my tool", "calc@sum", "get.todo"
16
+ *
17
+ * @param name - Tool name to validate
18
+ * @returns True if name is valid, false otherwise
19
+ */
20
+ export function validateToolName(name) {
21
+ const validNameRegex = /^[a-zA-Z0-9_-]+$/;
22
+ return validNameRegex.test(name);
23
+ }
24
+ /**
25
+ * Asserts that a tool name is valid, throwing an error if not.
26
+ * Use this when adding tools to ensure names are valid.
27
+ *
28
+ * @param name - Tool name to validate
29
+ * @throws Error if tool name is invalid
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * assertValidToolName('my-tool'); // OK
34
+ * assertValidToolName('my tool'); // Throws error
35
+ * ```
36
+ */
37
+ export function assertValidToolName(name) {
38
+ if (!validateToolName(name)) {
39
+ throw new Error(`Invalid tool name "${name}". Tool names can only contain alphanumeric characters, ` +
40
+ `hyphens (-), and underscores (_). No spaces or other special characters are allowed.`);
41
+ }
42
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Authentication Flow Utilities
3
+ * Handles different authentication methods (API key and email OTP)
4
+ */
5
+ /**
6
+ * Handles API key authentication flow.
7
+ * Prompts for API key, validates it, and saves it securely.
8
+ *
9
+ * @returns Promise that resolves when authentication is complete
10
+ * @throws Error if API key is invalid
11
+ */
12
+ export declare function handleApiKeyAuth(): Promise<void>;
13
+ /**
14
+ * Handles email authentication flow with OTP verification.
15
+ * Sends OTP to email, verifies it, generates API key, and saves it.
16
+ *
17
+ * @returns Promise that resolves when authentication is complete
18
+ * @throws Error if OTP sending fails, verification fails, or API key generation fails
19
+ */
20
+ export declare function handleEmailAuth(): Promise<void>;
21
+ /**
22
+ * Prompts user to choose authentication method.
23
+ *
24
+ * @returns Selected authentication method ('api-key' or 'email')
25
+ */
26
+ export declare function promptAuthMethod(): Promise<'api-key' | 'email'>;