lua-cli 1.3.0 → 1.3.2-alpha.0

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/README.md CHANGED
@@ -401,7 +401,7 @@ The Lua CLI provides a built-in User Data API that allows your tools to interact
401
401
  ### Basic Usage
402
402
 
403
403
  ```typescript
404
- import { user } from 'lua-cli';
404
+ import { user } from 'lua-cli/user-data-api';
405
405
 
406
406
  // Get user data
407
407
  const userData = await user.data.get();
@@ -432,8 +432,8 @@ await user.data.clear();
432
432
  ### Using in Tools
433
433
 
434
434
  ```typescript
435
- import { LuaTool } from 'lua-cli';
436
- import { user } from 'lua-cli';
435
+ import { LuaTool } from 'lua-cli/skill';
436
+ import { user } from 'lua-cli/user-data-api';
437
437
  import { z } from 'zod';
438
438
 
439
439
  export class UserPreferencesTool extends LuaTool {
@@ -7,6 +7,9 @@ import { Buffer } from "buffer";
7
7
  import { createRequire } from "module";
8
8
  import vm from "vm";
9
9
  import { withErrorHandling, clearPromptLines, writeProgress, writeSuccess } from "../utils/cli.js";
10
+ import { UserDataApi } from "../services/api.js";
11
+ import { loadApiKey } from "../services/auth.js";
12
+ import { readSkillConfig } from "../utils/files.js";
10
13
  // Decompression utility
11
14
  function decompressCode(compressedCode) {
12
15
  const buffer = Buffer.from(compressedCode, 'base64');
@@ -32,6 +35,16 @@ export async function testCommand() {
32
35
  if (!deployData.tools || deployData.tools.length === 0) {
33
36
  throw new Error("No tools found in deploy.json");
34
37
  }
38
+ // Get API key from keystore and agent ID from YAML
39
+ const apiKey = await loadApiKey();
40
+ if (!apiKey) {
41
+ throw new Error("No API key found. Please run 'lua auth configure' first.");
42
+ }
43
+ const config = readSkillConfig();
44
+ const agentId = config?.agent?.agentId;
45
+ if (!agentId) {
46
+ throw new Error("No agent ID found in lua.skill.yaml. Please run 'lua skill init' first.");
47
+ }
35
48
  // Let user select a tool using picker
36
49
  const toolChoices = deployData.tools.map((tool) => ({
37
50
  name: `${tool.name} - ${tool.description}`,
@@ -119,6 +132,15 @@ export async function testCommand() {
119
132
  try {
120
133
  // Create a CommonJS context for execution
121
134
  const require = createRequire(process.cwd() + '/package.json');
135
+ const updateUserData = async (data) => {
136
+ return await UserDataApi.updateUserData(apiKey, agentId, data);
137
+ };
138
+ const getUserData = async () => {
139
+ return await UserDataApi.getUserData(apiKey, agentId);
140
+ };
141
+ const linkUserData = async (data) => {
142
+ return await UserDataApi.createUserData(apiKey, agentId, data);
143
+ };
122
144
  // Create a sandbox context with require and other necessary globals
123
145
  const sandbox = {
124
146
  require,
@@ -160,7 +182,14 @@ export async function testCommand() {
160
182
  undefined: undefined,
161
183
  null: null,
162
184
  Infinity: Infinity,
163
- NaN: NaN
185
+ NaN: NaN,
186
+ user: {
187
+ data: {
188
+ update: updateUserData,
189
+ get: getUserData,
190
+ create: linkUserData
191
+ }
192
+ }
164
193
  };
165
194
  // Create the CommonJS wrapper code
166
195
  const commonJsWrapper = `
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export { user, createUserDataAPI, UserDataAPI } from './user-data-api.js';
2
+ export { user, UserDataAPI } from './user-data-api.js';
package/dist/index.js CHANGED
@@ -46,4 +46,4 @@ skillCommand
46
46
  .action(devCommand);
47
47
  program.parse(process.argv);
48
48
  // Export user data API for use in projects
49
- export { user, createUserDataAPI, UserDataAPI } from './user-data-api.js';
49
+ export { user, UserDataAPI } from './user-data-api.js';
@@ -183,6 +183,12 @@ export declare class ToolApi {
183
183
  static deleteTool(url: string, apiKey: string): Promise<ApiResponse<any>>;
184
184
  static patchTool(url: string, data: any, apiKey: string): Promise<ApiResponse<any>>;
185
185
  }
186
+ export declare class UserDataApi {
187
+ static getUserData(apiKey: string, agentId: string): Promise<ApiResponse<UserData>>;
188
+ static createUserData(apiKey: string, agentId: string, data: any): Promise<ApiResponse<UserData>>;
189
+ static updateUserData(apiKey: string, agentId: string, data: any): Promise<ApiResponse<UserData>>;
190
+ static deleteUserData(apiKey: string, agentId: string): Promise<ApiResponse<UserData>>;
191
+ }
186
192
  /**
187
193
  * Main API service that exports all API classes
188
194
  */
@@ -197,6 +197,29 @@ export class ToolApi {
197
197
  });
198
198
  }
199
199
  }
200
+ // User Data API calls
201
+ export class UserDataApi {
202
+ static async getUserData(apiKey, agentId) {
203
+ return httpClient.get(`${BASE_URLS.LOCAL}/developer/user/data/agent/${agentId}`, {
204
+ Authorization: `Bearer ${apiKey}`,
205
+ });
206
+ }
207
+ static async createUserData(apiKey, agentId, data) {
208
+ return httpClient.post(`${BASE_URLS.LOCAL}/developer/user/data/agent/${agentId}`, data, {
209
+ Authorization: `Bearer ${apiKey}`,
210
+ });
211
+ }
212
+ static async updateUserData(apiKey, agentId, data) {
213
+ return httpClient.put(`${BASE_URLS.LOCAL}/developer/user/data/agent/${agentId}`, data, {
214
+ Authorization: `Bearer ${apiKey}`,
215
+ });
216
+ }
217
+ static async deleteUserData(apiKey, agentId) {
218
+ return httpClient.delete(`${BASE_URLS.LOCAL}/developer/user/data/agent/${agentId}`, {
219
+ Authorization: `Bearer ${apiKey}`,
220
+ });
221
+ }
222
+ }
200
223
  /**
201
224
  * Main API service that exports all API classes
202
225
  */
@@ -3,14 +3,7 @@
3
3
  * Provides methods to interact with user data stored in the Lua system
4
4
  */
5
5
  export declare class UserDataAPI {
6
- private apiKey;
7
- private agentId;
8
- constructor(apiKey?: string, agentId?: string);
9
- /**
10
- * Initialize the API with credentials
11
- * If not provided, will attempt to load from stored configuration
12
- */
13
- initialize(): Promise<void>;
6
+ constructor();
14
7
  /**
15
8
  * Get user data for the current agent
16
9
  * @returns Promise<UserDataResponse>
@@ -43,10 +36,3 @@ export declare class UserDataAPI {
43
36
  export declare const user: {
44
37
  data: UserDataAPI;
45
38
  };
46
- /**
47
- * Create a new UserDataAPI instance with custom credentials
48
- * @param apiKey - Optional API key
49
- * @param agentId - Optional agent ID
50
- * @returns UserDataAPI instance
51
- */
52
- export declare function createUserDataAPI(apiKey?: string, agentId?: string): UserDataAPI;
@@ -1,60 +1,15 @@
1
- import { readSkillConfig } from './utils/files.js';
2
- import { loadApiKey } from './services/auth.js';
3
1
  /**
4
2
  * User Data API for Lua CLI projects
5
3
  * Provides methods to interact with user data stored in the Lua system
6
4
  */
7
5
  export class UserDataAPI {
8
- constructor(apiKey, agentId) {
9
- this.apiKey = apiKey || '';
10
- this.agentId = agentId || '';
11
- }
12
- /**
13
- * Initialize the API with credentials
14
- * If not provided, will attempt to load from stored configuration
15
- */
16
- async initialize() {
17
- if (!this.apiKey) {
18
- this.apiKey = await loadApiKey() || '';
19
- }
20
- if (!this.agentId) {
21
- const config = await readSkillConfig();
22
- this.agentId = config.agent.agentId;
23
- }
24
- if (!this.apiKey || !this.agentId) {
25
- throw new Error('API key and agent ID are required. Please run "lua auth configure" first.');
26
- }
27
- }
6
+ constructor() { }
28
7
  /**
29
8
  * Get user data for the current agent
30
9
  * @returns Promise<UserDataResponse>
31
10
  */
32
11
  async get() {
33
- await this.initialize();
34
- const response = await fetch(`http://localhost:3022/developer/user/data/agent/${this.agentId}`, {
35
- method: 'GET',
36
- headers: {
37
- 'accept': '*/*',
38
- 'Authorization': `Bearer ${this.apiKey}`
39
- }
40
- });
41
- if (!response.ok) {
42
- // Try alternative authentication method if Bearer fails
43
- if (response.status === 401) {
44
- const altResponse = await fetch(`http://localhost:3022/developer/user/data/agent/${this.agentId}`, {
45
- method: 'GET',
46
- headers: {
47
- 'accept': '*/*',
48
- 'Authorization': this.apiKey
49
- }
50
- });
51
- if (altResponse.ok) {
52
- return await altResponse.json();
53
- }
54
- }
55
- throw new Error(`Failed to get user data: ${response.status} ${response.statusText}`);
56
- }
57
- return await response.json();
12
+ return { success: true };
58
13
  }
59
14
  /**
60
15
  * Create or update user data for the current agent
@@ -62,35 +17,7 @@ export class UserDataAPI {
62
17
  * @returns Promise<UserDataResponse>
63
18
  */
64
19
  async create(data) {
65
- await this.initialize();
66
- const response = await fetch(`http://localhost:3022/developer/user/data/agent/${this.agentId}`, {
67
- method: 'PUT',
68
- headers: {
69
- 'accept': '*/*',
70
- 'Authorization': `Bearer ${this.apiKey}`,
71
- 'Content-Type': 'application/json'
72
- },
73
- body: JSON.stringify(data)
74
- });
75
- if (!response.ok) {
76
- // Try alternative authentication method if Bearer fails
77
- if (response.status === 401) {
78
- const altResponse = await fetch(`http://localhost:3022/developer/user/data/agent/${this.agentId}`, {
79
- method: 'PUT',
80
- headers: {
81
- 'accept': '*/*',
82
- 'Authorization': this.apiKey,
83
- 'Content-Type': 'application/json'
84
- },
85
- body: JSON.stringify(data)
86
- });
87
- if (altResponse.ok) {
88
- return await altResponse.json();
89
- }
90
- }
91
- throw new Error(`Failed to create user data: ${response.status} ${response.statusText}`);
92
- }
93
- return await response.json();
20
+ return { success: true };
94
21
  }
95
22
  /**
96
23
  * Update existing user data for the current agent
@@ -99,38 +26,14 @@ export class UserDataAPI {
99
26
  */
100
27
  async update(data) {
101
28
  // Update is the same as create for this API
102
- return this.create(data);
29
+ return { success: true };
103
30
  }
104
31
  /**
105
32
  * Clear all user data for the current agent
106
33
  * @returns Promise<{success: boolean}>
107
34
  */
108
35
  async clear() {
109
- await this.initialize();
110
- const response = await fetch(`http://localhost:3022/developer/user/data/agent/${this.agentId}`, {
111
- method: 'DELETE',
112
- headers: {
113
- 'accept': '*/*',
114
- 'Authorization': `Bearer ${this.apiKey}`
115
- }
116
- });
117
- if (!response.ok) {
118
- // Try alternative authentication method if Bearer fails
119
- if (response.status === 401) {
120
- const altResponse = await fetch(`http://localhost:3022/developer/user/data/agent/${this.agentId}`, {
121
- method: 'DELETE',
122
- headers: {
123
- 'accept': '*/*',
124
- 'Authorization': this.apiKey
125
- }
126
- });
127
- if (altResponse.ok) {
128
- return await altResponse.json();
129
- }
130
- }
131
- throw new Error(`Failed to clear user data: ${response.status} ${response.statusText}`);
132
- }
133
- return await response.json();
36
+ return { success: true };
134
37
  }
135
38
  }
136
39
  /**
@@ -140,12 +43,3 @@ export class UserDataAPI {
140
43
  export const user = {
141
44
  data: new UserDataAPI()
142
45
  };
143
- /**
144
- * Create a new UserDataAPI instance with custom credentials
145
- * @param apiKey - Optional API key
146
- * @param agentId - Optional agent ID
147
- * @returns UserDataAPI instance
148
- */
149
- export function createUserDataAPI(apiKey, agentId) {
150
- return new UserDataAPI(apiKey, agentId);
151
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lua-cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.2-alpha.0",
4
4
  "description": "Command-line interface for Lua AI platform - develop, test, and deploy LuaSkills with custom tools",
5
5
  "readmeFilename": "README.md",
6
6
  "main": "dist/index.js",
@@ -4,7 +4,7 @@ import GetUserDataTool from "./tools/GetUserDataTool";
4
4
  import CreatePostTool from "./tools/CreatePostTool";
5
5
  import CalculatorTool from "./tools/CalculatorTool";
6
6
  import AdvancedMathTool from "./tools/AdvancedMathTool";
7
- import { UserPreferencesTool } from "./tools/UserPreferencesTool";
7
+
8
8
 
9
9
  // Initialize skill with tools
10
10
  const skill = new LuaSkill({
@@ -13,10 +13,9 @@ const skill = new LuaSkill({
13
13
  });
14
14
  skill.addTool(new GetWeatherTool());
15
15
  skill.addTool(new GetUserDataTool());
16
- skill.addTool(new UserPreferencesTool());
17
- // skill.addTool(new CreatePostTool());
18
- // skill.addTool(new CalculatorTool());
19
- // skill.addTool(new AdvancedMathTool());
16
+ skill.addTool(new CreatePostTool());
17
+ skill.addTool(new CalculatorTool());
18
+ skill.addTool(new AdvancedMathTool());
20
19
 
21
20
  // Test cases
22
21
  const testCases = [
@@ -1,5 +1,5 @@
1
- import { LuaTool } from 'lua-cli';
2
- import { user } from 'lua-cli';
1
+ import { LuaTool } from 'lua-cli/skill';
2
+ import { user } from 'lua-cli/user-data-api';
3
3
  import { z } from 'zod';
4
4
 
5
5
  /**
@@ -1,73 +0,0 @@
1
- import { LuaTool } from 'lua-cli';
2
- import { user } from 'lua-cli';
3
- import { z } from 'zod';
4
-
5
- /**
6
- * Example tool demonstrating User Data API usage
7
- * This tool allows users to manage their preferences
8
- */
9
- export class UserPreferencesTool extends LuaTool {
10
- constructor() {
11
- super('user-preferences', 'Manage user preferences and settings');
12
- }
13
-
14
- async execute(input: { action: string; key?: string; value?: string }) {
15
- const { action, key, value } = input;
16
-
17
- try {
18
- switch (action) {
19
- case 'get':
20
- const userData = await user.data.get();
21
- return {
22
- success: true,
23
- preferences: userData.preferences || {},
24
- message: 'Preferences retrieved successfully'
25
- };
26
-
27
- case 'set':
28
- if (!key || !value) {
29
- throw new Error('Key and value are required for set action');
30
- }
31
-
32
- const currentData = await user.data.get();
33
- const updatedData = {
34
- ...currentData,
35
- preferences: {
36
- ...currentData.preferences,
37
- [key]: value
38
- }
39
- };
40
-
41
- await user.data.update(updatedData);
42
- return {
43
- success: true,
44
- message: `Set ${key} to ${value}`,
45
- preferences: updatedData.preferences
46
- };
47
-
48
- case 'clear':
49
- await user.data.clear();
50
- return {
51
- success: true,
52
- message: 'All preferences cleared'
53
- };
54
-
55
- default:
56
- throw new Error('Invalid action. Use: get, set, or clear');
57
- }
58
- } catch (error) {
59
- return {
60
- success: false,
61
- error: error instanceof Error ? error.message : 'Unknown error occurred'
62
- };
63
- }
64
- }
65
-
66
- getInputSchema() {
67
- return z.object({
68
- action: z.enum(['get', 'set', 'clear']).describe('Action to perform: get (retrieve preferences), set (update a preference), or clear (remove all preferences)'),
69
- key: z.string().optional().describe('Preference key (required for set action)'),
70
- value: z.string().optional().describe('Preference value (required for set action)')
71
- });
72
- }
73
- }