@dainprotocol/cli 1.1.21 → 1.1.28
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/deploy.js +55 -52
- package/dist/commands/dev.js +70 -21
- package/dist/commands/logs.js +25 -23
- package/dist/commands/status.js +19 -17
- package/dist/commands/undeploy.js +16 -14
- package/dist/index.js +1 -1
- package/dist/templates/default/dain.json +2 -1
- package/dist/templates/default/package.json +3 -3
- package/dist/templates/default/src/index.ts +90 -68
- package/dist/utils.js +38 -32
- package/package.json +1 -1
- package/templates/default/dain.json +2 -1
- package/templates/default/package.json +3 -3
- package/templates/default/src/index.ts +90 -68
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ program
|
|
|
33
33
|
program
|
|
34
34
|
.command('dev')
|
|
35
35
|
.description('Run the project in development mode')
|
|
36
|
-
.option('--port <port>', 'Set the port number'
|
|
36
|
+
.option('--port <port>', 'Set the port number')
|
|
37
37
|
.option('--noproxy', 'Disable localtunnel proxy')
|
|
38
38
|
.option('-c, --config <path>', 'Path to custom configuration file')
|
|
39
39
|
.option('--runtime <runtime>', 'Specify the runtime (node or workers)')
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"deploy": "dain deploy"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dainprotocol/service-sdk": "^1.0.
|
|
14
|
-
"@dainprotocol/utils": "^0.0.
|
|
13
|
+
"@dainprotocol/service-sdk": "^1.0.95",
|
|
14
|
+
"@dainprotocol/utils": "^0.0.49",
|
|
15
15
|
"zod": "^3.23.8",
|
|
16
16
|
"hono": "^4.6.3",
|
|
17
17
|
"ts-node": "^10.4.0",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"@types/express": "^4.17.13",
|
|
20
20
|
"@types/node": "^22.5.4",
|
|
21
21
|
"axios": "^1.7.5",
|
|
22
|
-
"@dainprotocol/cli": "^1.
|
|
22
|
+
"@dainprotocol/cli": "^1.1.26"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -3,20 +3,22 @@
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import axios from "axios";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
defineDAINService,
|
|
8
|
-
ToolConfig,
|
|
9
|
-
} from "@dainprotocol/service-sdk";
|
|
6
|
+
import { defineDAINService, ToolConfig } from "@dainprotocol/service-sdk";
|
|
10
7
|
|
|
11
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
CardUIBuilder,
|
|
10
|
+
TableUIBuilder,
|
|
11
|
+
MapUIBuilder,
|
|
12
|
+
LayoutUIBuilder,
|
|
13
|
+
} from "@dainprotocol/utils";
|
|
12
14
|
|
|
13
15
|
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
|
|
16
|
+
if (temperature <= 0) return "🥶";
|
|
17
|
+
if (temperature <= 10) return "❄️";
|
|
18
|
+
if (temperature <= 20) return "⛅";
|
|
19
|
+
if (temperature <= 25) return "☀️";
|
|
20
|
+
if (temperature <= 30) return "🌞";
|
|
21
|
+
return "🔥";
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
const getWeatherConfig: ToolConfig = {
|
|
@@ -37,12 +39,15 @@ const getWeatherConfig: ToolConfig = {
|
|
|
37
39
|
})
|
|
38
40
|
.describe("Current weather information"),
|
|
39
41
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
40
|
-
handler: async (
|
|
42
|
+
handler: async (
|
|
43
|
+
{ locationName, latitude, longitude },
|
|
44
|
+
agentInfo,
|
|
45
|
+
context
|
|
46
|
+
) => {
|
|
41
47
|
console.log(
|
|
42
48
|
`User / Agent ${agentInfo.id} requested weather at ${locationName} (${latitude},${longitude})`
|
|
43
49
|
);
|
|
44
50
|
|
|
45
|
-
|
|
46
51
|
const response = await axios.get(
|
|
47
52
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,wind_speed_10m`
|
|
48
53
|
);
|
|
@@ -59,20 +64,24 @@ const getWeatherConfig: ToolConfig = {
|
|
|
59
64
|
ui: new CardUIBuilder()
|
|
60
65
|
.setRenderMode("page")
|
|
61
66
|
.title(`Current Weather in ${locationName} ${weatherEmoji}`)
|
|
62
|
-
.addChild(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
.addChild(
|
|
68
|
+
new MapUIBuilder()
|
|
69
|
+
.setInitialView(latitude, longitude, 10)
|
|
70
|
+
.setMapStyle("mapbox://styles/mapbox/streets-v12")
|
|
71
|
+
.addMarkers([
|
|
72
|
+
{
|
|
73
|
+
latitude,
|
|
74
|
+
longitude,
|
|
75
|
+
title: locationName,
|
|
76
|
+
description: `Temperature: ${temperature_2m}°C\nWind: ${wind_speed_10m} km/h`,
|
|
77
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
78
|
+
},
|
|
79
|
+
])
|
|
80
|
+
.build()
|
|
81
|
+
)
|
|
82
|
+
.content(
|
|
83
|
+
`Temperature: ${temperature_2m}°C\nWind Speed: ${wind_speed_10m} km/h`
|
|
84
|
+
)
|
|
76
85
|
.build(),
|
|
77
86
|
};
|
|
78
87
|
},
|
|
@@ -102,12 +111,15 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
102
111
|
})
|
|
103
112
|
.describe("Hourly weather forecast"),
|
|
104
113
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
105
|
-
handler: async (
|
|
114
|
+
handler: async (
|
|
115
|
+
{ locationName, latitude, longitude },
|
|
116
|
+
agentInfo,
|
|
117
|
+
context
|
|
118
|
+
) => {
|
|
106
119
|
console.log(
|
|
107
120
|
`User / Agent ${agentInfo.id} requested forecast at ${locationName} (${latitude},${longitude})`
|
|
108
121
|
);
|
|
109
122
|
|
|
110
|
-
|
|
111
123
|
const response = await axios.get(
|
|
112
124
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m`
|
|
113
125
|
);
|
|
@@ -131,36 +143,46 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
131
143
|
windSpeeds: limitedWind,
|
|
132
144
|
humidity: limitedHumidity,
|
|
133
145
|
},
|
|
134
|
-
ui: new
|
|
146
|
+
ui: new LayoutUIBuilder()
|
|
135
147
|
.setRenderMode("page")
|
|
136
|
-
.
|
|
137
|
-
.addChild(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
148
|
+
.setLayoutType("column")
|
|
149
|
+
.addChild(
|
|
150
|
+
new MapUIBuilder()
|
|
151
|
+
.setInitialView(latitude, longitude, 10)
|
|
152
|
+
.setMapStyle("mapbox://styles/mapbox/streets-v12")
|
|
153
|
+
.addMarkers([
|
|
154
|
+
{
|
|
155
|
+
latitude,
|
|
156
|
+
longitude,
|
|
157
|
+
title: locationName,
|
|
158
|
+
description: `Temperature: ${limitedTemp[0]}°C\nWind: ${limitedWind[0]} km/h`,
|
|
159
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
160
|
+
},
|
|
161
|
+
])
|
|
162
|
+
.build()
|
|
163
|
+
)
|
|
164
|
+
.addChild(
|
|
165
|
+
new TableUIBuilder()
|
|
166
|
+
.addColumns([
|
|
167
|
+
{ key: "time", header: "Time", type: "string" },
|
|
168
|
+
{
|
|
169
|
+
key: "temperature",
|
|
170
|
+
header: "Temperature (°C)",
|
|
171
|
+
type: "number",
|
|
172
|
+
},
|
|
173
|
+
{ key: "windSpeed", header: "Wind Speed (km/h)", type: "number" },
|
|
174
|
+
{ key: "humidity", header: "Humidity (%)", type: "number" },
|
|
175
|
+
])
|
|
176
|
+
.rows(
|
|
177
|
+
limitedTime.map((t: string, i: number) => ({
|
|
178
|
+
time: new Date(t).toLocaleString(),
|
|
179
|
+
temperature: limitedTemp[i],
|
|
180
|
+
windSpeed: limitedWind[i],
|
|
181
|
+
humidity: limitedHumidity[i],
|
|
182
|
+
}))
|
|
183
|
+
)
|
|
184
|
+
.build()
|
|
185
|
+
)
|
|
164
186
|
.build(),
|
|
165
187
|
};
|
|
166
188
|
},
|
|
@@ -177,14 +199,14 @@ const dainService = defineDAINService({
|
|
|
177
199
|
logo: "https://cdn-icons-png.flaticon.com/512/252/252035.png",
|
|
178
200
|
},
|
|
179
201
|
exampleQueries: [
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
202
|
+
{
|
|
203
|
+
category: "Weather",
|
|
204
|
+
queries: [
|
|
205
|
+
"What is the weather in Tokyo?",
|
|
206
|
+
"What is the weather in San Francisco?",
|
|
207
|
+
"What is the weather in London?",
|
|
208
|
+
],
|
|
209
|
+
},
|
|
188
210
|
],
|
|
189
211
|
identity: {
|
|
190
212
|
apiKey: process.env.DAIN_API_KEY,
|
|
@@ -192,6 +214,6 @@ const dainService = defineDAINService({
|
|
|
192
214
|
tools: [getWeatherConfig, getWeatherForecastConfig],
|
|
193
215
|
});
|
|
194
216
|
|
|
195
|
-
dainService.startNode(
|
|
196
|
-
console.log("Weather DAIN Service is running
|
|
217
|
+
dainService.startNode().then(({ address }) => {
|
|
218
|
+
console.log("Weather DAIN Service is running at :" + address().port);
|
|
197
219
|
});
|
package/dist/utils.js
CHANGED
|
@@ -40,6 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.getDainConfig = getDainConfig;
|
|
43
|
+
exports.displayTunnelUrl = displayTunnelUrl;
|
|
43
44
|
exports.setupProxy = setupProxy;
|
|
44
45
|
exports.logError = logError;
|
|
45
46
|
exports.logSuccess = logSuccess;
|
|
@@ -53,7 +54,7 @@ var ora_1 = __importDefault(require("ora"));
|
|
|
53
54
|
var chalk_1 = __importDefault(require("chalk"));
|
|
54
55
|
var dotenv_1 = __importDefault(require("dotenv"));
|
|
55
56
|
function loadEnvFiles() {
|
|
56
|
-
var envFiles = [
|
|
57
|
+
var envFiles = [".env.local", ".env", ".env.development", ".env.production"];
|
|
57
58
|
envFiles.forEach(function (file) {
|
|
58
59
|
var envPath = path_1.default.join(process.cwd(), file);
|
|
59
60
|
if (fs_1.default.existsSync(envPath)) {
|
|
@@ -62,38 +63,35 @@ function loadEnvFiles() {
|
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
function getDainConfig(configFile) {
|
|
65
|
-
loadEnvFiles(); //
|
|
66
|
-
var defaultConfigPath = path_1.default.join(process.cwd(),
|
|
67
|
-
var configPath = configFile
|
|
68
|
-
|
|
69
|
-
: defaultConfigPath;
|
|
70
|
-
console.log('Config path: ', configPath);
|
|
66
|
+
loadEnvFiles(); // Loads all env files first
|
|
67
|
+
var defaultConfigPath = path_1.default.join(process.cwd(), "dain.json");
|
|
68
|
+
var configPath = configFile ? path_1.default.join(process.cwd(), configFile) : defaultConfigPath;
|
|
69
|
+
console.log("Config path: ", configPath);
|
|
71
70
|
if (!fs_1.default.existsSync(configPath)) {
|
|
72
71
|
logError("Configuration file not found: ".concat(configPath));
|
|
73
72
|
process.exit(1);
|
|
74
73
|
}
|
|
75
74
|
try {
|
|
76
|
-
var configData = fs_1.default.readFileSync(configPath,
|
|
75
|
+
var configData = fs_1.default.readFileSync(configPath, "utf8");
|
|
77
76
|
var config = JSON.parse(configData);
|
|
78
77
|
// Validate required fields
|
|
79
|
-
if (!config[
|
|
78
|
+
if (!config["main-file"]) {
|
|
80
79
|
throw new Error("Configuration must include 'main-file'");
|
|
81
80
|
}
|
|
82
81
|
// Set default values for optional fields
|
|
83
|
-
config[
|
|
84
|
-
config[
|
|
85
|
-
config[
|
|
86
|
-
config[
|
|
87
|
-
|
|
88
|
-
config['runtime'] = config['runtime'] || 'node'; // Add this line
|
|
82
|
+
config["environment"] = config["environment"] || "development";
|
|
83
|
+
config["version"] = config["version"] || "1.0.0";
|
|
84
|
+
config["out-dir"] = config["out-dir"] || "dist"; // Default to 'dist' if not specified
|
|
85
|
+
config["tunnel-base-url"] = config["tunnel-base-url"] || "wss:///tunnel.dain-local.com"; // Default value if not specified
|
|
86
|
+
config["runtime"] = config["runtime"] || "node"; // Add this line
|
|
89
87
|
// Handle API key
|
|
90
|
-
if (!config[
|
|
91
|
-
config[
|
|
92
|
-
config[
|
|
93
|
-
config[
|
|
88
|
+
if (!config["api-key"] ||
|
|
89
|
+
config["api-key"] === "env" ||
|
|
90
|
+
config["api-key"] === "MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY") {
|
|
91
|
+
config["api-key"] = process.env.DAIN_API_KEY;
|
|
94
92
|
}
|
|
95
|
-
if (!config[
|
|
96
|
-
throw new Error(
|
|
93
|
+
if (!config["api-key"]) {
|
|
94
|
+
throw new Error("API key is not set in config or DAIN_API_KEY environment variable");
|
|
97
95
|
}
|
|
98
96
|
return config;
|
|
99
97
|
}
|
|
@@ -101,29 +99,37 @@ function getDainConfig(configFile) {
|
|
|
101
99
|
throw new Error("Error reading or parsing configuration file: ".concat(error));
|
|
102
100
|
}
|
|
103
101
|
}
|
|
102
|
+
function displayTunnelUrl(tunnelUrl) {
|
|
103
|
+
var divider = chalk_1.default.green("------------------------------------------------------------");
|
|
104
|
+
var header = chalk_1.default.green("Your service is available publicly at:");
|
|
105
|
+
var url = chalk_1.default.cyan.underline(tunnelUrl);
|
|
106
|
+
var info = chalk_1.default.yellow("This service URL can be connected to by a DAIN client or assistant");
|
|
107
|
+
var subInfo = chalk_1.default.yellow("(such as butterfly in development mode)");
|
|
108
|
+
var warning = chalk_1.default.red("You should not visit this URL directly");
|
|
109
|
+
console.log("\n".concat(divider, "\n").concat(header, "\n").concat(url, "\n\n").concat(info, "\n").concat(subInfo, "\n\n").concat(warning, "\n").concat(divider, "\n"));
|
|
110
|
+
}
|
|
104
111
|
function setupProxy(port, apiKey, config) {
|
|
105
112
|
return __awaiter(this, void 0, void 0, function () {
|
|
106
113
|
var spinner, client, tunnelUrl, error_1;
|
|
107
114
|
return __generator(this, function (_a) {
|
|
108
115
|
switch (_a.label) {
|
|
109
116
|
case 0:
|
|
110
|
-
spinner = (0, ora_1.default)(
|
|
117
|
+
spinner = (0, ora_1.default)("Setting up proxy...").start();
|
|
111
118
|
_a.label = 1;
|
|
112
119
|
case 1:
|
|
113
120
|
_a.trys.push([1, 3, , 4]);
|
|
114
|
-
client = new client_1.DainTunnel(config[
|
|
121
|
+
client = new client_1.DainTunnel(config["tunnel-base-url"] || "wss:///tunnel.dain-local.com", apiKey);
|
|
115
122
|
return [4 /*yield*/, client.start(parseInt(port))];
|
|
116
123
|
case 2:
|
|
117
124
|
tunnelUrl = _a.sent();
|
|
118
|
-
spinner.succeed(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return [2 /*return*/, client];
|
|
125
|
+
spinner.succeed("Proxy setup complete");
|
|
126
|
+
displayTunnelUrl(tunnelUrl);
|
|
127
|
+
return [2 /*return*/, { client: client, tunnelUrl: tunnelUrl }];
|
|
122
128
|
case 3:
|
|
123
129
|
error_1 = _a.sent();
|
|
124
|
-
spinner.fail(chalk_1.default.red(
|
|
130
|
+
spinner.fail(chalk_1.default.red("Error setting up proxy"));
|
|
125
131
|
console.error(chalk_1.default.red(error_1));
|
|
126
|
-
|
|
132
|
+
throw error_1;
|
|
127
133
|
case 4: return [2 /*return*/];
|
|
128
134
|
}
|
|
129
135
|
});
|
|
@@ -142,9 +148,9 @@ function logInfo(message) {
|
|
|
142
148
|
console.log(chalk_1.default.blue("\nInfo: ".concat(message)));
|
|
143
149
|
}
|
|
144
150
|
function getStaticFilesPath() {
|
|
145
|
-
return path_1.default.join(process.cwd(),
|
|
151
|
+
return path_1.default.join(process.cwd(), "static");
|
|
146
152
|
}
|
|
147
153
|
function extractOrgId(apiKey) {
|
|
148
|
-
var apiKeySplit = apiKey === null || apiKey === void 0 ? void 0 : apiKey.split(
|
|
149
|
-
return apiKeySplit ? apiKeySplit[2] :
|
|
154
|
+
var apiKeySplit = apiKey === null || apiKey === void 0 ? void 0 : apiKey.split("_");
|
|
155
|
+
return apiKeySplit ? apiKeySplit[2] : "";
|
|
150
156
|
}
|
package/package.json
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"deploy": "dain deploy"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dainprotocol/service-sdk": "^1.0.
|
|
14
|
-
"@dainprotocol/utils": "^0.0.
|
|
13
|
+
"@dainprotocol/service-sdk": "^1.0.95",
|
|
14
|
+
"@dainprotocol/utils": "^0.0.49",
|
|
15
15
|
"zod": "^3.23.8",
|
|
16
16
|
"hono": "^4.6.3",
|
|
17
17
|
"ts-node": "^10.4.0",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"@types/express": "^4.17.13",
|
|
20
20
|
"@types/node": "^22.5.4",
|
|
21
21
|
"axios": "^1.7.5",
|
|
22
|
-
"@dainprotocol/cli": "^1.
|
|
22
|
+
"@dainprotocol/cli": "^1.1.26"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -3,20 +3,22 @@
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import axios from "axios";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
defineDAINService,
|
|
8
|
-
ToolConfig,
|
|
9
|
-
} from "@dainprotocol/service-sdk";
|
|
6
|
+
import { defineDAINService, ToolConfig } from "@dainprotocol/service-sdk";
|
|
10
7
|
|
|
11
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
CardUIBuilder,
|
|
10
|
+
TableUIBuilder,
|
|
11
|
+
MapUIBuilder,
|
|
12
|
+
LayoutUIBuilder,
|
|
13
|
+
} from "@dainprotocol/utils";
|
|
12
14
|
|
|
13
15
|
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
|
|
16
|
+
if (temperature <= 0) return "🥶";
|
|
17
|
+
if (temperature <= 10) return "❄️";
|
|
18
|
+
if (temperature <= 20) return "⛅";
|
|
19
|
+
if (temperature <= 25) return "☀️";
|
|
20
|
+
if (temperature <= 30) return "🌞";
|
|
21
|
+
return "🔥";
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
const getWeatherConfig: ToolConfig = {
|
|
@@ -37,12 +39,15 @@ const getWeatherConfig: ToolConfig = {
|
|
|
37
39
|
})
|
|
38
40
|
.describe("Current weather information"),
|
|
39
41
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
40
|
-
handler: async (
|
|
42
|
+
handler: async (
|
|
43
|
+
{ locationName, latitude, longitude },
|
|
44
|
+
agentInfo,
|
|
45
|
+
context
|
|
46
|
+
) => {
|
|
41
47
|
console.log(
|
|
42
48
|
`User / Agent ${agentInfo.id} requested weather at ${locationName} (${latitude},${longitude})`
|
|
43
49
|
);
|
|
44
50
|
|
|
45
|
-
|
|
46
51
|
const response = await axios.get(
|
|
47
52
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,wind_speed_10m`
|
|
48
53
|
);
|
|
@@ -59,20 +64,24 @@ const getWeatherConfig: ToolConfig = {
|
|
|
59
64
|
ui: new CardUIBuilder()
|
|
60
65
|
.setRenderMode("page")
|
|
61
66
|
.title(`Current Weather in ${locationName} ${weatherEmoji}`)
|
|
62
|
-
.addChild(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
.addChild(
|
|
68
|
+
new MapUIBuilder()
|
|
69
|
+
.setInitialView(latitude, longitude, 10)
|
|
70
|
+
.setMapStyle("mapbox://styles/mapbox/streets-v12")
|
|
71
|
+
.addMarkers([
|
|
72
|
+
{
|
|
73
|
+
latitude,
|
|
74
|
+
longitude,
|
|
75
|
+
title: locationName,
|
|
76
|
+
description: `Temperature: ${temperature_2m}°C\nWind: ${wind_speed_10m} km/h`,
|
|
77
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
78
|
+
},
|
|
79
|
+
])
|
|
80
|
+
.build()
|
|
81
|
+
)
|
|
82
|
+
.content(
|
|
83
|
+
`Temperature: ${temperature_2m}°C\nWind Speed: ${wind_speed_10m} km/h`
|
|
84
|
+
)
|
|
76
85
|
.build(),
|
|
77
86
|
};
|
|
78
87
|
},
|
|
@@ -102,12 +111,15 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
102
111
|
})
|
|
103
112
|
.describe("Hourly weather forecast"),
|
|
104
113
|
pricing: { pricePerUse: 0, currency: "USD" },
|
|
105
|
-
handler: async (
|
|
114
|
+
handler: async (
|
|
115
|
+
{ locationName, latitude, longitude },
|
|
116
|
+
agentInfo,
|
|
117
|
+
context
|
|
118
|
+
) => {
|
|
106
119
|
console.log(
|
|
107
120
|
`User / Agent ${agentInfo.id} requested forecast at ${locationName} (${latitude},${longitude})`
|
|
108
121
|
);
|
|
109
122
|
|
|
110
|
-
|
|
111
123
|
const response = await axios.get(
|
|
112
124
|
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m`
|
|
113
125
|
);
|
|
@@ -131,36 +143,46 @@ const getWeatherForecastConfig: ToolConfig = {
|
|
|
131
143
|
windSpeeds: limitedWind,
|
|
132
144
|
humidity: limitedHumidity,
|
|
133
145
|
},
|
|
134
|
-
ui: new
|
|
146
|
+
ui: new LayoutUIBuilder()
|
|
135
147
|
.setRenderMode("page")
|
|
136
|
-
.
|
|
137
|
-
.addChild(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
148
|
+
.setLayoutType("column")
|
|
149
|
+
.addChild(
|
|
150
|
+
new MapUIBuilder()
|
|
151
|
+
.setInitialView(latitude, longitude, 10)
|
|
152
|
+
.setMapStyle("mapbox://styles/mapbox/streets-v12")
|
|
153
|
+
.addMarkers([
|
|
154
|
+
{
|
|
155
|
+
latitude,
|
|
156
|
+
longitude,
|
|
157
|
+
title: locationName,
|
|
158
|
+
description: `Temperature: ${limitedTemp[0]}°C\nWind: ${limitedWind[0]} km/h`,
|
|
159
|
+
text: `${locationName} ${weatherEmoji}`,
|
|
160
|
+
},
|
|
161
|
+
])
|
|
162
|
+
.build()
|
|
163
|
+
)
|
|
164
|
+
.addChild(
|
|
165
|
+
new TableUIBuilder()
|
|
166
|
+
.addColumns([
|
|
167
|
+
{ key: "time", header: "Time", type: "string" },
|
|
168
|
+
{
|
|
169
|
+
key: "temperature",
|
|
170
|
+
header: "Temperature (°C)",
|
|
171
|
+
type: "number",
|
|
172
|
+
},
|
|
173
|
+
{ key: "windSpeed", header: "Wind Speed (km/h)", type: "number" },
|
|
174
|
+
{ key: "humidity", header: "Humidity (%)", type: "number" },
|
|
175
|
+
])
|
|
176
|
+
.rows(
|
|
177
|
+
limitedTime.map((t: string, i: number) => ({
|
|
178
|
+
time: new Date(t).toLocaleString(),
|
|
179
|
+
temperature: limitedTemp[i],
|
|
180
|
+
windSpeed: limitedWind[i],
|
|
181
|
+
humidity: limitedHumidity[i],
|
|
182
|
+
}))
|
|
183
|
+
)
|
|
184
|
+
.build()
|
|
185
|
+
)
|
|
164
186
|
.build(),
|
|
165
187
|
};
|
|
166
188
|
},
|
|
@@ -177,14 +199,14 @@ const dainService = defineDAINService({
|
|
|
177
199
|
logo: "https://cdn-icons-png.flaticon.com/512/252/252035.png",
|
|
178
200
|
},
|
|
179
201
|
exampleQueries: [
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
202
|
+
{
|
|
203
|
+
category: "Weather",
|
|
204
|
+
queries: [
|
|
205
|
+
"What is the weather in Tokyo?",
|
|
206
|
+
"What is the weather in San Francisco?",
|
|
207
|
+
"What is the weather in London?",
|
|
208
|
+
],
|
|
209
|
+
},
|
|
188
210
|
],
|
|
189
211
|
identity: {
|
|
190
212
|
apiKey: process.env.DAIN_API_KEY,
|
|
@@ -192,6 +214,6 @@ const dainService = defineDAINService({
|
|
|
192
214
|
tools: [getWeatherConfig, getWeatherForecastConfig],
|
|
193
215
|
});
|
|
194
216
|
|
|
195
|
-
dainService.startNode(
|
|
196
|
-
console.log("Weather DAIN Service is running
|
|
217
|
+
dainService.startNode().then(({ address }) => {
|
|
218
|
+
console.log("Weather DAIN Service is running at :" + address().port);
|
|
197
219
|
});
|