@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/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', '2022')
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)')
@@ -7,5 +7,6 @@
7
7
  "environment": "development",
8
8
  "version": "1.0.0",
9
9
  "tunnel-base-url": "wss:///tunnel.dain-local.com",
10
- "deployment-id": ""
10
+ "deployment-id": "",
11
+ "service-id": ""
11
12
  }
@@ -10,8 +10,8 @@
10
10
  "deploy": "dain deploy"
11
11
  },
12
12
  "dependencies": {
13
- "@dainprotocol/service-sdk": "^1.0.93",
14
- "@dainprotocol/utils": "^0.0.48",
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.0.31"
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 { CardUIBuilder, TableUIBuilder, MapUIBuilder } from "@dainprotocol/utils";
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 ({ locationName, latitude, longitude }, agentInfo, context) => {
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}&current=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(new MapUIBuilder()
63
- .setInitialView(latitude, longitude, 10)
64
- .setMapStyle('mapbox://styles/mapbox/streets-v12')
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`)
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 ({ locationName, latitude, longitude }, agentInfo, context) => {
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 CardUIBuilder()
146
+ ui: new LayoutUIBuilder()
135
147
  .setRenderMode("page")
136
- .title(`Weather Forecast for ${locationName} ${weatherEmoji}`)
137
- .addChild(new MapUIBuilder()
138
- .setInitialView(latitude, longitude, 10)
139
- .setMapStyle('mapbox://styles/mapbox/streets-v12')
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())
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
- 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
- }
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({ port: 2022 }).then(() => {
196
- console.log("Weather DAIN Service is running on port 2022");
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 = ['.env.local', '.env', '.env.development', '.env.production'];
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(); // Load environment variables from files
66
- var defaultConfigPath = path_1.default.join(process.cwd(), 'dain.json');
67
- var configPath = configFile
68
- ? path_1.default.join(process.cwd(), configFile)
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, 'utf8');
75
+ var configData = fs_1.default.readFileSync(configPath, "utf8");
77
76
  var config = JSON.parse(configData);
78
77
  // Validate required fields
79
- if (!config['main-file']) {
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['environment'] = config['environment'] || 'development';
84
- config['version'] = config['version'] || '1.0.0';
85
- config['out-dir'] = config['out-dir'] || 'dist'; // Default to 'dist' if not specified
86
- config['tunnel-base-url'] =
87
- config['tunnel-base-url'] || 'wss:///tunnel.dain-local.com'; // Default value if not specified
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['api-key'] ||
91
- config['api-key'] === 'env' ||
92
- config['api-key'] === 'MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY') {
93
- config['api-key'] = process.env.DAIN_API_KEY;
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['api-key']) {
96
- throw new Error('API key is not set in config or DAIN_API_KEY environment variable');
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)('Setting up proxy...').start();
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['tunnel-base-url'] || 'wss:///tunnel.dain-local.com', apiKey);
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(chalk_1.default.green("\n------------------------------------------------------------\nYour service is available publicly at: ") +
119
- chalk_1.default.cyan.underline("".concat(tunnelUrl)) +
120
- chalk_1.default.green("\n------------------------------------------------------------\n"));
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('\nError setting up proxy'));
130
+ spinner.fail(chalk_1.default.red("Error setting up proxy"));
125
131
  console.error(chalk_1.default.red(error_1));
126
- return [3 /*break*/, 4];
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(), 'static');
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.1.21",
3
+ "version": "1.1.28",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -7,5 +7,6 @@
7
7
  "environment": "development",
8
8
  "version": "1.0.0",
9
9
  "tunnel-base-url": "wss:///tunnel.dain-local.com",
10
- "deployment-id": ""
10
+ "deployment-id": "",
11
+ "service-id": ""
11
12
  }
@@ -10,8 +10,8 @@
10
10
  "deploy": "dain deploy"
11
11
  },
12
12
  "dependencies": {
13
- "@dainprotocol/service-sdk": "^1.0.93",
14
- "@dainprotocol/utils": "^0.0.48",
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.0.31"
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 { CardUIBuilder, TableUIBuilder, MapUIBuilder } from "@dainprotocol/utils";
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 ({ locationName, latitude, longitude }, agentInfo, context) => {
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}&current=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(new MapUIBuilder()
63
- .setInitialView(latitude, longitude, 10)
64
- .setMapStyle('mapbox://styles/mapbox/streets-v12')
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`)
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 ({ locationName, latitude, longitude }, agentInfo, context) => {
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 CardUIBuilder()
146
+ ui: new LayoutUIBuilder()
135
147
  .setRenderMode("page")
136
- .title(`Weather Forecast for ${locationName} ${weatherEmoji}`)
137
- .addChild(new MapUIBuilder()
138
- .setInitialView(latitude, longitude, 10)
139
- .setMapStyle('mapbox://styles/mapbox/streets-v12')
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())
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
- 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
- }
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({ port: 2022 }).then(() => {
196
- console.log("Weather DAIN Service is running on port 2022");
217
+ dainService.startNode().then(({ address }) => {
218
+ console.log("Weather DAIN Service is running at :" + address().port);
197
219
  });