@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.
@@ -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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
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) {
@@ -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, 7, , 8]);
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 6:
95
+ case 8:
88
96
  _a.sent();
89
97
  process.exit(0);
90
- return [3 /*break*/, 8];
91
- case 7:
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*/, 8];
97
- case 8: return [2 /*return*/];
104
+ return [3 /*break*/, 10];
105
+ case 10: return [2 /*return*/];
98
106
  }
99
107
  });
100
108
  });
@@ -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
- process.exit(1);
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 (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
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) {
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@dainprotocol/service-sdk": "^1.0.85",
14
+ "@dainprotocol/utils": "^0.0.43",
14
15
  "zod": "^3.23.8",
15
16
  "hono": "^4.6.3",
16
17
  "ts-node": "^10.4.0",
@@ -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}&current=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 ${time.length} hours`,
127
+ text: `Weather forecast for ${locationName} available for the next 24 hours`,
90
128
  data: {
91
- times: time,
92
- temperatures: temperature_2m,
93
- windSpeeds: wind_speed_10m,
94
- humidity: relative_humidity_2m,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@dainprotocol/service-sdk": "^1.0.85",
14
+ "@dainprotocol/utils": "^0.0.43",
14
15
  "zod": "^3.23.8",
15
16
  "hono": "^4.6.3",
16
17
  "ts-node": "^10.4.0",
@@ -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}&current=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 ${time.length} hours`,
127
+ text: `Weather forecast for ${locationName} available for the next 24 hours`,
90
128
  data: {
91
- times: time,
92
- temperatures: temperature_2m,
93
- windSpeeds: wind_speed_10m,
94
- humidity: relative_humidity_2m,
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
  },