limixbot 0.3.90 → 0.3.92
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/assets/{ActivityPanel-BFVHhWfW.js → ActivityPanel-CDjH1GU1.js} +1 -1
- package/dist/assets/{App-ebyARhWm.js → App-E4S2Izkf.js} +8 -8
- package/dist/assets/{AppEventEditor-BaMtFFYn.js → AppEventEditor-Doqqh7_C.js} +1 -1
- package/dist/assets/{BotSettingsDialog-E1PsetW2.js → BotSettingsDialog-BTZzKynL.js} +1 -1
- package/dist/assets/{BrowserPanel-C_xdt1Lx.js → BrowserPanel-Bb2e3egY.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-DBTheINN.js → BrowserProfilesManager-DzxzkZWW.js} +1 -1
- package/dist/assets/{CloudAddDialog-DJoAwrjq.js → CloudAddDialog-D9KV1a1D.js} +1 -1
- package/dist/assets/{ComputerFilesPane-BvpZo6wZ.js → ComputerFilesPane-CDB3RDwR.js} +1 -1
- package/dist/assets/{ComputerPanel-Dgr_i8Se.js → ComputerPanel-BA-mtqXF.js} +2 -2
- package/dist/assets/{DataPanel-9oXXtKQ8.js → DataPanel-C3OrzR_f.js} +1 -1
- package/dist/assets/{FilesView-VL_AghEZ.js → FilesView-DIYwTqth.js} +1 -1
- package/dist/assets/{GrokMoveDialog-D_KhklQ7.js → GrokMoveDialog-O-S4WG4h.js} +1 -1
- package/dist/assets/{InspectorPanel-BlynAXqy.js → InspectorPanel-BxEpmTyY.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-CPmUUp9_.js → KeyboardShortcutsModal-Y7Okkmh2.js} +1 -1
- package/dist/assets/{LiveDesktop-DjvsKBfs.js → LiveDesktop-DtXvjAg7.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-BKKIDrMj.js → LocalVmWorkspace-DmAaQ1iu.js} +1 -1
- package/dist/assets/{MacLocalControl-DV0mXhw9.js → MacLocalControl-DH5hm73q.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-Dsfs-P3l.js → MarkdownFilePreview-C_CQe8gj.js} +1 -1
- package/dist/assets/{NewBotDialog-DhuIRAiH.js → NewBotDialog-DV_QAXX1.js} +1 -1
- package/dist/assets/{PhoneAppDialog-CusQrifd.js → PhoneAppDialog-C66WHgKR.js} +1 -1
- package/dist/assets/{PluginsPanel-Dvlh2Sp8.js → PluginsPanel-BFAG0622.js} +1 -1
- package/dist/assets/{ProIntroduction-tmqCvqKh.js → ProIntroduction-CSHL4AjY.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-C_15ubIm.js → RemoteAgentSettingsPanel-OhhZ2dpn.js} +1 -1
- package/dist/assets/{RoomPanel-DMNh3sP5.js → RoomPanel-rM1GifxZ.js} +1 -1
- package/dist/assets/{RoutinesPage-CGM-lmJU.js → RoutinesPage-DfGg08tA.js} +1 -1
- package/dist/assets/{SettingsModal-NKTId0y_.js → SettingsModal-CaL-ALcB.js} +1 -1
- package/dist/assets/{ShareTeamDialog-kebvHKII.js → ShareTeamDialog-DvUjWwuU.js} +1 -1
- package/dist/assets/{SignedInSites-DMVs-F0X.js → SignedInSites-BXdscJ8L.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-CMpbb9QE.js → TeamLibraryPanel-C86g2tBN.js} +1 -1
- package/dist/assets/{TeamMapPage-2vSbbtUT.js → TeamMapPage-9hktKZ3B.js} +1 -1
- package/dist/assets/{TriggersPage-DxA2opyS.js → TriggersPage-B8MRIz1c.js} +1 -1
- package/dist/assets/{VisibilitySection-CBdYeTae.js → VisibilitySection-dDDM9MaH.js} +1 -1
- package/dist/assets/{WebhookTrigger-PAioK3GG.js → WebhookTrigger-DTI3cXoD.js} +1 -1
- package/dist/assets/{WorksOnGrid-DCjH3qb2.js → WorksOnGrid-CY-QtahV.js} +1 -1
- package/dist/assets/{core-BzgXwkM2.js → core-Bq5QXOuI.js} +1 -1
- package/dist/assets/{import-name-BSgMML8r.js → import-name-JpzGxW-s.js} +1 -1
- package/dist/assets/{index-BlBJTHwo.js → index-D40WrEpv.js} +1 -1
- package/dist/assets/{index-CjSnItNh.js → index-d0ffDpU-.js} +2 -2
- package/dist/assets/{mcp-servers-BlPvMIWD.js → mcp-servers-G2gJkOfh.js} +1 -1
- package/dist/assets/{new-bot-CYO0MYja.js → new-bot-CZIVY-7R.js} +1 -1
- package/dist/assets/{org-library-cgtdvD8N.js → org-library-CeikvdR1.js} +1 -1
- package/dist/assets/{package-format-C8ZeOB1J.js → package-format-UYYOWJv2.js} +1 -1
- package/dist/assets/{remote-desktop-panel-BEbc3T2U.js → remote-desktop-panel-BQKl1P-P.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/index.js +83 -69
- package/dist-server/package.json +1 -1
- package/dist-server/server/bot-api-host.js +6 -2
- package/dist-server/server/bot-api.js +3 -1
- package/dist-server/server/bot-channels/engine.js +21 -1
- package/dist-server/server/wait-probes.js +3 -3
- package/dist-server/server/zalo-public-lookup.js +107 -0
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { redactSecretsInText } from "../shared/redact.js";
|
|
3
|
+
import { fetchPublicPage, pageText } from "./wait-probes.js";
|
|
4
|
+
const WEATHER = /(?:thời tiết|nhiệt độ|weather|temperature)/iu;
|
|
5
|
+
const SEARCH = /\?|(?:tra cứu|tra giúp|tìm giúp|tìm trên web|là gì|ai là|ở đâu|khi nào|bao nhiêu|hôm nay|mới nhất|hiện nay)|\b(?:search|look up|what|where|when|who|latest|today)\b/iu;
|
|
6
|
+
const PLACE = /^[\p{L}\p{M} .,'’()-]{2,100}$/u;
|
|
7
|
+
const PRIVATE_QUERY = /https?:\/\/|\bBearer\s+[\w.-]+|\b[\w.+-]+@[\w.-]+\.[a-z]{2,}\b|(?<!\d)\+?\d(?:[ .()-]*\d){8,14}(?!\d)/iu;
|
|
8
|
+
const MAX_QUERY = 300;
|
|
9
|
+
const REQUEST = { maxRedirects: 0, timeoutMs: 4_000, maxBytes: 128 * 1024, userAgent: "LimixBot (https://limixmedia.com)" };
|
|
10
|
+
const NO_RESULTS = '{"status":"no_usable_results"}';
|
|
11
|
+
const ASK_PLACE = '{"status":"weather_location_required"}';
|
|
12
|
+
const geographicPages = z.object({ query: z.object({ pages: z.array(z.object({ title: z.string(), coordinates: z.array(z.object({
|
|
13
|
+
lat: z.number().min(-90).max(90), lon: z.number().min(-180).max(180),
|
|
14
|
+
})).optional() })) }).optional() });
|
|
15
|
+
const forecast = z.object({ properties: z.object({ timeseries: z.array(z.object({ time: z.string(), data: z.object({
|
|
16
|
+
instant: z.object({ details: z.object({ air_temperature: z.number() }) }),
|
|
17
|
+
}) })).min(1) }) });
|
|
18
|
+
const encyclopedia = z.object({ query: z.object({ search: z.array(z.object({ title: z.string(), pageid: z.number(), snippet: z.string() })) }).optional() });
|
|
19
|
+
const weatherCache = new Map();
|
|
20
|
+
function publicQuery(value) {
|
|
21
|
+
const query = value.trim().replace(/\s+/gu, " ");
|
|
22
|
+
if (!query || query.length > MAX_QUERY || PRIVATE_QUERY.test(query) || redactSecretsInText(query) !== query)
|
|
23
|
+
return null;
|
|
24
|
+
return query;
|
|
25
|
+
}
|
|
26
|
+
function weatherPlace(query) {
|
|
27
|
+
return query.replace(/^(?:(?:xem|tra cứu|tra|kiểm tra|check)\s+)?(?:thời tiết|nhiệt độ|weather|temperature)\s*/iu, "")
|
|
28
|
+
.replace(/(?:hôm nay|bây giờ|hiện tại|bao nhiêu(?: độ)?|today|now)(?=\s|[?!,.]|$)/giu, "")
|
|
29
|
+
.replace(/^\s*(?:ở|tại|in|of)\s+/iu, "").replace(/[?!]+$/u, "").trim();
|
|
30
|
+
}
|
|
31
|
+
function samePlace(value) {
|
|
32
|
+
return value.normalize("NFD").replace(/[^\p{L}\p{N}]/gu, "").toLowerCase();
|
|
33
|
+
}
|
|
34
|
+
function wikipedia(lang, params) {
|
|
35
|
+
const url = new URL(`https://${lang}.wikipedia.org/w/api.php`);
|
|
36
|
+
url.search = new URLSearchParams({ action: "query", format: "json", formatversion: "2", ...params }).toString();
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
async function currentTemperature(place) {
|
|
40
|
+
if (!PLACE.test(place))
|
|
41
|
+
return ASK_PLACE;
|
|
42
|
+
const key = samePlace(place);
|
|
43
|
+
const cache = weatherCache.get(key);
|
|
44
|
+
if (cache && cache.expires > Date.now())
|
|
45
|
+
return cache.value;
|
|
46
|
+
const url = wikipedia("vi", { generator: "search", gsrsearch: place, gsrlimit: "6", prop: "coordinates" });
|
|
47
|
+
const received = await fetchPublicPage(url.href, REQUEST);
|
|
48
|
+
if (!received.ok)
|
|
49
|
+
return NO_RESULTS;
|
|
50
|
+
const parsed = geographicPages.safeParse(JSON.parse(received.body.toString("utf8")));
|
|
51
|
+
const match = parsed.success && parsed.data.query?.pages.find(({ title, coordinates }) => samePlace(title) === key && coordinates?.length);
|
|
52
|
+
if (!match)
|
|
53
|
+
return ASK_PLACE;
|
|
54
|
+
const point = match.coordinates[0];
|
|
55
|
+
const weather = new URL("https://api.met.no/weatherapi/locationforecast/2.0/compact");
|
|
56
|
+
weather.search = new URLSearchParams({ lat: point.lat.toFixed(4), lon: point.lon.toFixed(4) }).toString();
|
|
57
|
+
const report = await fetchPublicPage(weather.href, REQUEST);
|
|
58
|
+
if (!report.ok)
|
|
59
|
+
return NO_RESULTS;
|
|
60
|
+
const latest = forecast.safeParse(JSON.parse(report.body.toString("utf8")));
|
|
61
|
+
if (!latest.success)
|
|
62
|
+
return NO_RESULTS;
|
|
63
|
+
const now = latest.data.properties.timeseries[0];
|
|
64
|
+
const value = JSON.stringify({ place: match.title, temperatureC: now.data.instant.details.air_temperature,
|
|
65
|
+
forecastTime: now.time, source: "https://www.met.no/en", locationSource: `https://vi.wikipedia.org/wiki/${encodeURIComponent(match.title.replaceAll(" ", "_"))}` });
|
|
66
|
+
const expires = Date.parse(String(report.headers.expires ?? ""));
|
|
67
|
+
if (expires > Date.now()) {
|
|
68
|
+
if (weatherCache.size >= 128)
|
|
69
|
+
weatherCache.delete(weatherCache.keys().next().value);
|
|
70
|
+
weatherCache.set(key, { expires, value });
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
async function searchWeb(query) {
|
|
75
|
+
const lang = /[\p{M}đĐ]/u.test(query.normalize("NFD")) ? "vi" : "en";
|
|
76
|
+
const topic = query.replace(/^(?:tra cứu|tra giúp|tìm giúp|search for|look up)\s+/iu, "")
|
|
77
|
+
.replace(/\s+là gì[?!.]*$/iu, "").replace(/^what is\s+/iu, "").replace(/[?!.]+$/u, "");
|
|
78
|
+
if (!topic)
|
|
79
|
+
return NO_RESULTS;
|
|
80
|
+
const url = wikipedia(lang, { list: "search", srsearch: topic, srlimit: "5" });
|
|
81
|
+
const page = await fetchPublicPage(url.href, REQUEST);
|
|
82
|
+
if (!page.ok)
|
|
83
|
+
return NO_RESULTS;
|
|
84
|
+
const report = encyclopedia.safeParse(JSON.parse(page.body.toString("utf8")));
|
|
85
|
+
const results = report.success ? report.data.query?.search.slice(0, 5).map((entry) => ({
|
|
86
|
+
title: entry.title.slice(0, 160), summary: pageText(entry.snippet).replace(/\s+([,.!?;:])/gu, "$1").slice(0, 360),
|
|
87
|
+
url: `https://${lang}.wikipedia.org/?curid=${entry.pageid}`,
|
|
88
|
+
})) ?? [] : [];
|
|
89
|
+
return results.length ? JSON.stringify(results) : NO_RESULTS;
|
|
90
|
+
}
|
|
91
|
+
export async function zaloPublicLookup(text, previousGuestText) {
|
|
92
|
+
const query = publicQuery(text);
|
|
93
|
+
if (!query)
|
|
94
|
+
return undefined;
|
|
95
|
+
try {
|
|
96
|
+
if (WEATHER.test(query) && !/(?:ngày mai|tomorrow|tuần sau|next week)/iu.test(query))
|
|
97
|
+
return await currentTemperature(weatherPlace(query));
|
|
98
|
+
if (previousGuestText && WEATHER.test(previousGuestText) && !SEARCH.test(query) && PLACE.test(query))
|
|
99
|
+
return await currentTemperature(query);
|
|
100
|
+
if (SEARCH.test(query))
|
|
101
|
+
return await searchWeb(query);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return NO_RESULTS;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|