lua-cli 1.2.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 +50 -0
- package/README.md +244 -63
- package/dist/commands/agents.js +17 -17
- package/dist/commands/apiKey.js +24 -19
- package/dist/commands/compile.d.ts +1 -0
- package/dist/commands/compile.js +1004 -0
- package/dist/commands/configure.js +93 -68
- package/dist/commands/deploy-new.d.ts +0 -0
- package/dist/commands/deploy-new.js +130 -0
- package/dist/commands/deploy.d.ts +19 -0
- package/dist/commands/deploy.js +81 -763
- package/dist/commands/destroy.js +26 -21
- package/dist/commands/dev.d.ts +63 -0
- package/dist/commands/dev.js +656 -0
- package/dist/commands/index.d.ts +4 -2
- package/dist/commands/index.js +4 -2
- package/dist/commands/init.js +297 -62
- package/dist/commands/push.d.ts +22 -0
- package/dist/commands/push.js +127 -0
- package/dist/commands/test.js +14 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +35 -19
- package/dist/services/api.d.ts +195 -0
- package/dist/services/api.js +209 -0
- package/dist/services/auth.d.ts +102 -0
- package/dist/services/auth.js +129 -40
- package/dist/skill.d.ts +22 -1
- package/dist/skill.js +21 -1
- package/dist/types/index.d.ts +16 -2
- package/dist/types/index.js +16 -1
- package/dist/user-data-api.d.ts +52 -0
- package/dist/user-data-api.js +151 -0
- package/dist/utils/cli.d.ts +34 -0
- package/dist/utils/cli.js +58 -0
- package/dist/utils/files.d.ts +4 -1
- package/dist/utils/files.js +61 -14
- 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 +18 -5
- package/template/package-lock.json +32 -3
- package/template/package.json +3 -1
- package/template/{index.ts → src/index.ts} +13 -4
- 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 -145
- /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
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,47 +31,150 @@ export async function requestEmailOTP(email) {
|
|
|
45
31
|
}
|
|
46
32
|
export async function verifyOTPAndGetToken(email, pin) {
|
|
47
33
|
try {
|
|
48
|
-
const
|
|
34
|
+
const result = await ApiService.Auth.verifyOtp(email, pin);
|
|
35
|
+
return result.success ? result.data.signInToken : null;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error("❌ Error verifying OTP:", error);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export async function generateApiKey(signInToken) {
|
|
43
|
+
try {
|
|
44
|
+
const result = await ApiService.Auth.getApiKey(signInToken);
|
|
45
|
+
return result.success ? result.data.apiKey : null;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error("❌ Error generating API key:", error);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function createSkill(apiKey, agentId, skillName) {
|
|
53
|
+
try {
|
|
54
|
+
const response = await fetch(`http://localhost:3022/developer/skills/${agentId}`, {
|
|
49
55
|
method: "POST",
|
|
50
56
|
headers: {
|
|
51
57
|
"accept": "application/json",
|
|
58
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
52
59
|
"Content-Type": "application/json"
|
|
53
60
|
},
|
|
54
61
|
body: JSON.stringify({
|
|
55
|
-
|
|
56
|
-
type: "email",
|
|
57
|
-
email: email
|
|
62
|
+
name: skillName
|
|
58
63
|
})
|
|
59
64
|
});
|
|
65
|
+
const data = await response.json();
|
|
66
|
+
if (response.ok) {
|
|
67
|
+
return {
|
|
68
|
+
success: true,
|
|
69
|
+
data: data
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: data
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error("❌ Error creating skill:", error);
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: {
|
|
84
|
+
message: "Network error",
|
|
85
|
+
error: "Failed to connect to server",
|
|
86
|
+
statusCode: 500
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
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
|
+
});
|
|
60
100
|
if (!response.ok) {
|
|
61
|
-
|
|
101
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
62
102
|
}
|
|
63
|
-
|
|
64
|
-
return data.signInToken;
|
|
103
|
+
return await response.json();
|
|
65
104
|
}
|
|
66
105
|
catch (error) {
|
|
67
|
-
console.error(
|
|
68
|
-
|
|
106
|
+
console.error('❌ Error fetching agent types:', error);
|
|
107
|
+
throw error;
|
|
69
108
|
}
|
|
70
109
|
}
|
|
71
|
-
export async function
|
|
110
|
+
export async function createAgent(apiKey, agentData) {
|
|
72
111
|
try {
|
|
73
|
-
const response = await fetch(
|
|
74
|
-
method:
|
|
112
|
+
const response = await fetch('https://api.lua.dev/agents/self-serve/create', {
|
|
113
|
+
method: 'POST',
|
|
75
114
|
headers: {
|
|
76
|
-
|
|
77
|
-
|
|
115
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
116
|
+
'Content-Type': 'application/json'
|
|
78
117
|
},
|
|
79
|
-
body:
|
|
118
|
+
body: JSON.stringify(agentData)
|
|
80
119
|
});
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
};
|
|
83
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
|
+
});
|
|
84
155
|
const data = await response.json();
|
|
85
|
-
|
|
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
|
+
}
|
|
86
168
|
}
|
|
87
169
|
catch (error) {
|
|
88
|
-
console.error(
|
|
89
|
-
return
|
|
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
|
+
};
|
|
90
179
|
}
|
|
91
180
|
}
|
package/dist/skill.d.ts
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { ZodType } from "zod";
|
|
2
2
|
import { LuaTool } from "./types/index.js";
|
|
3
3
|
export { LuaTool };
|
|
4
|
+
export interface LuaSkillConfig {
|
|
5
|
+
description: string;
|
|
6
|
+
context: string;
|
|
7
|
+
}
|
|
4
8
|
export declare class LuaSkill {
|
|
5
9
|
private readonly tools;
|
|
6
|
-
|
|
10
|
+
private readonly description;
|
|
11
|
+
private readonly context;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new LuaSkill instance
|
|
14
|
+
*
|
|
15
|
+
* @param config - Configuration object containing skill metadata
|
|
16
|
+
* @param config.description - Short description of what the skill does (1-2 sentences)
|
|
17
|
+
* @param config.context - Detailed explanation of how the agent should use the tools
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const skill = new LuaSkill({
|
|
22
|
+
* description: "Weather and calculator utilities",
|
|
23
|
+
* context: "This skill provides weather information for any city and basic mathematical operations. Use get_weather for current conditions and calculator for arithmetic operations."
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
constructor(config: LuaSkillConfig);
|
|
7
28
|
addTool<TInput extends ZodType, TOutput extends ZodType>(tool: LuaTool<TInput, TOutput>): void;
|
|
8
29
|
run(input: Record<string, any>): Promise<any>;
|
|
9
30
|
}
|
package/dist/skill.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
import { assertValidToolName } from "./types/index.js";
|
|
1
2
|
export class LuaSkill {
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new LuaSkill instance
|
|
5
|
+
*
|
|
6
|
+
* @param config - Configuration object containing skill metadata
|
|
7
|
+
* @param config.description - Short description of what the skill does (1-2 sentences)
|
|
8
|
+
* @param config.context - Detailed explanation of how the agent should use the tools
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const skill = new LuaSkill({
|
|
13
|
+
* description: "Weather and calculator utilities",
|
|
14
|
+
* context: "This skill provides weather information for any city and basic mathematical operations. Use get_weather for current conditions and calculator for arithmetic operations."
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
constructor(config) {
|
|
3
19
|
this.tools = [];
|
|
20
|
+
this.description = config.description;
|
|
21
|
+
this.context = config.context;
|
|
4
22
|
}
|
|
5
23
|
addTool(tool) {
|
|
24
|
+
// Validate the tool name before adding it
|
|
25
|
+
assertValidToolName(tool.name);
|
|
6
26
|
this.tools.push(tool);
|
|
7
27
|
}
|
|
8
28
|
async run(input) {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -53,6 +53,15 @@ export interface ApiKeyResponse {
|
|
|
53
53
|
apiId: string;
|
|
54
54
|
}
|
|
55
55
|
import { ZodType } from "zod";
|
|
56
|
+
/**
|
|
57
|
+
* Validates that a tool name contains only alphanumeric characters, hyphens, and underscores.
|
|
58
|
+
* No spaces or other special characters are allowed.
|
|
59
|
+
*/
|
|
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;
|
|
56
65
|
export interface LuaTool<TInput extends ZodType = ZodType, TOutput extends ZodType = ZodType> {
|
|
57
66
|
name: string;
|
|
58
67
|
description: string;
|
|
@@ -60,10 +69,15 @@ export interface LuaTool<TInput extends ZodType = ZodType, TOutput extends ZodTy
|
|
|
60
69
|
outputSchema: TOutput;
|
|
61
70
|
execute: (input: any) => Promise<any>;
|
|
62
71
|
}
|
|
72
|
+
export interface LuaSkillConfig {
|
|
73
|
+
description: string;
|
|
74
|
+
context: string;
|
|
75
|
+
}
|
|
63
76
|
export declare class LuaSkill {
|
|
64
|
-
private readonly apiKey;
|
|
65
77
|
private readonly tools;
|
|
66
|
-
|
|
78
|
+
private readonly description;
|
|
79
|
+
private readonly context;
|
|
80
|
+
constructor(config: LuaSkillConfig);
|
|
67
81
|
addTool<TInput extends ZodType, TOutput extends ZodType>(tool: LuaTool<TInput, TOutput>): void;
|
|
68
82
|
run(input: Record<string, any>): Promise<any>;
|
|
69
83
|
}
|
package/dist/types/index.js
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Validates that a tool name contains only alphanumeric characters, hyphens, and underscores.
|
|
3
|
+
* No spaces or other special characters are allowed.
|
|
4
|
+
*/
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized CLI utilities for consistent error handling and output management
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a command function with standardized error handling
|
|
6
|
+
* Handles SIGINT (Ctrl+C) gracefully and provides consistent error messages
|
|
7
|
+
*/
|
|
8
|
+
export declare function withErrorHandling<T>(commandFn: () => Promise<T>, commandName: string): Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Clears the specified number of lines from the terminal
|
|
11
|
+
* Used to clean up inquirer prompt output ONLY
|
|
12
|
+
* Should NOT be used to clear user input commands
|
|
13
|
+
*/
|
|
14
|
+
export declare function clearPromptLines(count?: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Writes a progress message that will be replaced by the next message
|
|
17
|
+
* Uses carriage return to overwrite the current line
|
|
18
|
+
*/
|
|
19
|
+
export declare function writeProgress(message: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Writes a final success message that will remain visible
|
|
22
|
+
* Uses console.log to ensure it stays in the output
|
|
23
|
+
*/
|
|
24
|
+
export declare function writeSuccess(message: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Writes an error message
|
|
27
|
+
* Uses console.error for proper error output
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeError(message: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Writes an info message
|
|
32
|
+
* Uses console.log for informational output
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeInfo(message: string): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized CLI utilities for consistent error handling and output management
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a command function with standardized error handling
|
|
6
|
+
* Handles SIGINT (Ctrl+C) gracefully and provides consistent error messages
|
|
7
|
+
*/
|
|
8
|
+
export async function withErrorHandling(commandFn, commandName) {
|
|
9
|
+
try {
|
|
10
|
+
return await commandFn();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (error.name === 'ExitPromptError') {
|
|
14
|
+
console.log("\n❌ Operation cancelled.");
|
|
15
|
+
process.exit(0);
|
|
16
|
+
}
|
|
17
|
+
console.error(`❌ Error during ${commandName}:`, error.message);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Clears the specified number of lines from the terminal
|
|
23
|
+
* Used to clean up inquirer prompt output ONLY
|
|
24
|
+
* Should NOT be used to clear user input commands
|
|
25
|
+
*/
|
|
26
|
+
export function clearPromptLines(count = 1) {
|
|
27
|
+
for (let i = 0; i < count; i++) {
|
|
28
|
+
process.stdout.write('\x1b[1A\x1b[2K'); // Move up 1 line and clear it
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Writes a progress message that will be replaced by the next message
|
|
33
|
+
* Uses carriage return to overwrite the current line
|
|
34
|
+
*/
|
|
35
|
+
export function writeProgress(message) {
|
|
36
|
+
process.stdout.write(`${message}\r`);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Writes a final success message that will remain visible
|
|
40
|
+
* Uses console.log to ensure it stays in the output
|
|
41
|
+
*/
|
|
42
|
+
export function writeSuccess(message) {
|
|
43
|
+
console.log(message);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Writes an error message
|
|
47
|
+
* Uses console.error for proper error output
|
|
48
|
+
*/
|
|
49
|
+
export function writeError(message) {
|
|
50
|
+
console.error(message);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Writes an info message
|
|
54
|
+
* Uses console.log for informational output
|
|
55
|
+
*/
|
|
56
|
+
export function writeInfo(message) {
|
|
57
|
+
console.log(message);
|
|
58
|
+
}
|
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;
|