lua-cli 1.3.0-alpha.1 → 1.3.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/CHANGELOG.md +8 -3
- package/README.md +168 -14
- package/dist/commands/agents.js +5 -9
- package/dist/commands/compile.js +252 -70
- package/dist/commands/deploy-new.d.ts +0 -20
- package/dist/commands/deploy-new.js +130 -128
- package/dist/commands/deploy.js +15 -43
- package/dist/commands/dev.d.ts +63 -0
- package/dist/commands/dev.js +656 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.js +1 -0
- package/dist/commands/init.js +230 -42
- package/dist/commands/push.js +25 -36
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -1
- package/dist/services/api.d.ts +195 -0
- package/dist/services/api.js +209 -0
- package/dist/services/auth.d.ts +82 -0
- package/dist/services/auth.js +101 -51
- package/dist/user-data-api.d.ts +52 -0
- package/dist/user-data-api.js +151 -0
- package/dist/utils/files.d.ts +4 -1
- package/dist/utils/files.js +62 -16
- package/dist/web/app.css +1050 -0
- package/dist/web/app.js +79 -0
- package/dist/web/tools-page.css +377 -0
- package/package.json +17 -4
- package/template/package-lock.json +32 -3
- package/template/package.json +3 -1
- package/template/{index.ts → src/index.ts} +9 -3
- package/template/src/tools/UserPreferencesTool.ts +73 -0
- package/template/tools/UserPreferencesTool.ts +73 -0
- package/template/tsconfig.json +1 -1
- package/template/.lua/deploy.json +0 -148
- /package/template/{services → src/services}/ApiService.ts +0 -0
- /package/template/{services → src/services}/GetWeather.ts +0 -0
- /package/template/{services → src/services}/MathService.ts +0 -0
- /package/template/{tools → src/tools}/AdvancedMathTool.ts +0 -0
- /package/template/{tools → src/tools}/CalculatorTool.ts +0 -0
- /package/template/{tools → src/tools}/CreatePostTool.ts +0 -0
- /package/template/{tools → src/tools}/GetUserDataTool.ts +0 -0
- /package/template/{tools → src/tools}/GetWeatherTool.ts +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized API service for all Lua CLI API calls
|
|
3
|
+
* This service handles all HTTP requests to various Lua endpoints
|
|
4
|
+
*/
|
|
5
|
+
// Base URLs for different environments
|
|
6
|
+
const BASE_URLS = {
|
|
7
|
+
LOCAL: 'http://localhost:3022',
|
|
8
|
+
API: 'https://api.lua.dev',
|
|
9
|
+
AUTH: 'https://auth.lua.dev',
|
|
10
|
+
CHAT: 'http://localhost:3001'
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Generic HTTP client with common error handling
|
|
14
|
+
*/
|
|
15
|
+
class HttpClient {
|
|
16
|
+
async request(url, options = {}) {
|
|
17
|
+
try {
|
|
18
|
+
const response = await fetch(url, {
|
|
19
|
+
...options,
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
...options.headers,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const data = await response.json();
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
return {
|
|
28
|
+
success: false,
|
|
29
|
+
error: {
|
|
30
|
+
message: data.message || data.error || `HTTP ${response.status}`,
|
|
31
|
+
statusCode: response.status,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
data,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: {
|
|
44
|
+
message: error instanceof Error ? error.message : 'Network error',
|
|
45
|
+
statusCode: 500,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async get(url, headers) {
|
|
51
|
+
return this.request(url, { method: 'GET', headers });
|
|
52
|
+
}
|
|
53
|
+
async post(url, data, headers) {
|
|
54
|
+
return this.request(url, {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
57
|
+
headers,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async put(url, data, headers) {
|
|
61
|
+
return this.request(url, {
|
|
62
|
+
method: 'PUT',
|
|
63
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
64
|
+
headers,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async delete(url, headers) {
|
|
68
|
+
return this.request(url, { method: 'DELETE', headers });
|
|
69
|
+
}
|
|
70
|
+
async patch(url, data, headers) {
|
|
71
|
+
return this.request(url, {
|
|
72
|
+
method: 'PATCH',
|
|
73
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
74
|
+
headers,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const httpClient = new HttpClient();
|
|
79
|
+
/**
|
|
80
|
+
* Authentication API calls
|
|
81
|
+
*/
|
|
82
|
+
export class AuthApi {
|
|
83
|
+
static async checkApiKey(apiKey) {
|
|
84
|
+
return httpClient.get(`${BASE_URLS.LOCAL}/admin`, {
|
|
85
|
+
Authorization: `Bearer ${apiKey}`,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
static async sendOtp(email) {
|
|
89
|
+
return httpClient.post(`${BASE_URLS.AUTH}/otp`, { email });
|
|
90
|
+
}
|
|
91
|
+
static async verifyOtp(email, otp) {
|
|
92
|
+
return httpClient.post(`${BASE_URLS.AUTH}/otp/verify`, { email, otp });
|
|
93
|
+
}
|
|
94
|
+
static async getApiKey(signInToken) {
|
|
95
|
+
return httpClient.post(`${BASE_URLS.AUTH}/profile/apiKey`, undefined, {
|
|
96
|
+
Authorization: `Bearer ${signInToken}`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Agent API calls
|
|
102
|
+
*/
|
|
103
|
+
export class AgentApi {
|
|
104
|
+
static async getOrganizations(apiKey) {
|
|
105
|
+
return httpClient.get(`${BASE_URLS.LOCAL}/admin`, {
|
|
106
|
+
Authorization: `Bearer ${apiKey}`,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
static async getAgentTypes(apiKey) {
|
|
110
|
+
return httpClient.get(`${BASE_URLS.API}/agents/self-serve/types`, {
|
|
111
|
+
Authorization: `Bearer ${apiKey}`,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
static async createAgent(apiKey, agentData) {
|
|
115
|
+
return httpClient.post(`${BASE_URLS.API}/agents/self-serve/create`, agentData, {
|
|
116
|
+
Authorization: `Bearer ${apiKey}`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
static async getAgent(apiKey, agentId) {
|
|
120
|
+
return httpClient.get(`${BASE_URLS.API}/admin/agents/${agentId}`, {
|
|
121
|
+
Authorization: `Bearer ${apiKey}`,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Skill API calls
|
|
127
|
+
*/
|
|
128
|
+
export class SkillApi {
|
|
129
|
+
static async createSkill(apiKey, agentId, skillData) {
|
|
130
|
+
return httpClient.post(`${BASE_URLS.LOCAL}/developer/skills/${agentId}`, skillData, {
|
|
131
|
+
Authorization: `Bearer ${apiKey}`,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
static async pushSkill(apiKey, agentId, skillId, versionData) {
|
|
135
|
+
return httpClient.post(`${BASE_URLS.LOCAL}/developer/skills/${agentId}/${skillId}/version`, versionData, {
|
|
136
|
+
Authorization: `Bearer ${apiKey}`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
static async pushDevSkill(apiKey, agentId, skillId, versionData) {
|
|
140
|
+
return httpClient.post(`${BASE_URLS.LOCAL}/developer/skills/${agentId}/${skillId}/version/sandbox`, versionData, {
|
|
141
|
+
Authorization: `Bearer ${apiKey}`,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
static async updateDevSkill(apiKey, agentId, skillId, sandboxVersionId, versionData) {
|
|
145
|
+
return httpClient.put(`${BASE_URLS.LOCAL}/developer/skills/${agentId}/${skillId}/version/sandbox/${sandboxVersionId}`, versionData, {
|
|
146
|
+
Authorization: `Bearer ${apiKey}`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
static async getSkillVersions(apiKey, agentId, skillId) {
|
|
150
|
+
return httpClient.get(`${BASE_URLS.LOCAL}/developer/skills/${agentId}/${skillId}/versions`, {
|
|
151
|
+
Authorization: `Bearer ${apiKey}`,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
static async publishSkillVersion(apiKey, agentId, skillId, version) {
|
|
155
|
+
return httpClient.put(`${BASE_URLS.LOCAL}/developer/skills/${agentId}/${skillId}/${version}/publish`, undefined, {
|
|
156
|
+
Authorization: `Bearer ${apiKey}`,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Chat API calls
|
|
162
|
+
*/
|
|
163
|
+
export class ChatApi {
|
|
164
|
+
static async sendMessage(agentId, chatData, apiKey) {
|
|
165
|
+
return httpClient.post(`${BASE_URLS.CHAT}/chat/generate/${agentId}?channel=dev`, chatData, {
|
|
166
|
+
Authorization: `Bearer ${apiKey}`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Tool API calls (for compile command)
|
|
172
|
+
*/
|
|
173
|
+
export class ToolApi {
|
|
174
|
+
static async getTool(url, apiKey) {
|
|
175
|
+
return httpClient.get(url, {
|
|
176
|
+
Authorization: `Bearer ${apiKey}`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
static async postTool(url, data, apiKey) {
|
|
180
|
+
return httpClient.post(url, data, {
|
|
181
|
+
Authorization: `Bearer ${apiKey}`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
static async putTool(url, data, apiKey) {
|
|
185
|
+
return httpClient.put(url, data, {
|
|
186
|
+
Authorization: `Bearer ${apiKey}`,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
static async deleteTool(url, apiKey) {
|
|
190
|
+
return httpClient.delete(url, {
|
|
191
|
+
Authorization: `Bearer ${apiKey}`,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
static async patchTool(url, data, apiKey) {
|
|
195
|
+
return httpClient.patch(url, data, {
|
|
196
|
+
Authorization: `Bearer ${apiKey}`,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Main API service that exports all API classes
|
|
202
|
+
*/
|
|
203
|
+
export const ApiService = {
|
|
204
|
+
Auth: AuthApi,
|
|
205
|
+
Agent: AgentApi,
|
|
206
|
+
Skill: SkillApi,
|
|
207
|
+
Chat: ChatApi,
|
|
208
|
+
Tool: ToolApi,
|
|
209
|
+
};
|
package/dist/services/auth.d.ts
CHANGED
|
@@ -26,3 +26,85 @@ export interface CreateSkillResponse {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
export declare function createSkill(apiKey: string, agentId: string, skillName: string): Promise<CreateSkillResponse>;
|
|
29
|
+
export interface AgentType {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
features: Record<string, any>;
|
|
33
|
+
requiredSubAgentMetadata?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface CreateAgentRequest {
|
|
36
|
+
id: string;
|
|
37
|
+
type: string;
|
|
38
|
+
metadata: Record<string, any>;
|
|
39
|
+
persona: {
|
|
40
|
+
agentName: string;
|
|
41
|
+
businessType: string;
|
|
42
|
+
brandPersonality: string;
|
|
43
|
+
brandTraits: string;
|
|
44
|
+
};
|
|
45
|
+
features: Record<string, boolean>;
|
|
46
|
+
channels: any[];
|
|
47
|
+
org: {
|
|
48
|
+
registeredName: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface CreateAgentResponse {
|
|
52
|
+
success: boolean;
|
|
53
|
+
data?: {
|
|
54
|
+
agentId: string;
|
|
55
|
+
name: string;
|
|
56
|
+
baseAgentId: string;
|
|
57
|
+
persona: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
welcomeMessage: string;
|
|
60
|
+
featuresOverride: Record<string, any>;
|
|
61
|
+
_id: string;
|
|
62
|
+
updatedAt: string;
|
|
63
|
+
__v: number;
|
|
64
|
+
org: {
|
|
65
|
+
registeredName: string;
|
|
66
|
+
type: string;
|
|
67
|
+
agents: string[];
|
|
68
|
+
paymentMethods: any[];
|
|
69
|
+
_id: string;
|
|
70
|
+
id: string;
|
|
71
|
+
createdAt: number;
|
|
72
|
+
__v: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
error?: {
|
|
76
|
+
message: string;
|
|
77
|
+
error: string;
|
|
78
|
+
statusCode: number;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export interface AgentDetailsResponse {
|
|
82
|
+
success: boolean;
|
|
83
|
+
data?: {
|
|
84
|
+
_id: string;
|
|
85
|
+
agentId: string;
|
|
86
|
+
name: string;
|
|
87
|
+
baseAgentId: string;
|
|
88
|
+
persona: string;
|
|
89
|
+
createdAt: string;
|
|
90
|
+
welcomeMessage: string;
|
|
91
|
+
featuresOverride: Record<string, any>;
|
|
92
|
+
updatedAt: string;
|
|
93
|
+
__v: number;
|
|
94
|
+
personaConfig: {
|
|
95
|
+
agentName: string;
|
|
96
|
+
businessType: string;
|
|
97
|
+
brandPersonality: string;
|
|
98
|
+
brandTraits: string;
|
|
99
|
+
};
|
|
100
|
+
skills: any[];
|
|
101
|
+
};
|
|
102
|
+
error?: {
|
|
103
|
+
message: string;
|
|
104
|
+
error: string;
|
|
105
|
+
statusCode: number;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export declare function getAgentTypes(apiKey: string): Promise<AgentType[]>;
|
|
109
|
+
export declare function createAgent(apiKey: string, agentData: CreateAgentRequest): Promise<CreateAgentResponse>;
|
|
110
|
+
export declare function getAgentDetails(apiKey: string, agentId: string): Promise<AgentDetailsResponse>;
|
package/dist/services/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import keytar from "keytar";
|
|
2
|
-
import
|
|
2
|
+
import { ApiService } from "./api.js";
|
|
3
3
|
const SERVICE = "lua-cli";
|
|
4
4
|
const ACCOUNT = "api-key";
|
|
5
5
|
export async function saveApiKey(apiKey) {
|
|
@@ -12,31 +12,17 @@ export async function deleteApiKey() {
|
|
|
12
12
|
return keytar.deletePassword(SERVICE, ACCOUNT);
|
|
13
13
|
}
|
|
14
14
|
export async function checkApiKey(apiKey) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
Authorization: `Bearer ${apiKey}`,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
if (!response.ok) {
|
|
15
|
+
const result = await ApiService.Auth.checkApiKey(apiKey);
|
|
16
|
+
if (!result.success) {
|
|
21
17
|
console.error(`❌ Invalid API key`);
|
|
22
18
|
process.exit(1);
|
|
23
19
|
}
|
|
24
|
-
return
|
|
20
|
+
return result.data;
|
|
25
21
|
}
|
|
26
22
|
export async function requestEmailOTP(email) {
|
|
27
23
|
try {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
headers: {
|
|
31
|
-
"accept": "application/json",
|
|
32
|
-
"Content-Type": "application/json"
|
|
33
|
-
},
|
|
34
|
-
body: JSON.stringify({
|
|
35
|
-
type: "email",
|
|
36
|
-
email: email
|
|
37
|
-
})
|
|
38
|
-
});
|
|
39
|
-
return response.ok;
|
|
24
|
+
const result = await ApiService.Auth.sendOtp(email);
|
|
25
|
+
return result.success;
|
|
40
26
|
}
|
|
41
27
|
catch (error) {
|
|
42
28
|
console.error("❌ Error requesting OTP:", error);
|
|
@@ -45,23 +31,8 @@ export async function requestEmailOTP(email) {
|
|
|
45
31
|
}
|
|
46
32
|
export async function verifyOTPAndGetToken(email, pin) {
|
|
47
33
|
try {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
headers: {
|
|
51
|
-
"accept": "application/json",
|
|
52
|
-
"Content-Type": "application/json"
|
|
53
|
-
},
|
|
54
|
-
body: JSON.stringify({
|
|
55
|
-
pin: pin,
|
|
56
|
-
type: "email",
|
|
57
|
-
email: email
|
|
58
|
-
})
|
|
59
|
-
});
|
|
60
|
-
if (!response.ok) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
const data = await response.json();
|
|
64
|
-
return data.signInToken;
|
|
34
|
+
const result = await ApiService.Auth.verifyOtp(email, pin);
|
|
35
|
+
return result.success ? result.data.signInToken : null;
|
|
65
36
|
}
|
|
66
37
|
catch (error) {
|
|
67
38
|
console.error("❌ Error verifying OTP:", error);
|
|
@@ -70,19 +41,8 @@ export async function verifyOTPAndGetToken(email, pin) {
|
|
|
70
41
|
}
|
|
71
42
|
export async function generateApiKey(signInToken) {
|
|
72
43
|
try {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
headers: {
|
|
76
|
-
"Authorization": `Bearer ${signInToken}`,
|
|
77
|
-
"Content-Type": "application/json"
|
|
78
|
-
},
|
|
79
|
-
body: ""
|
|
80
|
-
});
|
|
81
|
-
if (!response.ok) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
const data = await response.json();
|
|
85
|
-
return data.apiKey;
|
|
44
|
+
const result = await ApiService.Auth.getApiKey(signInToken);
|
|
45
|
+
return result.success ? result.data.apiKey : null;
|
|
86
46
|
}
|
|
87
47
|
catch (error) {
|
|
88
48
|
console.error("❌ Error generating API key:", error);
|
|
@@ -91,7 +51,7 @@ export async function generateApiKey(signInToken) {
|
|
|
91
51
|
}
|
|
92
52
|
export async function createSkill(apiKey, agentId, skillName) {
|
|
93
53
|
try {
|
|
94
|
-
const response = await fetch(`
|
|
54
|
+
const response = await fetch(`http://localhost:3022/developer/skills/${agentId}`, {
|
|
95
55
|
method: "POST",
|
|
96
56
|
headers: {
|
|
97
57
|
"accept": "application/json",
|
|
@@ -128,3 +88,93 @@ export async function createSkill(apiKey, agentId, skillName) {
|
|
|
128
88
|
};
|
|
129
89
|
}
|
|
130
90
|
}
|
|
91
|
+
export async function getAgentTypes(apiKey) {
|
|
92
|
+
try {
|
|
93
|
+
const response = await fetch('https://api.lua.dev/agents/self-serve/types', {
|
|
94
|
+
method: 'GET',
|
|
95
|
+
headers: {
|
|
96
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
97
|
+
'Content-Type': 'application/json'
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
102
|
+
}
|
|
103
|
+
return await response.json();
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error('❌ Error fetching agent types:', error);
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function createAgent(apiKey, agentData) {
|
|
111
|
+
try {
|
|
112
|
+
const response = await fetch('https://api.lua.dev/agents/self-serve/create', {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: {
|
|
115
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
116
|
+
'Content-Type': 'application/json'
|
|
117
|
+
},
|
|
118
|
+
body: JSON.stringify(agentData)
|
|
119
|
+
});
|
|
120
|
+
const data = await response.json();
|
|
121
|
+
if (response.ok) {
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
data: data
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
error: data
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error('❌ Error creating agent:', error);
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
error: {
|
|
139
|
+
message: 'Network error',
|
|
140
|
+
error: 'Failed to connect to server',
|
|
141
|
+
statusCode: 500
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export async function getAgentDetails(apiKey, agentId) {
|
|
147
|
+
try {
|
|
148
|
+
const response = await fetch(`https://api.lua.dev/admin/agents/${agentId}`, {
|
|
149
|
+
method: 'GET',
|
|
150
|
+
headers: {
|
|
151
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
152
|
+
'Content-Type': 'application/json'
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const data = await response.json();
|
|
156
|
+
if (response.ok) {
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
data: data
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return {
|
|
164
|
+
success: false,
|
|
165
|
+
error: data
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.error('❌ Error fetching agent details:', error);
|
|
171
|
+
return {
|
|
172
|
+
success: false,
|
|
173
|
+
error: {
|
|
174
|
+
message: 'Network error',
|
|
175
|
+
error: 'Failed to connect to server',
|
|
176
|
+
statusCode: 500
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Data API for Lua CLI projects
|
|
3
|
+
* Provides methods to interact with user data stored in the Lua system
|
|
4
|
+
*/
|
|
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>;
|
|
14
|
+
/**
|
|
15
|
+
* Get user data for the current agent
|
|
16
|
+
* @returns Promise<UserDataResponse>
|
|
17
|
+
*/
|
|
18
|
+
get(): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Create or update user data for the current agent
|
|
21
|
+
* @param data - The user data to store
|
|
22
|
+
* @returns Promise<UserDataResponse>
|
|
23
|
+
*/
|
|
24
|
+
create(data: Record<string, any>): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Update existing user data for the current agent
|
|
27
|
+
* @param data - The user data to update
|
|
28
|
+
* @returns Promise<UserDataResponse>
|
|
29
|
+
*/
|
|
30
|
+
update(data: Record<string, any>): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Clear all user data for the current agent
|
|
33
|
+
* @returns Promise<{success: boolean}>
|
|
34
|
+
*/
|
|
35
|
+
clear(): Promise<{
|
|
36
|
+
success: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convenience object for user data operations
|
|
41
|
+
* Usage: user.data.get(), user.data.create(data), user.data.update(data), user.data.clear()
|
|
42
|
+
*/
|
|
43
|
+
export declare const user: {
|
|
44
|
+
data: UserDataAPI;
|
|
45
|
+
};
|
|
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;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { readSkillConfig } from './utils/files.js';
|
|
2
|
+
import { loadApiKey } from './services/auth.js';
|
|
3
|
+
/**
|
|
4
|
+
* User Data API for Lua CLI projects
|
|
5
|
+
* Provides methods to interact with user data stored in the Lua system
|
|
6
|
+
*/
|
|
7
|
+
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
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get user data for the current agent
|
|
30
|
+
* @returns Promise<UserDataResponse>
|
|
31
|
+
*/
|
|
32
|
+
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();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create or update user data for the current agent
|
|
61
|
+
* @param data - The user data to store
|
|
62
|
+
* @returns Promise<UserDataResponse>
|
|
63
|
+
*/
|
|
64
|
+
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();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Update existing user data for the current agent
|
|
97
|
+
* @param data - The user data to update
|
|
98
|
+
* @returns Promise<UserDataResponse>
|
|
99
|
+
*/
|
|
100
|
+
async update(data) {
|
|
101
|
+
// Update is the same as create for this API
|
|
102
|
+
return this.create(data);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Clear all user data for the current agent
|
|
106
|
+
* @returns Promise<{success: boolean}>
|
|
107
|
+
*/
|
|
108
|
+
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();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Convenience object for user data operations
|
|
138
|
+
* Usage: user.data.get(), user.data.create(data), user.data.update(data), user.data.clear()
|
|
139
|
+
*/
|
|
140
|
+
export const user = {
|
|
141
|
+
data: new UserDataAPI()
|
|
142
|
+
};
|
|
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/dist/utils/files.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export declare function copyTemplateFiles(templateDir: string, targetDir: string): void;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function createSkillYaml(agentId: string, orgId: string, skillName: string, skillId?: string, persona?: string, welcomeMessage?: string): void;
|
|
3
|
+
export declare function readSkillYaml(): any;
|
|
4
|
+
export declare function readSkillConfig(): any;
|
|
5
|
+
export declare function updateSkillYamlPersona(persona: string, welcomeMessage?: string): void;
|