create-aixyz-app 0.1.2 → 0.2.4
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/package.json +1 -1
- package/templates/default/aixyz.config.ts +19 -9
- package/templates/default/app/agent.ts +13 -9
- package/templates/default/app/tools/length.ts +45 -0
- package/templates/default/app/tools/temperature.ts +39 -0
- package/templates/default/app/tools/weight.ts +33 -0
- package/templates/default/app/tools/weather.ts +0 -95
package/package.json
CHANGED
|
@@ -12,15 +12,25 @@ const config: AixyzConfig = {
|
|
|
12
12
|
},
|
|
13
13
|
skills: [
|
|
14
14
|
{
|
|
15
|
-
id: "
|
|
16
|
-
name: "
|
|
17
|
-
description: "
|
|
18
|
-
tags: ["
|
|
19
|
-
examples: [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
id: "convert-length",
|
|
16
|
+
name: "Convert Length",
|
|
17
|
+
description: "Convert length and distance values between metric and imperial units",
|
|
18
|
+
tags: ["length", "distance", "metric", "imperial"],
|
|
19
|
+
examples: ["Convert 100 meters to feet", "How many miles is 10 kilometers?", "Convert 6 feet to centimeters"],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "convert-weight",
|
|
23
|
+
name: "Convert Weight",
|
|
24
|
+
description: "Convert weight and mass values between metric and imperial units",
|
|
25
|
+
tags: ["weight", "mass", "metric", "imperial"],
|
|
26
|
+
examples: ["Convert 70 kilograms to pounds", "How many grams is 5 ounces?", "Convert 2 tons to pounds"],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "convert-temperature",
|
|
30
|
+
name: "Convert Temperature",
|
|
31
|
+
description: "Convert temperature values between Celsius, Fahrenheit, and Kelvin",
|
|
32
|
+
tags: ["temperature", "celsius", "fahrenheit", "kelvin"],
|
|
33
|
+
examples: ["Convert 100°C to Fahrenheit", "What is 72°F in Celsius?", "Convert 300 Kelvin to Celsius"],
|
|
24
34
|
},
|
|
25
35
|
],
|
|
26
36
|
};
|
|
@@ -2,30 +2,34 @@ import { openai } from "@ai-sdk/openai";
|
|
|
2
2
|
import { stepCountIs, ToolLoopAgent } from "ai";
|
|
3
3
|
import type { Accepts } from "aixyz/accepts";
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import convertLength from "./tools/length";
|
|
6
|
+
import convertTemperature from "./tools/temperature";
|
|
7
|
+
import convertWeight from "./tools/weight";
|
|
6
8
|
|
|
7
9
|
// language=Markdown
|
|
8
10
|
const instructions = `
|
|
9
|
-
#
|
|
11
|
+
# Unit Conversion Agent
|
|
10
12
|
|
|
11
|
-
You are a helpful
|
|
13
|
+
You are a helpful unit conversion assistant that accurately converts values between different measurement systems.
|
|
12
14
|
|
|
13
15
|
## Guidelines
|
|
14
16
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
17
|
+
- Use the appropriate tool based on the type of conversion requested.
|
|
18
|
+
- Use \`convertLength\` for distances and lengths (meters, feet, miles, km, etc.).
|
|
19
|
+
- Use \`convertWeight\` for mass and weight (kilograms, pounds, ounces, etc.).
|
|
20
|
+
- Use \`convertTemperature\` for temperature (Celsius, Fahrenheit, Kelvin).
|
|
21
|
+
- Always show both the original value with its unit and the converted result.
|
|
22
|
+
- If the unit type is ambiguous, ask the user to clarify.
|
|
19
23
|
`.trim();
|
|
20
24
|
|
|
21
25
|
export const accepts: Accepts = {
|
|
22
26
|
scheme: "exact",
|
|
23
|
-
price: "$0.
|
|
27
|
+
price: "$0.001",
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
export default new ToolLoopAgent({
|
|
27
31
|
model: openai("gpt-4o-mini"),
|
|
28
32
|
instructions: instructions,
|
|
29
|
-
tools: {
|
|
33
|
+
tools: { convertLength, convertWeight, convertTemperature },
|
|
30
34
|
stopWhen: stepCountIs(10),
|
|
31
35
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
const LENGTH_UNITS = [
|
|
5
|
+
"meter",
|
|
6
|
+
"kilometer",
|
|
7
|
+
"centimeter",
|
|
8
|
+
"millimeter",
|
|
9
|
+
"mile",
|
|
10
|
+
"yard",
|
|
11
|
+
"foot",
|
|
12
|
+
"inch",
|
|
13
|
+
"nautical_mile",
|
|
14
|
+
] as const;
|
|
15
|
+
type LengthUnit = (typeof LENGTH_UNITS)[number];
|
|
16
|
+
|
|
17
|
+
// All conversion factors relative to 1 meter
|
|
18
|
+
const TO_METERS: Record<LengthUnit, number> = {
|
|
19
|
+
meter: 1,
|
|
20
|
+
kilometer: 1000,
|
|
21
|
+
centimeter: 0.01,
|
|
22
|
+
millimeter: 0.001,
|
|
23
|
+
mile: 1609.344,
|
|
24
|
+
yard: 0.9144,
|
|
25
|
+
foot: 0.3048,
|
|
26
|
+
inch: 0.0254,
|
|
27
|
+
nautical_mile: 1852,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default tool({
|
|
31
|
+
description: "Convert a length or distance value between different units (metric and imperial).",
|
|
32
|
+
inputSchema: z.object({
|
|
33
|
+
value: z.number().describe("The numeric value to convert"),
|
|
34
|
+
from: z.enum(LENGTH_UNITS).describe("The unit to convert from"),
|
|
35
|
+
to: z.enum(LENGTH_UNITS).describe("The unit to convert to"),
|
|
36
|
+
}),
|
|
37
|
+
execute: async ({ value, from, to }) => {
|
|
38
|
+
const meters = value * TO_METERS[from];
|
|
39
|
+
const result = meters / TO_METERS[to];
|
|
40
|
+
return {
|
|
41
|
+
input: { value, unit: from },
|
|
42
|
+
output: { value: parseFloat(result.toPrecision(10)), unit: to },
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
const TEMPERATURE_UNITS = ["celsius", "fahrenheit", "kelvin"] as const;
|
|
5
|
+
|
|
6
|
+
export default tool({
|
|
7
|
+
description: "Convert a temperature value between Celsius, Fahrenheit, and Kelvin.",
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
value: z.number().describe("The numeric temperature value to convert"),
|
|
10
|
+
from: z.enum(TEMPERATURE_UNITS).describe("The unit to convert from"),
|
|
11
|
+
to: z.enum(TEMPERATURE_UNITS).describe("The unit to convert to"),
|
|
12
|
+
}),
|
|
13
|
+
execute: async ({ value, from, to }) => {
|
|
14
|
+
// First convert to Celsius as intermediate
|
|
15
|
+
let celsius: number;
|
|
16
|
+
if (from === "celsius") {
|
|
17
|
+
celsius = value;
|
|
18
|
+
} else if (from === "fahrenheit") {
|
|
19
|
+
celsius = (value - 32) * (5 / 9);
|
|
20
|
+
} else {
|
|
21
|
+
celsius = value - 273.15;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Then convert from Celsius to target unit
|
|
25
|
+
let result: number;
|
|
26
|
+
if (to === "celsius") {
|
|
27
|
+
result = celsius;
|
|
28
|
+
} else if (to === "fahrenheit") {
|
|
29
|
+
result = celsius * (9 / 5) + 32;
|
|
30
|
+
} else {
|
|
31
|
+
result = celsius + 273.15;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
input: { value, unit: from },
|
|
36
|
+
output: { value: parseFloat(result.toPrecision(10)), unit: to },
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
const WEIGHT_UNITS = ["kilogram", "gram", "milligram", "pound", "ounce", "ton", "stone"] as const;
|
|
5
|
+
type WeightUnit = (typeof WEIGHT_UNITS)[number];
|
|
6
|
+
|
|
7
|
+
// All conversion factors relative to 1 kilogram
|
|
8
|
+
const TO_KILOGRAMS: Record<WeightUnit, number> = {
|
|
9
|
+
kilogram: 1,
|
|
10
|
+
gram: 0.001,
|
|
11
|
+
milligram: 0.000001,
|
|
12
|
+
pound: 0.45359237,
|
|
13
|
+
ounce: 0.028349523125,
|
|
14
|
+
ton: 1000,
|
|
15
|
+
stone: 6.35029318,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default tool({
|
|
19
|
+
description: "Convert a weight or mass value between different units (metric and imperial).",
|
|
20
|
+
inputSchema: z.object({
|
|
21
|
+
value: z.number().describe("The numeric value to convert"),
|
|
22
|
+
from: z.enum(WEIGHT_UNITS).describe("The unit to convert from"),
|
|
23
|
+
to: z.enum(WEIGHT_UNITS).describe("The unit to convert to"),
|
|
24
|
+
}),
|
|
25
|
+
execute: async ({ value, from, to }) => {
|
|
26
|
+
const kg = value * TO_KILOGRAMS[from];
|
|
27
|
+
const result = kg / TO_KILOGRAMS[to];
|
|
28
|
+
return {
|
|
29
|
+
input: { value, unit: from },
|
|
30
|
+
output: { value: parseFloat(result.toPrecision(10)), unit: to },
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { tool } from "ai";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { Accepts } from "aixyz/accepts";
|
|
4
|
-
|
|
5
|
-
interface GeocodingResponse {
|
|
6
|
-
results?: {
|
|
7
|
-
latitude: number;
|
|
8
|
-
longitude: number;
|
|
9
|
-
name: string;
|
|
10
|
-
}[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface WeatherResponse {
|
|
14
|
-
current: {
|
|
15
|
-
time: string;
|
|
16
|
-
temperature_2m: number;
|
|
17
|
-
apparent_temperature: number;
|
|
18
|
-
relative_humidity_2m: number;
|
|
19
|
-
wind_speed_10m: number;
|
|
20
|
-
wind_gusts_10m: number;
|
|
21
|
-
weather_code: number;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getWeatherCondition(code: number): string {
|
|
26
|
-
const conditions: Record<number, string> = {
|
|
27
|
-
0: "Clear sky",
|
|
28
|
-
1: "Mainly clear",
|
|
29
|
-
2: "Partly cloudy",
|
|
30
|
-
3: "Overcast",
|
|
31
|
-
45: "Foggy",
|
|
32
|
-
48: "Depositing rime fog",
|
|
33
|
-
51: "Light drizzle",
|
|
34
|
-
53: "Moderate drizzle",
|
|
35
|
-
55: "Dense drizzle",
|
|
36
|
-
56: "Light freezing drizzle",
|
|
37
|
-
57: "Dense freezing drizzle",
|
|
38
|
-
61: "Slight rain",
|
|
39
|
-
63: "Moderate rain",
|
|
40
|
-
65: "Heavy rain",
|
|
41
|
-
66: "Light freezing rain",
|
|
42
|
-
67: "Heavy freezing rain",
|
|
43
|
-
71: "Slight snow fall",
|
|
44
|
-
73: "Moderate snow fall",
|
|
45
|
-
75: "Heavy snow fall",
|
|
46
|
-
77: "Snow grains",
|
|
47
|
-
80: "Slight rain showers",
|
|
48
|
-
81: "Moderate rain showers",
|
|
49
|
-
82: "Violent rain showers",
|
|
50
|
-
85: "Slight snow showers",
|
|
51
|
-
86: "Heavy snow showers",
|
|
52
|
-
95: "Thunderstorm",
|
|
53
|
-
96: "Thunderstorm with slight hail",
|
|
54
|
-
99: "Thunderstorm with heavy hail",
|
|
55
|
-
};
|
|
56
|
-
return conditions[code] ?? "Unknown";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const accepts: Accepts = {
|
|
60
|
-
scheme: "exact",
|
|
61
|
-
price: "$0.0001",
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export default tool({
|
|
65
|
-
description: "Get current weather conditions for a city or location.",
|
|
66
|
-
inputSchema: z.object({
|
|
67
|
-
location: z.string().describe("City name (e.g. 'Tokyo', 'New York', 'London')"),
|
|
68
|
-
}),
|
|
69
|
-
execute: async ({ location }) => {
|
|
70
|
-
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
71
|
-
const geocodingResponse = await fetch(geocodingUrl);
|
|
72
|
-
const geocodingData = (await geocodingResponse.json()) as GeocodingResponse;
|
|
73
|
-
|
|
74
|
-
if (!geocodingData.results?.[0]) {
|
|
75
|
-
throw new Error(`Location '${location}' not found`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const { latitude, longitude, name } = geocodingData.results[0];
|
|
79
|
-
|
|
80
|
-
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
|
|
81
|
-
const response = await fetch(weatherUrl);
|
|
82
|
-
const data = (await response.json()) as WeatherResponse;
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
location: name,
|
|
86
|
-
temperature: data.current.temperature_2m,
|
|
87
|
-
feelsLike: data.current.apparent_temperature,
|
|
88
|
-
humidity: data.current.relative_humidity_2m,
|
|
89
|
-
windSpeed: data.current.wind_speed_10m,
|
|
90
|
-
windGust: data.current.wind_gusts_10m,
|
|
91
|
-
conditions: getWeatherCondition(data.current.weather_code),
|
|
92
|
-
time: data.current.time,
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
});
|