UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

88 lines (87 loc) • 2.85 kB
import { c as asFiniteNumberInRange } from "./number-coercion-D6u-4YD8.mjs"; //#region src/channels/location.ts function readOptionalLocationText(e, t) { if (e === void 0) return; if (typeof e !== "string" || !e.trim()) throw new Error(`${t} must be a non-empty string.`); return e.trim(); } /** Normalize a portable location payload at an outbound/plugin boundary. */ function normalizeOutboundLocation(e, t = "location") { if (e == null) return; if (typeof e !== "object" || Array.isArray(e)) throw new Error(`${t} must be an object.`); const n = e; const r = n.latitude; const i = n.longitude; const a = asFiniteNumberInRange(r, { min: -90, max: 90 }); if (a === void 0) throw new Error(`${t}.latitude must be a finite number between -90 and 90.`); const o = asFiniteNumberInRange(i, { min: -180, max: 180 }); if (o === void 0) throw new Error(`${t}.longitude must be a finite number between -180 and 180.`); const s = n.accuracy; const c = asFiniteNumberInRange(s, { min: 0, max: 1500 }); if (s !== void 0 && c === void 0) throw new Error(`${t}.accuracy must be a finite number between 0 and 1500.`); for (const e of [ "source", "isLive", "caption" ]) if (n[e] !== void 0) throw new Error(`${t}.${e} is not supported for outbound locations.`); const l = readOptionalLocationText(n.name, `${t}.name`); const u = readOptionalLocationText(n.address, `${t}.address`); return { latitude: a, longitude: o, ...c !== void 0 ? { accuracy: c } : {}, ...l ? { name: l } : {}, ...u ? { address: u } : {} }; } function resolveLocation(e) { const t = e.source ?? (e.isLive ? "live" : e.name || e.address ? "place" : "pin"); const n = e.isLive ?? t === "live"; return { ...e, source: t, isLive: n }; } function formatAccuracy(e) { if (!Number.isFinite(e)) return ""; return ` ±${Math.round(e ?? 0)}m`; } /** * Formats the safe inline location body shown to the model. * * Channel-provided labels, addresses, and captions are intentionally excluded * here; `toLocationContext` carries them into the untrusted metadata block. */ function formatLocationText(e) { const t = resolveLocation(e); const n = `${t.latitude.toFixed(6)}, ${t.longitude.toFixed(6)}`; const r = formatAccuracy(t.accuracy); if (t.source === "live" || t.isLive) return `🛰 Live location: ${n}${r}`; return `📍 ${n}${r}`; } /** Converts a normalized location into template context fields for prompt metadata. */ function toLocationContext(e) { const t = resolveLocation(e); return { LocationLat: t.latitude, LocationLon: t.longitude, LocationAccuracy: t.accuracy, LocationName: t.name, LocationAddress: t.address, LocationSource: t.source, LocationIsLive: t.isLive, LocationCaption: t.caption }; } //#endregion export { normalizeOutboundLocation as n, toLocationContext as r, formatLocationText as t };