@dainprotocol/cli 1.2.5 → 1.2.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,15 +10,17 @@
10
10
  "bin": {
11
11
  "dain": "./dist/index.js"
12
12
  },
13
+ "scripts": {
14
+ "build": "tsc && cp -r templates dist/"
15
+ },
13
16
  "files": [
14
17
  "dist",
15
- "templates",
16
18
  "README.md"
17
19
  ],
18
20
  "dependencies": {
19
21
  "@ai-sdk/anthropic": "^0.0.50",
20
- "@dainprotocol/service-sdk": "^1.3.5",
21
- "@dainprotocol/tunnel": "^1.1.5",
22
+ "@dainprotocol/service-sdk": "^2.0.31",
23
+ "@dainprotocol/tunnel": "^1.1.7",
22
24
  "@types/fs-extra": "^11.0.4",
23
25
  "@types/localtunnel": "^2.0.4",
24
26
  "ai": "^3.3.41",
@@ -38,8 +40,5 @@
38
40
  "@types/node": "^22.5.4",
39
41
  "ts-node": "^10.9.2",
40
42
  "typescript": "^5.5.4"
41
- },
42
- "scripts": {
43
- "build": "tsc && cp -r templates dist/"
44
43
  }
45
- }
44
+ }
@@ -1,2 +0,0 @@
1
- DAIN_API_KEY=NEED_TO_BE_SET
2
- PORT=
@@ -1,12 +0,0 @@
1
- {
2
- "project-id": "",
3
- "api-key": "MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY",
4
- "main-file": "src/index.ts",
5
- "static-dir": "static",
6
- "out-dir": "dist",
7
- "environment": "development",
8
- "version": "1.0.0",
9
- "tunnel-base-url": "wss:///tunnel.dain-local.com",
10
- "deployment-id": "",
11
- "service-id": ""
12
- }
@@ -1,24 +0,0 @@
1
- {
2
- "name": "example-dain-project",
3
- "version": "1.0.0",
4
- "description": "A Dain Protocol project",
5
- "main": "src/index.ts",
6
- "scripts": {
7
- "start": "ts-node src/index.ts",
8
- "dev": "dain dev",
9
- "build": "dain build",
10
- "deploy": "dain deploy"
11
- },
12
- "dependencies": {
13
- "@dainprotocol/service-sdk": "^1.0.95",
14
- "@dainprotocol/utils": "^0.0.49",
15
- "zod": "^3.23.8",
16
- "hono": "^4.6.3",
17
- "ts-node": "^10.4.0",
18
- "typescript": "^5.5.4",
19
- "@types/express": "^4.17.13",
20
- "@types/node": "^22.5.4",
21
- "axios": "^1.7.5",
22
- "@dainprotocol/cli": "^1.1.26"
23
- }
24
- }
@@ -1,221 +0,0 @@
1
- //File: example/example-node.ts
2
-
3
- import { z } from "zod";
4
- import axios from "axios";
5
-
6
- import { defineDAINService, ToolConfig } from "@dainprotocol/service-sdk";
7
-
8
- import {
9
- CardUIBuilder,
10
- TableUIBuilder,
11
- MapUIBuilder,
12
- LayoutUIBuilder,
13
- } from "@dainprotocol/utils";
14
-
15
- const port = Number(process.env.PORT) || 2022;
16
-
17
- const getWeatherEmoji = (temperature: number): string => {
18
- if (temperature <= 0) return "🥶";
19
- if (temperature <= 10) return "❄️";
20
- if (temperature <= 20) return "⛅";
21
- if (temperature <= 25) return "☀️";
22
- if (temperature <= 30) return "🌞";
23
- return "🔥";
24
- };
25
-
26
- const getWeatherConfig: ToolConfig = {
27
- id: "get-weather",
28
- name: "Get Weather",
29
- description: "Fetches current weather for a city",
30
- input: z
31
- .object({
32
- locationName: z.string().describe("Location name"),
33
- latitude: z.number().describe("Latitude coordinate"),
34
- longitude: z.number().describe("Longitude coordinate"),
35
- })
36
- .describe("Input parameters for the weather request"),
37
- output: z
38
- .object({
39
- temperature: z.number().describe("Current temperature in Celsius"),
40
- windSpeed: z.number().describe("Current wind speed in km/h"),
41
- })
42
- .describe("Current weather information"),
43
- pricing: { pricePerUse: 0, currency: "USD" },
44
- handler: async (
45
- { locationName, latitude, longitude },
46
- agentInfo,
47
- context
48
- ) => {
49
- console.log(
50
- `User / Agent ${agentInfo.id} requested weather at ${locationName} (${latitude},${longitude})`
51
- );
52
-
53
- const response = await axios.get(
54
- `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,wind_speed_10m`
55
- );
56
-
57
- const { temperature_2m, wind_speed_10m } = response.data.current;
58
- const weatherEmoji = getWeatherEmoji(temperature_2m);
59
-
60
- return {
61
- text: `The current temperature in ${locationName} is ${temperature_2m}°C with wind speed of ${wind_speed_10m} km/h`,
62
- data: {
63
- temperature: temperature_2m,
64
- windSpeed: wind_speed_10m,
65
- },
66
- ui: new CardUIBuilder()
67
- .setRenderMode("page")
68
- .title(`Current Weather in ${locationName} ${weatherEmoji}`)
69
- .addChild(
70
- new MapUIBuilder()
71
- .setInitialView(latitude, longitude, 10)
72
- .setMapStyle("mapbox://styles/mapbox/streets-v12")
73
- .addMarkers([
74
- {
75
- latitude,
76
- longitude,
77
- title: locationName,
78
- description: `Temperature: ${temperature_2m}°C\nWind: ${wind_speed_10m} km/h`,
79
- text: `${locationName} ${weatherEmoji}`,
80
- },
81
- ])
82
- .build()
83
- )
84
- .content(
85
- `Temperature: ${temperature_2m}°C\nWind Speed: ${wind_speed_10m} km/h`
86
- )
87
- .build(),
88
- };
89
- },
90
- };
91
-
92
- const getWeatherForecastConfig: ToolConfig = {
93
- id: "get-weather-forecast",
94
- name: "Get Weather Forecast",
95
- description: "Fetches hourly weather forecast",
96
- input: z
97
- .object({
98
- locationName: z.string().describe("Location name"),
99
- latitude: z.number().describe("Latitude coordinate"),
100
- longitude: z.number().describe("Longitude coordinate"),
101
- })
102
- .describe("Input parameters for the forecast request"),
103
- output: z
104
- .object({
105
- times: z.array(z.string()).describe("Forecast times"),
106
- temperatures: z
107
- .array(z.number())
108
- .describe("Temperature forecasts in Celsius"),
109
- windSpeeds: z.array(z.number()).describe("Wind speed forecasts in km/h"),
110
- humidity: z
111
- .array(z.number())
112
- .describe("Relative humidity forecasts in %"),
113
- })
114
- .describe("Hourly weather forecast"),
115
- pricing: { pricePerUse: 0, currency: "USD" },
116
- handler: async (
117
- { locationName, latitude, longitude },
118
- agentInfo,
119
- context
120
- ) => {
121
- console.log(
122
- `User / Agent ${agentInfo.id} requested forecast at ${locationName} (${latitude},${longitude})`
123
- );
124
-
125
- const response = await axios.get(
126
- `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m`
127
- );
128
-
129
- const { time, temperature_2m, wind_speed_10m, relative_humidity_2m } =
130
- response.data.hourly;
131
-
132
- // Limit to first 24 hours of forecast data
133
- const limitedTime = time.slice(0, 24);
134
- const limitedTemp = temperature_2m.slice(0, 24);
135
- const limitedWind = wind_speed_10m.slice(0, 24);
136
- const limitedHumidity = relative_humidity_2m.slice(0, 24);
137
-
138
- const weatherEmoji = getWeatherEmoji(limitedTemp[0]);
139
-
140
- return {
141
- text: `Weather forecast for ${locationName} available for the next 24 hours`,
142
- data: {
143
- times: limitedTime,
144
- temperatures: limitedTemp,
145
- windSpeeds: limitedWind,
146
- humidity: limitedHumidity,
147
- },
148
- ui: new LayoutUIBuilder()
149
- .setRenderMode("page")
150
- .setLayoutType("column")
151
- .addChild(
152
- new MapUIBuilder()
153
- .setInitialView(latitude, longitude, 10)
154
- .setMapStyle("mapbox://styles/mapbox/streets-v12")
155
- .addMarkers([
156
- {
157
- latitude,
158
- longitude,
159
- title: locationName,
160
- description: `Temperature: ${limitedTemp[0]}°C\nWind: ${limitedWind[0]} km/h`,
161
- text: `${locationName} ${weatherEmoji}`,
162
- },
163
- ])
164
- .build()
165
- )
166
- .addChild(
167
- new TableUIBuilder()
168
- .addColumns([
169
- { key: "time", header: "Time", type: "string" },
170
- {
171
- key: "temperature",
172
- header: "Temperature (°C)",
173
- type: "number",
174
- },
175
- { key: "windSpeed", header: "Wind Speed (km/h)", type: "number" },
176
- { key: "humidity", header: "Humidity (%)", type: "number" },
177
- ])
178
- .rows(
179
- limitedTime.map((t: string, i: number) => ({
180
- time: new Date(t).toLocaleString(),
181
- temperature: limitedTemp[i],
182
- windSpeed: limitedWind[i],
183
- humidity: limitedHumidity[i],
184
- }))
185
- )
186
- .build()
187
- )
188
- .build(),
189
- };
190
- },
191
- };
192
-
193
- const dainService = defineDAINService({
194
- metadata: {
195
- title: "Weather DAIN Service",
196
- description:
197
- "A DAIN service for current weather and forecasts using Open-Meteo API",
198
- version: "1.0.0",
199
- author: "Your Name",
200
- tags: ["weather", "forecast", "dain"],
201
- logo: "https://cdn-icons-png.flaticon.com/512/252/252035.png",
202
- },
203
- exampleQueries: [
204
- {
205
- category: "Weather",
206
- queries: [
207
- "What is the weather in Tokyo?",
208
- "What is the weather in San Francisco?",
209
- "What is the weather in London?",
210
- ],
211
- },
212
- ],
213
- identity: {
214
- apiKey: process.env.DAIN_API_KEY,
215
- },
216
- tools: [getWeatherConfig, getWeatherForecastConfig],
217
- });
218
-
219
- dainService.startNode({ port: port }).then(({ address }) => {
220
- console.log("Weather DAIN Service is running at :" + address().port);
221
- });
@@ -1,8 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "skipLibCheck": true,
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext"
6
- }
7
- }
8
-