lua-cli 1.1.4-beta.2 → 1.2.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 +32 -0
- package/README.md +183 -8
- package/dist/commands/deploy.js +69 -10
- package/dist/commands/test.js +62 -11
- package/dist/skill.d.ts +1 -2
- package/dist/skill.js +1 -2
- package/package.json +8 -3
- package/template/.lua/deploy.json +53 -3
- package/template/API.md +604 -0
- package/template/DEVELOPER.md +771 -0
- package/template/QUICKSTART.md +170 -0
- package/template/README.md +477 -0
- package/template/index.ts +40 -16
- package/template/services/GetWeather.ts +35 -3
- package/template/services/MathService.ts +61 -0
- package/template/tools/AdvancedMathTool.ts +82 -0
- package/template/tools/CalculatorTool.ts +65 -0
- package/template/tools/CreatePostTool.ts +15 -3
- package/template/tools/GetUserDataTool.ts +15 -3
- package/template/tools/GetWeatherTool.ts +18 -5
|
@@ -1,8 +1,40 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface WeatherData {
|
|
2
|
+
weather: string;
|
|
3
|
+
city: string;
|
|
4
|
+
temperature?: number;
|
|
5
|
+
humidity?: number;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default class GetWeatherService {
|
|
10
|
+
// Mock weather data - in a real app, this would call a weather API
|
|
11
|
+
weatherData: Record<string, WeatherData>;
|
|
12
|
+
|
|
2
13
|
constructor() {
|
|
14
|
+
this.weatherData = {
|
|
15
|
+
"london": { weather: "cloudy", city: "London", temperature: 15, humidity: 80, description: "Overcast with light rain" },
|
|
16
|
+
"paris": { weather: "sunny", city: "Paris", temperature: 22, humidity: 60, description: "Clear skies" },
|
|
17
|
+
"tokyo": { weather: "rainy", city: "Tokyo", temperature: 18, humidity: 85, description: "Heavy rainfall" },
|
|
18
|
+
"new york": { weather: "sunny", city: "New York", temperature: 25, humidity: 55, description: "Partly cloudy" },
|
|
19
|
+
"sydney": { weather: "sunny", city: "Sydney", temperature: 28, humidity: 45, description: "Clear and warm" }
|
|
20
|
+
};
|
|
3
21
|
}
|
|
4
22
|
|
|
5
|
-
async getWeather(city: string) {
|
|
6
|
-
|
|
23
|
+
async getWeather(city: string): Promise<WeatherData> {
|
|
24
|
+
const normalizedCity = city.toLowerCase().trim();
|
|
25
|
+
|
|
26
|
+
// Return cached data if available, otherwise return generic response
|
|
27
|
+
const weatherInfo = this.weatherData[normalizedCity] || {
|
|
28
|
+
weather: "unknown",
|
|
29
|
+
city: city,
|
|
30
|
+
temperature: 20,
|
|
31
|
+
humidity: 50,
|
|
32
|
+
description: "Weather data not available"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Simulate API delay
|
|
36
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
37
|
+
|
|
38
|
+
return weatherInfo;
|
|
7
39
|
}
|
|
8
40
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Example: Simple Math Service
|
|
2
|
+
export default class MathService {
|
|
3
|
+
/**
|
|
4
|
+
* Calculate the factorial of a number
|
|
5
|
+
*/
|
|
6
|
+
factorial(n: number): number {
|
|
7
|
+
if (n < 0) throw new Error("Factorial is not defined for negative numbers");
|
|
8
|
+
if (n === 0 || n === 1) return 1;
|
|
9
|
+
return n * this.factorial(n - 1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if a number is prime
|
|
14
|
+
*/
|
|
15
|
+
isPrime(n: number): boolean {
|
|
16
|
+
if (n < 2) return false;
|
|
17
|
+
if (n === 2) return true;
|
|
18
|
+
if (n % 2 === 0) return false;
|
|
19
|
+
|
|
20
|
+
for (let i = 3; i <= Math.sqrt(n); i += 2) {
|
|
21
|
+
if (n % i === 0) return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generate Fibonacci sequence up to n terms
|
|
29
|
+
*/
|
|
30
|
+
fibonacci(n: number): number[] {
|
|
31
|
+
if (n <= 0) return [];
|
|
32
|
+
if (n === 1) return [0];
|
|
33
|
+
if (n === 2) return [0, 1];
|
|
34
|
+
|
|
35
|
+
const sequence = [0, 1];
|
|
36
|
+
for (let i = 2; i < n; i++) {
|
|
37
|
+
sequence.push(sequence[i - 1] + sequence[i - 2]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return sequence;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Calculate the greatest common divisor
|
|
45
|
+
*/
|
|
46
|
+
gcd(a: number, b: number): number {
|
|
47
|
+
while (b !== 0) {
|
|
48
|
+
const temp = b;
|
|
49
|
+
b = a % b;
|
|
50
|
+
a = temp;
|
|
51
|
+
}
|
|
52
|
+
return Math.abs(a);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Calculate the least common multiple
|
|
57
|
+
*/
|
|
58
|
+
lcm(a: number, b: number): number {
|
|
59
|
+
return Math.abs(a * b) / this.gcd(a, b);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Example: Advanced Math Tool using MathService
|
|
2
|
+
import { LuaTool } from "lua-cli/skill";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import MathService from "../services/MathService";
|
|
5
|
+
|
|
6
|
+
// Define schemas as static properties for Lua CLI detection
|
|
7
|
+
const inputSchema = z.object({
|
|
8
|
+
operation: z.enum(["factorial", "is_prime", "fibonacci", "gcd", "lcm"]).describe("Mathematical operation"),
|
|
9
|
+
numbers: z.array(z.number()).describe("Numbers for the operation")
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const outputSchema = z.object({
|
|
13
|
+
result: z.any(),
|
|
14
|
+
operation: z.string(),
|
|
15
|
+
input: z.array(z.number())
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default class AdvancedMathTool implements LuaTool<typeof inputSchema, typeof outputSchema> {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
inputSchema: typeof inputSchema;
|
|
22
|
+
outputSchema: typeof outputSchema;
|
|
23
|
+
private mathService: MathService;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
this.name = "advanced_math";
|
|
27
|
+
this.description = "Perform advanced mathematical operations";
|
|
28
|
+
this.inputSchema = inputSchema;
|
|
29
|
+
this.outputSchema = outputSchema;
|
|
30
|
+
this.mathService = new MathService();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async execute(input) {
|
|
34
|
+
let result: any;
|
|
35
|
+
|
|
36
|
+
switch (input.operation) {
|
|
37
|
+
case "factorial":
|
|
38
|
+
if (input.numbers.length !== 1) {
|
|
39
|
+
throw new Error("Factorial requires exactly one number");
|
|
40
|
+
}
|
|
41
|
+
result = this.mathService.factorial(input.numbers[0]);
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case "is_prime":
|
|
45
|
+
if (input.numbers.length !== 1) {
|
|
46
|
+
throw new Error("Prime check requires exactly one number");
|
|
47
|
+
}
|
|
48
|
+
result = this.mathService.isPrime(input.numbers[0]);
|
|
49
|
+
break;
|
|
50
|
+
|
|
51
|
+
case "fibonacci":
|
|
52
|
+
if (input.numbers.length !== 1) {
|
|
53
|
+
throw new Error("Fibonacci requires exactly one number");
|
|
54
|
+
}
|
|
55
|
+
result = this.mathService.fibonacci(input.numbers[0]);
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case "gcd":
|
|
59
|
+
if (input.numbers.length !== 2) {
|
|
60
|
+
throw new Error("GCD requires exactly two numbers");
|
|
61
|
+
}
|
|
62
|
+
result = this.mathService.gcd(input.numbers[0], input.numbers[1]);
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
case "lcm":
|
|
66
|
+
if (input.numbers.length !== 2) {
|
|
67
|
+
throw new Error("LCM requires exactly two numbers");
|
|
68
|
+
}
|
|
69
|
+
result = this.mathService.lcm(input.numbers[0], input.numbers[1]);
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
default:
|
|
73
|
+
throw new Error(`Unknown operation: ${input.operation}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
result,
|
|
78
|
+
operation: input.operation,
|
|
79
|
+
input: input.numbers
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Example: Simple Calculator Tool
|
|
2
|
+
import { LuaTool } from "lua-cli/skill";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
// Define schemas as static properties for Lua CLI detection
|
|
6
|
+
const inputSchema = z.object({
|
|
7
|
+
operation: z.enum(["add", "subtract", "multiply", "divide"]).describe("Mathematical operation"),
|
|
8
|
+
a: z.number().describe("First number"),
|
|
9
|
+
b: z.number().describe("Second number")
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const outputSchema = z.object({
|
|
13
|
+
result: z.number(),
|
|
14
|
+
operation: z.string(),
|
|
15
|
+
expression: z.string()
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default class CalculatorTool implements LuaTool<typeof inputSchema, typeof outputSchema> {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
inputSchema: typeof inputSchema;
|
|
22
|
+
outputSchema: typeof outputSchema;
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
this.name = "calculator";
|
|
26
|
+
this.description = "Perform basic mathematical operations";
|
|
27
|
+
this.inputSchema = inputSchema;
|
|
28
|
+
this.outputSchema = outputSchema;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async execute(input) {
|
|
32
|
+
let result: number;
|
|
33
|
+
let expression: string;
|
|
34
|
+
|
|
35
|
+
switch (input.operation) {
|
|
36
|
+
case "add":
|
|
37
|
+
result = input.a + input.b;
|
|
38
|
+
expression = `${input.a} + ${input.b}`;
|
|
39
|
+
break;
|
|
40
|
+
case "subtract":
|
|
41
|
+
result = input.a - input.b;
|
|
42
|
+
expression = `${input.a} - ${input.b}`;
|
|
43
|
+
break;
|
|
44
|
+
case "multiply":
|
|
45
|
+
result = input.a * input.b;
|
|
46
|
+
expression = `${input.a} × ${input.b}`;
|
|
47
|
+
break;
|
|
48
|
+
case "divide":
|
|
49
|
+
if (input.b === 0) {
|
|
50
|
+
throw new Error("Division by zero is not allowed");
|
|
51
|
+
}
|
|
52
|
+
result = input.a / input.b;
|
|
53
|
+
expression = `${input.a} ÷ ${input.b}`;
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unknown operation: ${input.operation}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
result,
|
|
61
|
+
operation: input.operation,
|
|
62
|
+
expression
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -2,14 +2,26 @@ import { LuaTool } from "lua-cli/skill";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import ApiService from "../services/ApiService";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
// Define schemas as static properties for Lua CLI detection
|
|
6
|
+
const inputSchema = z.object({
|
|
7
|
+
title: z.string(),
|
|
8
|
+
content: z.string()
|
|
9
|
+
});
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
const outputSchema = z.object({
|
|
12
|
+
id: z.string().nullable(),
|
|
13
|
+
title: z.string(),
|
|
14
|
+
status: z.string(),
|
|
15
|
+
error: z.string().optional(),
|
|
16
|
+
url: z.string().nullable()
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default class CreatePostTool implements LuaTool<typeof inputSchema, typeof outputSchema> {
|
|
9
20
|
name: string;
|
|
10
21
|
description: string;
|
|
11
22
|
inputSchema: typeof inputSchema;
|
|
12
23
|
outputSchema: typeof outputSchema;
|
|
24
|
+
|
|
13
25
|
apiService: ApiService;
|
|
14
26
|
|
|
15
27
|
constructor() {
|
|
@@ -2,14 +2,26 @@ import { LuaTool } from "lua-cli/skill";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import ApiService from "../services/ApiService";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
// Define schemas as static properties for Lua CLI detection
|
|
6
|
+
const inputSchema = z.object({
|
|
7
|
+
userId: z.string()
|
|
8
|
+
});
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
const outputSchema = z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
name: z.string(),
|
|
13
|
+
url: z.string().nullable(),
|
|
14
|
+
status: z.string(),
|
|
15
|
+
error: z.string().optional(),
|
|
16
|
+
timestamp: z.string()
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default class GetUserDataTool implements LuaTool<typeof inputSchema, typeof outputSchema> {
|
|
9
20
|
name: string;
|
|
10
21
|
description: string;
|
|
11
22
|
inputSchema: typeof inputSchema;
|
|
12
23
|
outputSchema: typeof outputSchema;
|
|
24
|
+
|
|
13
25
|
apiService: ApiService;
|
|
14
26
|
|
|
15
27
|
constructor() {
|
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
import { LuaTool } from "lua-cli/skill";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import
|
|
3
|
+
import GetWeatherService from "../services/GetWeather";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
// Define schemas as static properties for Lua CLI detection
|
|
6
|
+
const inputSchema = z.object({
|
|
7
|
+
city: z.string()
|
|
8
|
+
});
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
const outputSchema = z.object({
|
|
11
|
+
weather: z.string(),
|
|
12
|
+
city: z.string(),
|
|
13
|
+
temperature: z.number().optional(),
|
|
14
|
+
humidity: z.number().optional(),
|
|
15
|
+
description: z.string().optional()
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default class GetWeatherTool implements LuaTool<typeof inputSchema, typeof outputSchema> {
|
|
9
19
|
name: string;
|
|
10
20
|
description: string;
|
|
11
21
|
inputSchema: typeof inputSchema;
|
|
12
22
|
outputSchema: typeof outputSchema;
|
|
23
|
+
|
|
24
|
+
weatherService: GetWeatherService;
|
|
13
25
|
|
|
14
26
|
constructor() {
|
|
15
27
|
this.name = "get_weather";
|
|
16
28
|
this.description = "Get the weather for a given city";
|
|
17
29
|
this.inputSchema = inputSchema;
|
|
18
30
|
this.outputSchema = outputSchema;
|
|
31
|
+
this.weatherService = new GetWeatherService();
|
|
19
32
|
}
|
|
20
33
|
|
|
21
34
|
async execute(input: z.infer<typeof inputSchema>) {
|
|
22
|
-
return
|
|
35
|
+
return this.weatherService.getWeather(input.city);
|
|
23
36
|
}
|
|
24
37
|
}
|