mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
Gateway/CLI: add paired-device remove and clear flows (#20057)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 26523f8a38
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
This commit is contained in:
@@ -14,6 +14,8 @@ type DevicesRpcOpts = {
|
||||
timeout?: string;
|
||||
json?: boolean;
|
||||
latest?: boolean;
|
||||
yes?: boolean;
|
||||
pending?: boolean;
|
||||
device?: string;
|
||||
role?: string;
|
||||
scope?: string[];
|
||||
@@ -180,6 +182,86 @@ export function registerDevicesCli(program: Command) {
|
||||
}),
|
||||
);
|
||||
|
||||
devicesCallOpts(
|
||||
devices
|
||||
.command("remove")
|
||||
.description("Remove a paired device entry")
|
||||
.argument("<deviceId>", "Paired device id")
|
||||
.action(async (deviceId: string, opts: DevicesRpcOpts) => {
|
||||
const trimmed = deviceId.trim();
|
||||
if (!trimmed) {
|
||||
defaultRuntime.error("deviceId is required");
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
const result = await callGatewayCli("device.pair.remove", opts, { deviceId: trimmed });
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(`${theme.warn("Removed")} ${theme.command(trimmed)}`);
|
||||
}),
|
||||
);
|
||||
|
||||
devicesCallOpts(
|
||||
devices
|
||||
.command("clear")
|
||||
.description("Clear paired devices from the gateway table")
|
||||
.option("--pending", "Also reject all pending pairing requests", false)
|
||||
.option("--yes", "Confirm destructive clear", false)
|
||||
.action(async (opts: DevicesRpcOpts) => {
|
||||
if (!opts.yes) {
|
||||
defaultRuntime.error("Refusing to clear pairing table without --yes");
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
const list = parseDevicePairingList(await callGatewayCli("device.pair.list", opts, {}));
|
||||
const removedDeviceIds: string[] = [];
|
||||
const rejectedRequestIds: string[] = [];
|
||||
const paired = Array.isArray(list.paired) ? list.paired : [];
|
||||
for (const device of paired) {
|
||||
const deviceId = typeof device.deviceId === "string" ? device.deviceId.trim() : "";
|
||||
if (!deviceId) {
|
||||
continue;
|
||||
}
|
||||
await callGatewayCli("device.pair.remove", opts, { deviceId });
|
||||
removedDeviceIds.push(deviceId);
|
||||
}
|
||||
if (opts.pending) {
|
||||
const pending = Array.isArray(list.pending) ? list.pending : [];
|
||||
for (const req of pending) {
|
||||
const requestId = typeof req.requestId === "string" ? req.requestId.trim() : "";
|
||||
if (!requestId) {
|
||||
continue;
|
||||
}
|
||||
await callGatewayCli("device.pair.reject", opts, { requestId });
|
||||
rejectedRequestIds.push(requestId);
|
||||
}
|
||||
}
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
removedDevices: removedDeviceIds,
|
||||
rejectedPending: rejectedRequestIds,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(
|
||||
`${theme.warn("Cleared")} ${removedDeviceIds.length} paired device${removedDeviceIds.length === 1 ? "" : "s"}`,
|
||||
);
|
||||
if (opts.pending) {
|
||||
defaultRuntime.log(
|
||||
`${theme.warn("Rejected")} ${rejectedRequestIds.length} pending request${rejectedRequestIds.length === 1 ? "" : "s"}`,
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
devicesCallOpts(
|
||||
devices
|
||||
.command("approve")
|
||||
|
||||
Reference in New Issue
Block a user