lua-cli 2.2.8-alpha.2 → 2.3.0-alpha.2
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.
- package/API_REFERENCE.md +1408 -0
- package/CLI_REFERENCE.md +818 -0
- package/GETTING_STARTED.md +1040 -0
- package/README.md +738 -424
- package/TEMPLATE_GUIDE.md +1398 -0
- package/dist/api/agent.api.service.d.ts +33 -6
- package/dist/api/agent.api.service.js +27 -0
- package/dist/api/auth.api.service.d.ts +31 -2
- package/dist/api/auth.api.service.js +29 -0
- package/dist/api/basket.api.service.d.ts +53 -11
- package/dist/api/basket.api.service.js +63 -14
- package/dist/api/chat.api.service.d.ts +15 -3
- package/dist/api/chat.api.service.js +12 -0
- package/dist/api/credentials.d.ts +24 -0
- package/dist/api/credentials.js +46 -0
- package/dist/api/custom.data.api.service.d.ts +45 -9
- package/dist/api/custom.data.api.service.js +43 -9
- package/dist/api/lazy-instances.d.ts +49 -0
- package/dist/api/lazy-instances.js +95 -0
- package/dist/api/order.api.service.d.ts +34 -4
- package/dist/api/order.api.service.js +41 -3
- package/dist/api/products.api.service.d.ts +39 -9
- package/dist/api/products.api.service.js +43 -5
- package/dist/api/skills.api.service.d.ts +49 -2
- package/dist/api/skills.api.service.js +47 -1
- package/dist/api/tool.api.service.d.ts +39 -1
- package/dist/api/tool.api.service.js +38 -0
- package/dist/api/user.data.api.service.d.ts +23 -1
- package/dist/api/user.data.api.service.js +22 -0
- package/dist/api-exports.d.ts +236 -5
- package/dist/api-exports.js +264 -81
- package/dist/cli/command-definitions.d.ts +30 -0
- package/dist/cli/command-definitions.js +71 -0
- package/dist/commands/agents.d.ts +20 -0
- package/dist/commands/agents.js +24 -2
- package/dist/commands/apiKey.d.ts +23 -0
- package/dist/commands/apiKey.js +23 -0
- package/dist/commands/compile.d.ts +24 -0
- package/dist/commands/compile.js +67 -759
- package/dist/commands/configure.d.ts +24 -0
- package/dist/commands/configure.js +31 -96
- package/dist/commands/deploy.d.ts +31 -19
- package/dist/commands/deploy.js +45 -74
- package/dist/commands/destroy.d.ts +27 -0
- package/dist/commands/destroy.js +27 -1
- package/dist/commands/dev.d.ts +25 -62
- package/dist/commands/dev.js +58 -878
- package/dist/commands/init.d.ts +27 -0
- package/dist/commands/init.js +98 -260
- package/dist/commands/push.d.ts +24 -21
- package/dist/commands/push.js +39 -92
- package/dist/commands/test.d.ts +26 -0
- package/dist/commands/test.js +41 -188
- package/dist/common/basket.instance.d.ts +54 -3
- package/dist/common/basket.instance.js +56 -3
- package/dist/common/data.entry.instance.d.ts +25 -2
- package/dist/common/data.entry.instance.js +24 -0
- package/dist/common/http.client.d.ts +51 -1
- package/dist/common/http.client.js +50 -0
- package/dist/common/order.instance.d.ts +22 -0
- package/dist/common/order.instance.js +31 -4
- package/dist/common/product.instance.d.ts +22 -1
- package/dist/common/product.instance.js +24 -6
- package/dist/common/product.pagination.instance.d.ts +22 -2
- package/dist/common/product.pagination.instance.js +22 -1
- package/dist/common/product.search.instance.d.ts +13 -3
- package/dist/common/product.search.instance.js +12 -1
- package/dist/common/user.instance.d.ts +27 -3
- package/dist/common/user.instance.js +28 -7
- package/dist/config/auth.constants.d.ts +11 -0
- package/dist/config/auth.constants.js +11 -0
- package/dist/config/compile.constants.d.ts +67 -0
- package/dist/config/compile.constants.js +99 -0
- package/dist/config/constants.d.ts +5 -0
- package/dist/config/constants.js +5 -0
- package/dist/config/dev.constants.d.ts +65 -0
- package/dist/config/dev.constants.js +79 -0
- package/dist/config/init.constants.d.ts +23 -0
- package/dist/config/init.constants.js +41 -0
- package/dist/index.d.ts +19 -3
- package/dist/index.js +28 -44
- package/dist/interfaces/admin.d.ts +56 -50
- package/dist/interfaces/admin.js +4 -0
- package/dist/interfaces/agent.d.ts +21 -0
- package/dist/interfaces/agent.js +4 -0
- package/dist/interfaces/baskets.d.ts +60 -0
- package/dist/interfaces/baskets.js +12 -0
- package/dist/interfaces/chat.d.ts +48 -4
- package/dist/interfaces/chat.js +4 -0
- package/dist/interfaces/common.d.ts +62 -0
- package/dist/interfaces/common.js +8 -0
- package/dist/interfaces/compile.d.ts +11 -0
- package/dist/interfaces/compile.js +4 -0
- package/dist/interfaces/custom.data.d.ts +49 -19
- package/dist/interfaces/custom.data.js +4 -0
- package/dist/interfaces/deploy.d.ts +29 -0
- package/dist/interfaces/deploy.js +4 -0
- package/dist/interfaces/dev.d.ts +53 -0
- package/dist/interfaces/dev.js +5 -0
- package/dist/interfaces/init.d.ts +60 -0
- package/dist/interfaces/init.js +4 -0
- package/dist/interfaces/orders.d.ts +37 -0
- package/dist/interfaces/orders.js +12 -0
- package/dist/interfaces/product.d.ts +38 -10
- package/dist/interfaces/product.js +4 -0
- package/dist/interfaces/push.d.ts +26 -0
- package/dist/interfaces/push.js +4 -0
- package/dist/interfaces/test.d.ts +36 -0
- package/dist/interfaces/test.js +4 -0
- package/dist/services/auth.d.ts +54 -99
- package/dist/services/auth.js +76 -12
- package/dist/types/api-contracts.d.ts +211 -0
- package/dist/types/api-contracts.js +8 -0
- package/dist/types/compile.types.d.ts +76 -0
- package/dist/types/compile.types.js +4 -0
- package/dist/types/index.d.ts +23 -121
- package/dist/types/index.js +25 -14
- package/dist/types/skill.d.ts +142 -0
- package/dist/{skill.js → types/skill.js} +66 -17
- package/dist/types/tool-validation.d.ts +34 -0
- package/dist/types/tool-validation.js +42 -0
- package/dist/utils/auth-flows.d.ts +26 -0
- package/dist/utils/auth-flows.js +141 -0
- package/dist/utils/bundling.d.ts +36 -0
- package/dist/utils/bundling.js +137 -0
- package/dist/utils/compile.d.ts +37 -0
- package/dist/utils/compile.js +242 -0
- package/dist/utils/deploy-api.d.ts +26 -0
- package/dist/utils/deploy-api.js +53 -0
- package/dist/utils/deploy-helpers.d.ts +46 -0
- package/dist/utils/deploy-helpers.js +86 -0
- package/dist/utils/deployment.d.ts +25 -0
- package/dist/utils/deployment.js +161 -0
- package/dist/utils/dev-api.d.ts +61 -0
- package/dist/utils/dev-api.js +262 -0
- package/dist/utils/dev-helpers.d.ts +46 -0
- package/dist/utils/dev-helpers.js +83 -0
- package/dist/utils/dev-server.d.ts +24 -0
- package/dist/utils/dev-server.js +555 -0
- package/dist/utils/dev-watcher.d.ts +31 -0
- package/dist/utils/dev-watcher.js +110 -0
- package/dist/utils/files.js +0 -5
- package/dist/utils/init-agent.d.ts +34 -0
- package/dist/utils/init-agent.js +129 -0
- package/dist/utils/init-helpers.d.ts +41 -0
- package/dist/utils/init-helpers.js +73 -0
- package/dist/utils/init-prompts.d.ts +47 -0
- package/dist/utils/init-prompts.js +168 -0
- package/dist/utils/push-api.d.ts +15 -0
- package/dist/utils/push-api.js +48 -0
- package/dist/utils/push-helpers.d.ts +38 -0
- package/dist/utils/push-helpers.js +84 -0
- package/dist/utils/sandbox-storage.d.ts +27 -0
- package/dist/utils/sandbox-storage.js +71 -0
- package/dist/utils/sandbox.js +78 -114
- package/dist/utils/skill-management.d.ts +14 -0
- package/dist/utils/skill-management.js +148 -0
- package/dist/utils/test-helpers.d.ts +40 -0
- package/dist/utils/test-helpers.js +92 -0
- package/dist/utils/test-prompts.d.ts +23 -0
- package/dist/utils/test-prompts.js +186 -0
- package/dist/utils/tool-detection.d.ts +18 -0
- package/dist/utils/tool-detection.js +110 -0
- package/dist/web/app.css +941 -17
- package/dist/web/app.js +174 -22
- package/dist/web/index.html +7 -1
- package/package.json +13 -4
- package/template/QUICKSTART.md +299 -144
- package/template/README.md +928 -349
- package/template/TOOL_EXAMPLES.md +655 -0
- package/template/package-lock.json +5 -5
- package/template/package.json +1 -1
- package/template/src/index.ts +147 -207
- package/template/src/tools/BasketTool.ts +128 -0
- package/template/src/tools/CustomDataTool.ts +7 -13
- package/template/src/tools/OrderTool.ts +54 -0
- package/template/src/tools/PaymentTool.ts +1 -1
- package/template/src/tools/ProductsTool.ts +56 -118
- package/template/src/tools/UserDataTool.ts +4 -26
- package/dist/common/config.d.ts +0 -5
- package/dist/common/config.js +0 -5
- package/dist/custom-data-api.d.ts +0 -72
- package/dist/custom-data-api.js +0 -174
- package/dist/product-api.d.ts +0 -189
- package/dist/product-api.js +0 -141
- package/dist/services/api.d.ts +0 -549
- package/dist/services/api.js +0 -596
- package/dist/skill.d.ts +0 -50
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -2
- package/dist/user-data-api.d.ts +0 -39
- package/dist/user-data-api.js +0 -50
- package/template/API.md +0 -604
- package/template/DEVELOPER.md +0 -771
- 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
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
58
|
-
*
|
|
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
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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';
|
package/dist/types/index.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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'>;
|