@dainprotocol/cli 1.1.12 → 1.1.14
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/dist/commands/build.js +17 -7
- package/dist/commands/deploy.js +15 -7
- package/dist/commands/status.js +3 -1
- package/dist/commands/testchat.js +17 -7
- package/dist/templates/default/package.json +1 -0
- package/dist/templates/default/src/index.ts +94 -16
- package/package.json +1 -1
- package/templates/default/package.json +1 -0
- package/templates/default/src/index.ts +94 -16
package/dist/commands/build.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
package/dist/commands/deploy.js
CHANGED
|
@@ -50,7 +50,7 @@ var status_1 = __importDefault(require("./status"));
|
|
|
50
50
|
var START_DEPLOY_URI = '/api/app/data/deployments/start-deploy';
|
|
51
51
|
function deploy(options) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
var config, spinner, basePath, deployPath, envArray, result, deploymentId, error_1;
|
|
53
|
+
var config, spinner, basePath, deployPath, envArray, result, deploymentId, dainJson, dainJsonObject, error_1;
|
|
54
54
|
return __generator(this, function (_a) {
|
|
55
55
|
switch (_a.label) {
|
|
56
56
|
case 0:
|
|
@@ -60,7 +60,7 @@ function deploy(options) {
|
|
|
60
60
|
deployPath = "".concat(basePath).concat(START_DEPLOY_URI);
|
|
61
61
|
_a.label = 1;
|
|
62
62
|
case 1:
|
|
63
|
-
_a.trys.push([1,
|
|
63
|
+
_a.trys.push([1, 9, , 10]);
|
|
64
64
|
return [4 /*yield*/, loadAndValidateEnvVariables()];
|
|
65
65
|
case 2:
|
|
66
66
|
envArray = _a.sent();
|
|
@@ -73,6 +73,14 @@ function deploy(options) {
|
|
|
73
73
|
deploymentId = result.deploymentId.replace('codegen-', '');
|
|
74
74
|
return [4 /*yield*/, recursiveStatusUntilRunning(JSON.stringify(config), deploymentId)];
|
|
75
75
|
case 5:
|
|
76
|
+
_a.sent();
|
|
77
|
+
return [4 /*yield*/, fs_extra_1.default.readFile('./dain.json', 'utf-8')];
|
|
78
|
+
case 6:
|
|
79
|
+
dainJson = _a.sent();
|
|
80
|
+
dainJsonObject = JSON.parse(dainJson);
|
|
81
|
+
dainJsonObject['deployment-id'] = deploymentId;
|
|
82
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile('./dain.json', JSON.stringify(dainJsonObject, null, 2))];
|
|
83
|
+
case 7:
|
|
76
84
|
_a.sent();
|
|
77
85
|
console.log('\n-----------------------');
|
|
78
86
|
spinner.succeed("Deployment URL: ".concat(result.service.url));
|
|
@@ -84,17 +92,17 @@ function deploy(options) {
|
|
|
84
92
|
return [4 /*yield*/, fetch(result.service.url, {
|
|
85
93
|
method: 'GET',
|
|
86
94
|
})];
|
|
87
|
-
case
|
|
95
|
+
case 8:
|
|
88
96
|
_a.sent();
|
|
89
97
|
process.exit(0);
|
|
90
|
-
return [3 /*break*/,
|
|
91
|
-
case
|
|
98
|
+
return [3 /*break*/, 10];
|
|
99
|
+
case 9:
|
|
92
100
|
error_1 = _a.sent();
|
|
93
101
|
spinner.fail('Deployment failed.');
|
|
94
102
|
(0, utils_1.logError)('Error during deployment: ', error_1);
|
|
95
103
|
process.exit(1);
|
|
96
|
-
return [3 /*break*/,
|
|
97
|
-
case
|
|
104
|
+
return [3 /*break*/, 10];
|
|
105
|
+
case 10: return [2 /*return*/];
|
|
98
106
|
}
|
|
99
107
|
});
|
|
100
108
|
});
|
package/dist/commands/status.js
CHANGED
|
@@ -85,7 +85,9 @@ function status(options, preDefinedDeploymentId) {
|
|
|
85
85
|
error_1 = _b.sent();
|
|
86
86
|
spinner.fail('Failed to retrieve project status.');
|
|
87
87
|
(0, utils_1.logError)('Error during status check', error_1);
|
|
88
|
-
|
|
88
|
+
if (!preDefinedDeploymentId) {
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
89
91
|
return [3 /*break*/, 5];
|
|
90
92
|
case 5: return [2 /*return*/];
|
|
91
93
|
}
|
|
@@ -26,13 +26,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
26
26
|
}) : function(o, v) {
|
|
27
27
|
o["default"] = v;
|
|
28
28
|
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
36
46
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
47
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
48
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -6,17 +6,26 @@ import axios from "axios";
|
|
|
6
6
|
import {
|
|
7
7
|
defineDAINService,
|
|
8
8
|
ToolConfig,
|
|
9
|
-
ServiceConfig,
|
|
10
|
-
ToolboxConfig,
|
|
11
|
-
ServiceContext,
|
|
12
9
|
} from "@dainprotocol/service-sdk";
|
|
13
10
|
|
|
11
|
+
import { CardUIBuilder, TableUIBuilder, MapUIBuilder } from "@dainprotocol/utils";
|
|
12
|
+
|
|
13
|
+
const getWeatherEmoji = (temperature: number): string => {
|
|
14
|
+
if (temperature <= 0) return '🥶';
|
|
15
|
+
if (temperature <= 10) return '❄️';
|
|
16
|
+
if (temperature <= 20) return '⛅';
|
|
17
|
+
if (temperature <= 25) return '☀️';
|
|
18
|
+
if (temperature <= 30) return '🌞';
|
|
19
|
+
return '🔥';
|
|
20
|
+
};
|
|
21
|
+
|
|
14
22
|
const getWeatherConfig: ToolConfig = {
|
|
15
23
|
id: "get-weather",
|
|
16
24
|
name: "Get Weather",
|
|
17
25
|
description: "Fetches current weather for a city",
|
|
18
26
|
input: z
|
|
19
27
|
.object({
|
|
28
|
+
locationName: z.string().describe("Location name"),
|
|
20
29
|
latitude: z.number().describe("Latitude coordinate"),
|
|
21
30
|
longitude: z.number().describe("Longitude coordinate"),
|
|
22
31
|
})
|
|
@@ -28,24 +37,43 @@ const getWeatherConfig: ToolConfig = {
|
|
|
28
37
|
})
|
|
29
38
|
.describe("Current weather information"),
|
|
30
39
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
31
|
-
handler: async ({ latitude, longitude }, agentInfo) => {
|
|
40
|
+
handler: async ({ locationName, latitude, longitude }, agentInfo, context) => {
|
|
32
41
|
console.log(
|
|
33
|
-
`User / Agent ${agentInfo.id} requested weather at ${latitude},${longitude}`
|
|
42
|
+
`User / Agent ${agentInfo.id} requested weather at ${locationName} (${latitude},${longitude})`
|
|
34
43
|
);
|
|
35
44
|
|
|
45
|
+
|
|
36
46
|
const response = await axios.get(
|
|
37
47
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,wind_speed_10m`
|
|
38
48
|
);
|
|
39
49
|
|
|
40
50
|
const { temperature_2m, wind_speed_10m } = response.data.current;
|
|
51
|
+
const weatherEmoji = getWeatherEmoji(temperature_2m);
|
|
41
52
|
|
|
42
53
|
return {
|
|
43
|
-
text: `The current temperature is ${temperature_2m}°C with wind speed of ${wind_speed_10m} km/h`,
|
|
54
|
+
text: `The current temperature in ${locationName} is ${temperature_2m}°C with wind speed of ${wind_speed_10m} km/h`,
|
|
44
55
|
data: {
|
|
45
56
|
temperature: temperature_2m,
|
|
46
57
|
windSpeed: wind_speed_10m,
|
|
47
58
|
},
|
|
48
|
-
ui:
|
|
59
|
+
ui: new CardUIBuilder()
|
|
60
|
+
.setRenderMode("page")
|
|
61
|
+
.title(`Current Weather in ${locationName} ${weatherEmoji}`)
|
|
62
|
+
.addChild(new MapUIBuilder()
|
|
63
|
+
.setInitialView(latitude, longitude, 10)
|
|
64
|
+
.setMapStyle('streets')
|
|
65
|
+
.addMarkers([
|
|
66
|
+
{
|
|
67
|
+
latitude,
|
|
68
|
+
longitude,
|
|
69
|
+
title: locationName,
|
|
70
|
+
description: `Temperature: ${temperature_2m}°C\nWind: ${wind_speed_10m} km/h`,
|
|
71
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
72
|
+
}
|
|
73
|
+
])
|
|
74
|
+
.build())
|
|
75
|
+
.content(`Temperature: ${temperature_2m}°C\nWind Speed: ${wind_speed_10m} km/h`)
|
|
76
|
+
.build(),
|
|
49
77
|
};
|
|
50
78
|
},
|
|
51
79
|
};
|
|
@@ -56,6 +84,7 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
56
84
|
description: "Fetches hourly weather forecast",
|
|
57
85
|
input: z
|
|
58
86
|
.object({
|
|
87
|
+
locationName: z.string().describe("Location name"),
|
|
59
88
|
latitude: z.number().describe("Latitude coordinate"),
|
|
60
89
|
longitude: z.number().describe("Longitude coordinate"),
|
|
61
90
|
})
|
|
@@ -73,11 +102,12 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
73
102
|
})
|
|
74
103
|
.describe("Hourly weather forecast"),
|
|
75
104
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
76
|
-
handler: async ({ latitude, longitude }, agentInfo) => {
|
|
105
|
+
handler: async ({ locationName, latitude, longitude }, agentInfo, context) => {
|
|
77
106
|
console.log(
|
|
78
|
-
`User / Agent ${agentInfo.id} requested forecast at ${latitude},${longitude}`
|
|
107
|
+
`User / Agent ${agentInfo.id} requested forecast at ${locationName} (${latitude},${longitude})`
|
|
79
108
|
);
|
|
80
109
|
|
|
110
|
+
|
|
81
111
|
const response = await axios.get(
|
|
82
112
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m`
|
|
83
113
|
);
|
|
@@ -85,15 +115,53 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
85
115
|
const { time, temperature_2m, wind_speed_10m, relative_humidity_2m } =
|
|
86
116
|
response.data.hourly;
|
|
87
117
|
|
|
118
|
+
// Limit to first 24 hours of forecast data
|
|
119
|
+
const limitedTime = time.slice(0, 24);
|
|
120
|
+
const limitedTemp = temperature_2m.slice(0, 24);
|
|
121
|
+
const limitedWind = wind_speed_10m.slice(0, 24);
|
|
122
|
+
const limitedHumidity = relative_humidity_2m.slice(0, 24);
|
|
123
|
+
|
|
124
|
+
const weatherEmoji = getWeatherEmoji(limitedTemp[0]);
|
|
125
|
+
|
|
88
126
|
return {
|
|
89
|
-
text: `Weather forecast available for the next
|
|
127
|
+
text: `Weather forecast for ${locationName} available for the next 24 hours`,
|
|
90
128
|
data: {
|
|
91
|
-
times:
|
|
92
|
-
temperatures:
|
|
93
|
-
windSpeeds:
|
|
94
|
-
humidity:
|
|
129
|
+
times: limitedTime,
|
|
130
|
+
temperatures: limitedTemp,
|
|
131
|
+
windSpeeds: limitedWind,
|
|
132
|
+
humidity: limitedHumidity,
|
|
95
133
|
},
|
|
96
|
-
ui:
|
|
134
|
+
ui: new CardUIBuilder()
|
|
135
|
+
.setRenderMode("page")
|
|
136
|
+
.title(`Weather Forecast for ${locationName} ${weatherEmoji}`)
|
|
137
|
+
.addChild(new MapUIBuilder()
|
|
138
|
+
.setInitialView(latitude, longitude, 10)
|
|
139
|
+
.setMapStyle('streets')
|
|
140
|
+
.addMarkers([
|
|
141
|
+
{
|
|
142
|
+
latitude,
|
|
143
|
+
longitude,
|
|
144
|
+
title: locationName,
|
|
145
|
+
description: `Temperature: ${limitedTemp[0]}°C\nWind: ${limitedWind[0]} km/h`,
|
|
146
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
147
|
+
}
|
|
148
|
+
])
|
|
149
|
+
.build())
|
|
150
|
+
.addChild(new TableUIBuilder()
|
|
151
|
+
.addColumns([
|
|
152
|
+
{ key: 'time', header: 'Time', type: 'string' },
|
|
153
|
+
{ key: 'temperature', header: 'Temperature (°C)', type: 'number' },
|
|
154
|
+
{ key: 'windSpeed', header: 'Wind Speed (km/h)', type: 'number' },
|
|
155
|
+
{ key: 'humidity', header: 'Humidity (%)', type: 'number' },
|
|
156
|
+
])
|
|
157
|
+
.rows(limitedTime.map((t: string, i: number) => ({
|
|
158
|
+
time: new Date(t).toLocaleString(),
|
|
159
|
+
temperature: limitedTemp[i],
|
|
160
|
+
windSpeed: limitedWind[i],
|
|
161
|
+
humidity: limitedHumidity[i],
|
|
162
|
+
})))
|
|
163
|
+
.build())
|
|
164
|
+
.build(),
|
|
97
165
|
};
|
|
98
166
|
},
|
|
99
167
|
};
|
|
@@ -106,8 +174,18 @@ const dainService = defineDAINService({
|
|
|
106
174
|
version: "1.0.0",
|
|
107
175
|
author: "Your Name",
|
|
108
176
|
tags: ["weather", "forecast", "dain"],
|
|
109
|
-
logo: "https://cdn-icons-png.flaticon.com/512/252/252035.png"
|
|
177
|
+
logo: "https://cdn-icons-png.flaticon.com/512/252/252035.png",
|
|
110
178
|
},
|
|
179
|
+
exampleQueries: [
|
|
180
|
+
{
|
|
181
|
+
category: "Weather",
|
|
182
|
+
queries: [
|
|
183
|
+
"What is the weather in Tokyo?",
|
|
184
|
+
"What is the weather in San Francisco?",
|
|
185
|
+
"What is the weather in London?",
|
|
186
|
+
],
|
|
187
|
+
}
|
|
188
|
+
],
|
|
111
189
|
identity: {
|
|
112
190
|
apiKey: process.env.DAIN_API_KEY,
|
|
113
191
|
},
|
package/package.json
CHANGED
|
@@ -6,17 +6,26 @@ import axios from "axios";
|
|
|
6
6
|
import {
|
|
7
7
|
defineDAINService,
|
|
8
8
|
ToolConfig,
|
|
9
|
-
ServiceConfig,
|
|
10
|
-
ToolboxConfig,
|
|
11
|
-
ServiceContext,
|
|
12
9
|
} from "@dainprotocol/service-sdk";
|
|
13
10
|
|
|
11
|
+
import { CardUIBuilder, TableUIBuilder, MapUIBuilder } from "@dainprotocol/utils";
|
|
12
|
+
|
|
13
|
+
const getWeatherEmoji = (temperature: number): string => {
|
|
14
|
+
if (temperature <= 0) return '🥶';
|
|
15
|
+
if (temperature <= 10) return '❄️';
|
|
16
|
+
if (temperature <= 20) return '⛅';
|
|
17
|
+
if (temperature <= 25) return '☀️';
|
|
18
|
+
if (temperature <= 30) return '🌞';
|
|
19
|
+
return '🔥';
|
|
20
|
+
};
|
|
21
|
+
|
|
14
22
|
const getWeatherConfig: ToolConfig = {
|
|
15
23
|
id: "get-weather",
|
|
16
24
|
name: "Get Weather",
|
|
17
25
|
description: "Fetches current weather for a city",
|
|
18
26
|
input: z
|
|
19
27
|
.object({
|
|
28
|
+
locationName: z.string().describe("Location name"),
|
|
20
29
|
latitude: z.number().describe("Latitude coordinate"),
|
|
21
30
|
longitude: z.number().describe("Longitude coordinate"),
|
|
22
31
|
})
|
|
@@ -28,24 +37,43 @@ const getWeatherConfig: ToolConfig = {
|
|
|
28
37
|
})
|
|
29
38
|
.describe("Current weather information"),
|
|
30
39
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
31
|
-
handler: async ({ latitude, longitude }, agentInfo) => {
|
|
40
|
+
handler: async ({ locationName, latitude, longitude }, agentInfo, context) => {
|
|
32
41
|
console.log(
|
|
33
|
-
`User / Agent ${agentInfo.id} requested weather at ${latitude},${longitude}`
|
|
42
|
+
`User / Agent ${agentInfo.id} requested weather at ${locationName} (${latitude},${longitude})`
|
|
34
43
|
);
|
|
35
44
|
|
|
45
|
+
|
|
36
46
|
const response = await axios.get(
|
|
37
47
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,wind_speed_10m`
|
|
38
48
|
);
|
|
39
49
|
|
|
40
50
|
const { temperature_2m, wind_speed_10m } = response.data.current;
|
|
51
|
+
const weatherEmoji = getWeatherEmoji(temperature_2m);
|
|
41
52
|
|
|
42
53
|
return {
|
|
43
|
-
text: `The current temperature is ${temperature_2m}°C with wind speed of ${wind_speed_10m} km/h`,
|
|
54
|
+
text: `The current temperature in ${locationName} is ${temperature_2m}°C with wind speed of ${wind_speed_10m} km/h`,
|
|
44
55
|
data: {
|
|
45
56
|
temperature: temperature_2m,
|
|
46
57
|
windSpeed: wind_speed_10m,
|
|
47
58
|
},
|
|
48
|
-
ui:
|
|
59
|
+
ui: new CardUIBuilder()
|
|
60
|
+
.setRenderMode("page")
|
|
61
|
+
.title(`Current Weather in ${locationName} ${weatherEmoji}`)
|
|
62
|
+
.addChild(new MapUIBuilder()
|
|
63
|
+
.setInitialView(latitude, longitude, 10)
|
|
64
|
+
.setMapStyle('streets')
|
|
65
|
+
.addMarkers([
|
|
66
|
+
{
|
|
67
|
+
latitude,
|
|
68
|
+
longitude,
|
|
69
|
+
title: locationName,
|
|
70
|
+
description: `Temperature: ${temperature_2m}°C\nWind: ${wind_speed_10m} km/h`,
|
|
71
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
72
|
+
}
|
|
73
|
+
])
|
|
74
|
+
.build())
|
|
75
|
+
.content(`Temperature: ${temperature_2m}°C\nWind Speed: ${wind_speed_10m} km/h`)
|
|
76
|
+
.build(),
|
|
49
77
|
};
|
|
50
78
|
},
|
|
51
79
|
};
|
|
@@ -56,6 +84,7 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
56
84
|
description: "Fetches hourly weather forecast",
|
|
57
85
|
input: z
|
|
58
86
|
.object({
|
|
87
|
+
locationName: z.string().describe("Location name"),
|
|
59
88
|
latitude: z.number().describe("Latitude coordinate"),
|
|
60
89
|
longitude: z.number().describe("Longitude coordinate"),
|
|
61
90
|
})
|
|
@@ -73,11 +102,12 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
73
102
|
})
|
|
74
103
|
.describe("Hourly weather forecast"),
|
|
75
104
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
76
|
-
handler: async ({ latitude, longitude }, agentInfo) => {
|
|
105
|
+
handler: async ({ locationName, latitude, longitude }, agentInfo, context) => {
|
|
77
106
|
console.log(
|
|
78
|
-
`User / Agent ${agentInfo.id} requested forecast at ${latitude},${longitude}`
|
|
107
|
+
`User / Agent ${agentInfo.id} requested forecast at ${locationName} (${latitude},${longitude})`
|
|
79
108
|
);
|
|
80
109
|
|
|
110
|
+
|
|
81
111
|
const response = await axios.get(
|
|
82
112
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m`
|
|
83
113
|
);
|
|
@@ -85,15 +115,53 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
85
115
|
const { time, temperature_2m, wind_speed_10m, relative_humidity_2m } =
|
|
86
116
|
response.data.hourly;
|
|
87
117
|
|
|
118
|
+
// Limit to first 24 hours of forecast data
|
|
119
|
+
const limitedTime = time.slice(0, 24);
|
|
120
|
+
const limitedTemp = temperature_2m.slice(0, 24);
|
|
121
|
+
const limitedWind = wind_speed_10m.slice(0, 24);
|
|
122
|
+
const limitedHumidity = relative_humidity_2m.slice(0, 24);
|
|
123
|
+
|
|
124
|
+
const weatherEmoji = getWeatherEmoji(limitedTemp[0]);
|
|
125
|
+
|
|
88
126
|
return {
|
|
89
|
-
text: `Weather forecast available for the next
|
|
127
|
+
text: `Weather forecast for ${locationName} available for the next 24 hours`,
|
|
90
128
|
data: {
|
|
91
|
-
times:
|
|
92
|
-
temperatures:
|
|
93
|
-
windSpeeds:
|
|
94
|
-
humidity:
|
|
129
|
+
times: limitedTime,
|
|
130
|
+
temperatures: limitedTemp,
|
|
131
|
+
windSpeeds: limitedWind,
|
|
132
|
+
humidity: limitedHumidity,
|
|
95
133
|
},
|
|
96
|
-
ui:
|
|
134
|
+
ui: new CardUIBuilder()
|
|
135
|
+
.setRenderMode("page")
|
|
136
|
+
.title(`Weather Forecast for ${locationName} ${weatherEmoji}`)
|
|
137
|
+
.addChild(new MapUIBuilder()
|
|
138
|
+
.setInitialView(latitude, longitude, 10)
|
|
139
|
+
.setMapStyle('streets')
|
|
140
|
+
.addMarkers([
|
|
141
|
+
{
|
|
142
|
+
latitude,
|
|
143
|
+
longitude,
|
|
144
|
+
title: locationName,
|
|
145
|
+
description: `Temperature: ${limitedTemp[0]}°C\nWind: ${limitedWind[0]} km/h`,
|
|
146
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
147
|
+
}
|
|
148
|
+
])
|
|
149
|
+
.build())
|
|
150
|
+
.addChild(new TableUIBuilder()
|
|
151
|
+
.addColumns([
|
|
152
|
+
{ key: 'time', header: 'Time', type: 'string' },
|
|
153
|
+
{ key: 'temperature', header: 'Temperature (°C)', type: 'number' },
|
|
154
|
+
{ key: 'windSpeed', header: 'Wind Speed (km/h)', type: 'number' },
|
|
155
|
+
{ key: 'humidity', header: 'Humidity (%)', type: 'number' },
|
|
156
|
+
])
|
|
157
|
+
.rows(limitedTime.map((t: string, i: number) => ({
|
|
158
|
+
time: new Date(t).toLocaleString(),
|
|
159
|
+
temperature: limitedTemp[i],
|
|
160
|
+
windSpeed: limitedWind[i],
|
|
161
|
+
humidity: limitedHumidity[i],
|
|
162
|
+
})))
|
|
163
|
+
.build())
|
|
164
|
+
.build(),
|
|
97
165
|
};
|
|
98
166
|
},
|
|
99
167
|
};
|
|
@@ -106,8 +174,18 @@ const dainService = defineDAINService({
|
|
|
106
174
|
version: "1.0.0",
|
|
107
175
|
author: "Your Name",
|
|
108
176
|
tags: ["weather", "forecast", "dain"],
|
|
109
|
-
logo: "https://cdn-icons-png.flaticon.com/512/252/252035.png"
|
|
177
|
+
logo: "https://cdn-icons-png.flaticon.com/512/252/252035.png",
|
|
110
178
|
},
|
|
179
|
+
exampleQueries: [
|
|
180
|
+
{
|
|
181
|
+
category: "Weather",
|
|
182
|
+
queries: [
|
|
183
|
+
"What is the weather in Tokyo?",
|
|
184
|
+
"What is the weather in San Francisco?",
|
|
185
|
+
"What is the weather in London?",
|
|
186
|
+
],
|
|
187
|
+
}
|
|
188
|
+
],
|
|
111
189
|
identity: {
|
|
112
190
|
apiKey: process.env.DAIN_API_KEY,
|
|
113
191
|
},
|