UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

45 lines (44 loc) • 2.08 kB
import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "../../string-coerce-CCIiB4H7.mjs"; import "../../string-coerce-runtime-BwAZZDf5.mjs"; import { n as approveDevicePairing } from "../../device-pairing-approval-QMJvpfTq.mjs"; import "../../api-DI-rMgGh.mjs"; import { n as formatPendingRequests } from "../../notify-BEaR7Zmw.mjs"; //#region extensions/device-pair/pair-command-approve.ts function buildMultiplePendingApprovalReply(e) { return { text: `${formatPendingRequests(e)}\n\nMultiple pending requests found. Approve one explicitly: /pair approve <requestId> Or approve the most recent: /pair approve latest` }; } function selectPendingApprovalRequest(e) { const [t, ...n] = e.pending; if (!t) return { reply: { text: "No pending device pairing requests." } }; if (!e.requested) return n.length === 0 ? { pending: t } : { reply: buildMultiplePendingApprovalReply(e.pending) }; if (normalizeLowercaseStringOrEmpty(e.requested) === "latest") { let e = t; for (const t of n) if ((t.ts ?? 0) > (e.ts ?? 0)) e = t; return { pending: e }; } return { pending: e.pending.find((t) => t.requestId === e.requested) }; } function formatApprovedPairingReply(e) { const t = normalizeOptionalString(e.device.displayName) || e.device.deviceId; const n = normalizeOptionalString(e.device.platform); return { text: `✅ Paired ${t}${n ? ` (${n})` : ""}.` }; } async function approvePendingPairingRequest(e) { const t = e.assertCurrent; const n = t ? () => { t(); return true; } : void 0; const r = e.callerScopes === void 0 && !n ? await approveDevicePairing(e.requestId) : await approveDevicePairing(e.requestId, { callerScopes: e.callerScopes, ...n ? { isApprovalCurrent: n } : {} }); if (!r) return { text: "Pairing request not found." }; if (r.status === "forbidden") return { text: `⚠️ This command requires ${r.scope ?? r.role ?? "additional approval"} to approve this pairing request.` }; return formatApprovedPairingReply(r); } //#endregion export { approvePendingPairingRequest, selectPendingApprovalRequest };