UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

150 lines (149 loc) • 6.84 kB
import "./logger-kwZIqwuw.js"; import "./paths-ViKUYWUK.js"; import "./tmp-openclaw-dir-idKIOMmb.js"; import { r as theme } from "./theme-CdOoMzRk.js"; import "./globals-DBUMOBZ8.js"; import { m as defaultRuntime } from "./subsystem-DISldKSB.js"; import "./ansi-BEJF8NKS.js"; import "./boolean-C3GkJetE.js"; import "./env-Dnra1IpT.js"; import "./utils-CS0Ikux6.js"; import { t as formatDocsLink } from "./links-8xRhWBQL.js"; import "./agent-scope-bjWqU22i.js"; import "./boundary-path-Dm0QJ7-y.js"; import "./boundary-file-read-DcZxlWD8.js"; import "./logger-BmpSCz93.js"; import "./exec-B5_AYfQG.js"; import "./workspace-D4K6QX9X.js"; import "./model-selection-BnFtDmP7.js"; import { s as loadConfig } from "./io-y3Az_Onx.js"; import "./shell-env-BOu7XeT_.js"; import "./safe-text-yavot2qw.js"; import "./version-CD3oP1-d.js"; import "./env-substitution-O6uabUmO.js"; import "./includes-Bj3eLUWH.js"; import "./zod-schema.providers-core-COy5nBQ0.js"; import "./legacy-web-search-BB-ZHEhz.js"; import "./registry-C5UkPpaO.js"; import "./config-state-Br0ucqMb.js"; import "./min-host-version-RMBWtIAR.js"; import "./manifest-registry-B5JNQdOM.js"; import "./runtime-guard-PhQ6PwQa.js"; import "./avatar-policy-B5nOfso_.js"; import "./ip-Ce8EDTBZ.js"; import "./zod-schema.agent-runtime-Dtg4Jy6G.js"; import "./zod-schema.core-BuVz8Rk7.js"; import "./config-D4zN4BRl.js"; import "./file-lock-DEiVq2ow.js"; import { t as formatCliCommand } from "./command-format-DBQUhADm.js"; import "./runtime-Iz8uZ7EU.js"; import { l as normalizeChannelId } from "./plugins-B09-vgme.js"; import { i as listChannelPairingRequests, m as notifyPairingApproved, n as approveChannelPairingCode, p as listPairingChannels } from "./pairing-store-BGKLrjo6.js"; import "./json-store--JDX3zNL.js"; import { t as resolvePairingIdLabel } from "./pairing-labels-D27Y4Vv6.js"; import { n as renderTable, t as getTerminalTableWidth } from "./table-7g_hocqO.js"; //#region src/cli/pairing-cli.ts /** Parse channel, allowing extension channels not in core registry. */ function parseChannel(raw, channels) { const value = (typeof raw === "string" ? raw : typeof raw === "number" || typeof raw === "boolean" ? String(raw) : "").trim().toLowerCase(); if (!value) throw new Error("Channel required"); const normalized = normalizeChannelId(value); if (normalized) { if (!channels.includes(normalized)) throw new Error(`Channel ${normalized} does not support pairing`); return normalized; } if (/^[a-z][a-z0-9_-]{0,63}$/.test(value)) return value; throw new Error(`Invalid channel: ${value}`); } async function notifyApproved(channel, id) { await notifyPairingApproved({ channelId: channel, id, cfg: loadConfig() }); } function registerPairingCli(program) { const channels = listPairingChannels(); const pairing = program.command("pairing").description("Secure DM pairing (approve inbound requests)").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/pairing", "docs.openclaw.ai/cli/pairing")}\n`); pairing.command("list").description("List pending pairing requests").option("--channel <channel>", `Channel (${channels.join(", ")})`).option("--account <accountId>", "Account id (for multi-account channels)").argument("[channel]", `Channel (${channels.join(", ")})`).option("--json", "Print JSON", false).action(async (channelArg, opts) => { const channelRaw = opts.channel ?? channelArg ?? (channels.length === 1 ? channels[0] : ""); if (!channelRaw) throw new Error(`Channel required. Use --channel <channel> or pass it as the first argument (expected one of: ${channels.join(", ")})`); const channel = parseChannel(channelRaw, channels); const accountId = String(opts.account ?? "").trim(); const requests = accountId ? await listChannelPairingRequests(channel, process.env, accountId) : await listChannelPairingRequests(channel); if (opts.json) { defaultRuntime.writeJson({ channel, requests }); return; } if (requests.length === 0) { defaultRuntime.log(theme.muted(`No pending ${channel} pairing requests.`)); return; } const idLabel = resolvePairingIdLabel(channel); const tableWidth = getTerminalTableWidth(); defaultRuntime.log(`${theme.heading("Pairing requests")} ${theme.muted(`(${requests.length})`)}`); defaultRuntime.log(renderTable({ width: tableWidth, columns: [ { key: "Code", header: "Code", minWidth: 10 }, { key: "ID", header: idLabel, minWidth: 12, flex: true }, { key: "Meta", header: "Meta", minWidth: 8, flex: true }, { key: "Requested", header: "Requested", minWidth: 12 } ], rows: requests.map((r) => ({ Code: r.code, ID: r.id, Meta: r.meta ? JSON.stringify(r.meta) : "", Requested: r.createdAt })) }).trimEnd()); }); pairing.command("approve").description("Approve a pairing code and allow that sender").option("--channel <channel>", `Channel (${channels.join(", ")})`).option("--account <accountId>", "Account id (for multi-account channels)").argument("<codeOrChannel>", "Pairing code (or channel when using 2 args)").argument("[code]", "Pairing code (when channel is passed as the 1st arg)").option("--notify", "Notify the requester on the same channel", false).action(async (codeOrChannel, code, opts) => { const defaultChannel = channels.length === 1 ? channels[0] : ""; const usingExplicitChannel = Boolean(opts.channel); const hasPositionalCode = code != null; const channelRaw = usingExplicitChannel ? opts.channel : hasPositionalCode ? codeOrChannel : defaultChannel; const resolvedCode = usingExplicitChannel ? codeOrChannel : hasPositionalCode ? code : codeOrChannel; if (!channelRaw || !resolvedCode) throw new Error(`Usage: ${formatCliCommand("openclaw pairing approve <channel> <code>")} (or: ${formatCliCommand("openclaw pairing approve --channel <channel> <code>")})`); if (opts.channel && code != null) throw new Error(`Too many arguments. Use: ${formatCliCommand("openclaw pairing approve --channel <channel> <code>")}`); const channel = parseChannel(channelRaw, channels); const accountId = String(opts.account ?? "").trim(); const approved = accountId ? await approveChannelPairingCode({ channel, code: String(resolvedCode), accountId }) : await approveChannelPairingCode({ channel, code: String(resolvedCode) }); if (!approved) throw new Error(`No pending pairing request found for code: ${String(resolvedCode)}`); defaultRuntime.log(`${theme.success("Approved")} ${theme.muted(channel)} sender ${theme.command(approved.id)}.`); if (!opts.notify) return; await notifyApproved(channel, approved.id).catch((err) => { defaultRuntime.log(theme.warn(`Failed to notify requester: ${String(err)}`)); }); }); } //#endregion export { registerPairingCli };