@nickyzj2023/ai 1.6.2 → 1.6.3
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/cli.mjs +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{src-DPR9YjB3.mjs → src-Bh2ZFPb4.mjs} +53 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as runAgent, n as get_weather_default, r as get_time_default } from "./src-
|
|
1
|
+
import { i as runAgent, n as get_weather_default, r as get_time_default } from "./src-Bh2ZFPb4.mjs";
|
|
2
2
|
import { a as listModels, t as defineModel } from "./helper-DJw58Gmz.mjs";
|
|
3
3
|
import { n as loadMCPTools } from "./mcp-BBjcb8es.mjs";
|
|
4
4
|
import { compactStr, extractErrorMessage, isObject, to } from "@nickyzj2023/utils";
|
|
@@ -478,7 +478,7 @@ var TUI = class {
|
|
|
478
478
|
printToolResult(name, result, options) {
|
|
479
479
|
const { ellipsis = true } = options ?? {};
|
|
480
480
|
const _result = ellipsis ? compactStr(result, {
|
|
481
|
-
maxLength:
|
|
481
|
+
maxLength: 100,
|
|
482
482
|
truncateMiddle: true
|
|
483
483
|
}) : result;
|
|
484
484
|
this.preparePrint("tool_result");
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as stream, i as runAgent, n as get_weather_default, r as get_time_default, t as compact } from "./src-
|
|
1
|
+
import { a as stream, i as runAgent, n as get_weather_default, r as get_time_default, t as compact } from "./src-Bh2ZFPb4.mjs";
|
|
2
2
|
import { a as listModels, i as estimateTokens, n as defineTool, r as estimateTextTokens, t as defineModel } from "./helper-DJw58Gmz.mjs";
|
|
3
3
|
export { compact, defineModel, defineTool, estimateTextTokens, estimateTokens, get_time_default as getTime, get_weather_default as getWeather, listModels, runAgent, stream };
|
|
@@ -190,12 +190,64 @@ var get_time_default = defineTool("get_time", "查询指定时区的当前时间
|
|
|
190
190
|
});
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/tools/get-weather.ts
|
|
193
|
+
/**
|
|
194
|
+
* 把wttr.in的时间转成好读的"HH:mm"
|
|
195
|
+
* @param rawTime - wttr.in hourly里的time字段,3小时粒度不带冒号,比如"0"、"300"、"1200"
|
|
196
|
+
* @returns 补零后的时间字符串,比如"00:00"、"03:00"、"12:00"
|
|
197
|
+
* @example toHHmm("930") // "09:30"
|
|
198
|
+
*/
|
|
199
|
+
const toHHmm = (rawTime) => {
|
|
200
|
+
const padded = String(rawTime ?? "").padStart(4, "0");
|
|
201
|
+
return `${padded.slice(0, 2)}:${padded.slice(2)}`;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* 精简wttr.in返回的天气数据
|
|
205
|
+
* @param rawData - wttr.in API返回的原始JSON
|
|
206
|
+
* @returns 精简后的天气数据
|
|
207
|
+
*/
|
|
208
|
+
const pickValuableFields = (rawData) => {
|
|
209
|
+
if (!rawData) return null;
|
|
210
|
+
const area = rawData.nearest_area?.[0] || {};
|
|
211
|
+
return {
|
|
212
|
+
location: {
|
|
213
|
+
city: area.areaName?.[0]?.value || "",
|
|
214
|
+
region: area.region?.[0]?.value || "",
|
|
215
|
+
country: area.country?.[0]?.value || "",
|
|
216
|
+
latitude: area.latitude,
|
|
217
|
+
longitude: area.longitude
|
|
218
|
+
},
|
|
219
|
+
forecast: (rawData.weather || []).map((day) => ({
|
|
220
|
+
date: day.date,
|
|
221
|
+
maxTempC: day.maxtempC,
|
|
222
|
+
minTempC: day.mintempC,
|
|
223
|
+
astro: {
|
|
224
|
+
sunrise: day.astronomy?.[0]?.sunrise || "",
|
|
225
|
+
sunset: day.astronomy?.[0]?.sunset || "",
|
|
226
|
+
moonPhase: day.astronomy?.[0]?.moon_phase || ""
|
|
227
|
+
},
|
|
228
|
+
hourly: (day.hourly || []).map((h) => ({
|
|
229
|
+
time: toHHmm(h.time),
|
|
230
|
+
tempC: h.tempC,
|
|
231
|
+
feelsLikeC: h.FeelsLikeC,
|
|
232
|
+
weatherDesc: h.weatherDesc?.[0]?.value || "",
|
|
233
|
+
chanceOfRain: h.chanceofrain,
|
|
234
|
+
precipMM: h.precipMM,
|
|
235
|
+
humidity: h.humidity,
|
|
236
|
+
windSpeedKmph: h.windspeedKmph,
|
|
237
|
+
windDir: h.winddir16Point
|
|
238
|
+
}))
|
|
239
|
+
}))
|
|
240
|
+
};
|
|
241
|
+
};
|
|
193
242
|
var get_weather_default = defineTool("get_weather", "查询指定城市的天气情况", { city: {
|
|
194
243
|
type: "string",
|
|
195
244
|
description: "城市名,如shanghai、tokyo",
|
|
196
245
|
required: true
|
|
197
246
|
} }, async ({ city }) => {
|
|
198
|
-
|
|
247
|
+
const api = fetcher("https://wttr.in", { params: { format: "j1" } });
|
|
248
|
+
const [error, response] = await to(api.get(`/${city}`));
|
|
249
|
+
if (error) return error.message;
|
|
250
|
+
return pickValuableFields(response);
|
|
199
251
|
});
|
|
200
252
|
//#endregion
|
|
201
253
|
//#region src/utils/compact/helper.ts
|