lua-cli 1.3.2-alpha.0 → 1.3.2-alpha.3

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.
@@ -1,37 +1,53 @@
1
1
  import { LuaTool } from "lua-cli/skill";
2
2
  import { z } from "zod";
3
- import GetWeatherService from "../services/GetWeather";
4
3
 
5
- // Define schemas as static properties for Lua CLI detection
6
- const inputSchema = z.object({
7
- city: z.string()
8
- });
4
+ export default class GetWeatherTool implements LuaTool {
5
+ name = "get_weather";
6
+ description = "Get the weather for a given city";
7
+ inputSchema = z.object({
8
+ city: z.string()
9
+ });
10
+ 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
+ });
9
17
 
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
- });
18
+ async execute(input: z.infer<typeof this.inputSchema>) {
19
+ // Step 1: Geocode city → lat/lon (use Open-Meteo’s free geocoding API)
20
+ const geoUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(
21
+ input.city
22
+ )}&count=1`;
23
+
24
+ const geoRes = await fetch(geoUrl);
25
+ if (!geoRes.ok) {
26
+ throw new Error(`Failed to fetch location: ${geoRes.statusText}`);
27
+ }
28
+ const geoData = await geoRes.json();
29
+ if (!geoData.results || geoData.results.length === 0) {
30
+ throw new Error(`No location found for ${input.city}`);
31
+ }
17
32
 
18
- export default class GetWeatherTool implements LuaTool<typeof inputSchema, typeof outputSchema> {
19
- name: string;
20
- description: string;
21
- inputSchema: typeof inputSchema;
22
- outputSchema: typeof outputSchema;
23
-
24
- weatherService: GetWeatherService;
33
+ const { latitude, longitude, name } = geoData.results[0];
25
34
 
26
- constructor() {
27
- this.name = "get_weather";
28
- this.description = "Get the weather for a given city";
29
- this.inputSchema = inputSchema;
30
- this.outputSchema = outputSchema;
31
- this.weatherService = new GetWeatherService();
32
- }
35
+ // Step 2: Get weather for lat/lon
36
+ const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current_weather=true`;
37
+
38
+ const weatherRes = await fetch(weatherUrl);
39
+ if (!weatherRes.ok) {
40
+ throw new Error(`Failed to fetch weather: ${weatherRes.statusText}`);
41
+ }
42
+ const weatherData = await weatherRes.json();
43
+ const current = weatherData.current_weather;
33
44
 
34
- async execute(input: z.infer<typeof inputSchema>) {
35
- return this.weatherService.getWeather(input.city);
45
+ return {
46
+ weather: current.weathercode?.toString() || "Unknown",
47
+ city: name,
48
+ temperature: current.temperature,
49
+ humidity: undefined, // Open-Meteo current_weather does not include humidity
50
+ description: `Windspeed ${current.windspeed} km/h`
51
+ };
36
52
  }
37
- }
53
+ }
@@ -0,0 +1,52 @@
1
+ import { LuaTool, env } from "lua-cli/skill";
2
+ import { z } from "zod";
3
+
4
+ export default class CreatePaymentLinkTool implements LuaTool {
5
+ name = "create_payment_link";
6
+ description = "Create a Stripe payment link for a one-time payment";
7
+ inputSchema = z.object({
8
+ amount: z.number().int().positive(), // in cents
9
+ currency: z.string().default("usd"),
10
+ quantity: z.number().int().positive().default(1),
11
+ });
12
+ outputSchema = z.object({
13
+ url: z.string(),
14
+ id: z.string(),
15
+ });
16
+
17
+ async execute(input: z.infer<typeof this.inputSchema>) {
18
+ const apiKey = env("STRIPE_SECRET_KEY");
19
+ if (!apiKey) {
20
+ throw new Error("STRIPE_SECRET_KEY is not set in environment variables");
21
+ }
22
+
23
+ // Create a one-time Checkout Session with dummy redirect URLs
24
+ const sessionRes = await fetch("https://api.stripe.com/v1/checkout/sessions", {
25
+ method: "POST",
26
+ headers: {
27
+ Authorization: `Bearer ${apiKey}`,
28
+ "Content-Type": "application/x-www-form-urlencoded",
29
+ },
30
+ body: new URLSearchParams({
31
+ mode: "payment",
32
+ "line_items[0][price_data][currency]": input.currency,
33
+ "line_items[0][price_data][product_data][name]": "One-time Payment",
34
+ "line_items[0][price_data][unit_amount]": input.amount.toString(),
35
+ "line_items[0][quantity]": input.quantity.toString(),
36
+ success_url: "https://example.com/success",
37
+ cancel_url: "https://example.com/cancel",
38
+ }),
39
+ });
40
+
41
+ if (!sessionRes.ok) {
42
+ throw new Error(`Failed to create checkout session: ${await sessionRes.text()}`);
43
+ }
44
+
45
+ const session = await sessionRes.json();
46
+
47
+ return {
48
+ url: session.url,
49
+ id: session.id,
50
+ };
51
+ }
52
+ }
@@ -0,0 +1,43 @@
1
+ import { env, LuaTool } from "lua-cli/skill";
2
+ import { z } from "zod";
3
+ import { user } from 'lua-cli/user-data-api';
4
+ import { Pinecone, Index } from '@pinecone-database/pinecone';
5
+ import OpenAI from "openai";
6
+ export class SearchProductsTool implements LuaTool {
7
+ name = "search_products";
8
+ description = "Search for products";
9
+ inputSchema = z.object({
10
+ query: z.string()
11
+ });
12
+ pinecone: Pinecone;
13
+ openai: OpenAI;
14
+ index: Index;
15
+
16
+ constructor() {
17
+ const pinecone = new Pinecone({
18
+ apiKey: env('PINECONE_API_KEY') || ''
19
+ });
20
+ this.openai = new OpenAI({ apiKey: env('OPENAI_API_KEY') || '' });
21
+ this.pinecone = pinecone;
22
+ this.index = pinecone.Index('products-demo');
23
+ }
24
+
25
+ async embedText(text: string) {
26
+ const embeddingResponse = await this.openai.embeddings.create({
27
+ model: "text-embedding-3-small",
28
+ input: text,
29
+ });
30
+ return embeddingResponse.data[0].embedding;
31
+ }
32
+
33
+ async execute(input: z.infer<typeof this.inputSchema>) {
34
+ const queryVector = await this.embedText(input.query);
35
+ const results = await this.index.query({
36
+ vector: queryVector,
37
+ topK: 3,
38
+ includeMetadata: true,
39
+ });
40
+ console.log(results);
41
+ return results;
42
+ }
43
+ }
@@ -0,0 +1,56 @@
1
+ import { LuaTool } from "lua-cli/skill";
2
+ import { z } from "zod";
3
+ import { user } from 'lua-cli/user-data-api';
4
+
5
+
6
+ export class GetUserDataTool implements LuaTool {
7
+ name = "get_user_data";
8
+ description = "Get the user data for a given user id";
9
+ inputSchema = z.object({ });
10
+
11
+ constructor() {}
12
+
13
+ async execute(input: z.infer<typeof this.inputSchema>) {
14
+ return user.data.get();
15
+ }
16
+ }
17
+
18
+
19
+ export class CreateUserDataTool implements LuaTool {
20
+ name = "create_user_data";
21
+ description = "Get the user data for a given user id";
22
+ inputSchema = z.object({
23
+ data: z.object({
24
+ name: z.string(),
25
+ age: z.number()
26
+ })
27
+ });
28
+
29
+ constructor() {}
30
+
31
+ async execute(input: z.infer<typeof this.inputSchema>) {
32
+ console.log('createUserData tool', input);
33
+ const userData = await user.data.get();
34
+ if (userData.data) {
35
+ return user.data.update(input.data);
36
+ }
37
+ return user.data.create(input.data);
38
+ }
39
+ }
40
+
41
+ export class UpdateUserDataTool implements LuaTool {
42
+ name = "update_user_data";
43
+ description = "Update the user data for a given user id";
44
+ inputSchema = z.object({
45
+ data: z.object({
46
+ name: z.string().optional(),
47
+ age: z.number().optional()
48
+ })
49
+ });
50
+
51
+ constructor() {}
52
+
53
+ async execute(input: z.infer<typeof this.inputSchema>) {
54
+ return user.data.update(input.data);
55
+ }
56
+ }
@@ -1,61 +0,0 @@
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
- }
@@ -1,82 +0,0 @@
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: z.infer<typeof inputSchema>) {
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
- }
@@ -1,65 +0,0 @@
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: z.infer<typeof inputSchema>) {
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
- }
@@ -1,38 +0,0 @@
1
- import { LuaTool } from "lua-cli/skill";
2
- import { z } from "zod";
3
- import ApiService from "../services/ApiService";
4
-
5
- // Define schemas as static properties for Lua CLI detection
6
- const inputSchema = z.object({
7
- userId: z.string()
8
- });
9
-
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> {
20
- name: string;
21
- description: string;
22
- inputSchema: typeof inputSchema;
23
- outputSchema: typeof outputSchema;
24
-
25
- apiService: ApiService;
26
-
27
- constructor() {
28
- this.name = "get_user_data";
29
- this.description = "Get the user data for a given user id";
30
- this.inputSchema = inputSchema;
31
- this.outputSchema = outputSchema;
32
- this.apiService = new ApiService();
33
- }
34
-
35
- async execute(input: z.infer<typeof inputSchema>) {
36
- return this.apiService.fetchUserData(input.userId);
37
- }
38
- }
@@ -1,73 +0,0 @@
1
- import { LuaTool } from 'lua-cli/skill';
2
- import { user } from 'lua-cli/user-data-api';
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
- }