mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-03 00:01:32 +00:00
* feat(ui): manage DM pairing requests * fix(ui): clear pairing data across auth changes * test(ui): tighten pairing page fixture type * fix(gateway): complete pairing protocol contracts * fix(ui): guard pairing mutations across epochs * fix(ui): restore chat teardown gates * fix(ui): isolate channel auth lifecycles * fix(ui): remove stale chat view export
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
// Shared first-owner bootstrap for DM pairing approval surfaces.
|
|
import {
|
|
formatCommandOwnerFromChannelSender,
|
|
hasConfiguredCommandOwners,
|
|
} from "../commands/doctor-command-owner.js";
|
|
import { readConfigFileSnapshotForWrite, replaceConfigFile } from "../config/config.js";
|
|
import type { PairingChannel } from "./pairing-store.types.js";
|
|
|
|
type PairingCommandOwnerBootstrapResult = {
|
|
ownerEntry: string | null;
|
|
status: "configured" | "already-configured" | "unavailable";
|
|
};
|
|
|
|
/** Adds the approved sender as command owner only when no owner exists yet. */
|
|
export async function bootstrapCommandOwnerFromPairing(params: {
|
|
channel: PairingChannel;
|
|
id: string;
|
|
}): Promise<PairingCommandOwnerBootstrapResult> {
|
|
const ownerEntry = formatCommandOwnerFromChannelSender(params);
|
|
if (!ownerEntry) {
|
|
return { ownerEntry: null, status: "unavailable" };
|
|
}
|
|
|
|
const { snapshot, writeOptions } = await readConfigFileSnapshotForWrite();
|
|
if (hasConfiguredCommandOwners(snapshot.sourceConfig)) {
|
|
return { ownerEntry, status: "already-configured" };
|
|
}
|
|
|
|
const nextConfig = structuredClone(snapshot.sourceConfig);
|
|
nextConfig.commands = {
|
|
...nextConfig.commands,
|
|
ownerAllowFrom: [ownerEntry],
|
|
};
|
|
await replaceConfigFile({
|
|
nextConfig,
|
|
snapshot,
|
|
writeOptions,
|
|
afterWrite: { mode: "auto" },
|
|
});
|
|
return { ownerEntry, status: "configured" };
|
|
}
|