mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 15:13:23 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
78
openclaw/extensions/device-pair/pair-command-approve.ts
Normal file
78
openclaw/extensions/device-pair/pair-command-approve.ts
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalString,
|
||||
} from "openclaw/plugin-sdk/text-runtime";
|
||||
import { approveDevicePairing, listDevicePairing } from "./api.js";
|
||||
import { formatPendingRequests } from "./notify.js";
|
||||
|
||||
type PendingPairingEntry = Awaited<ReturnType<typeof listDevicePairing>>["pending"][number];
|
||||
type ApprovePairingResult = Awaited<ReturnType<typeof approveDevicePairing>>;
|
||||
type ApprovedPairingEntry = Exclude<ApprovePairingResult, null | { status: "forbidden" }>;
|
||||
type ForbiddenPairingEntry = Extract<ApprovePairingResult, { status: "forbidden" }>;
|
||||
|
||||
function buildMultiplePendingApprovalReply(pending: PendingPairingEntry[]): { text: string } {
|
||||
return {
|
||||
text:
|
||||
`${formatPendingRequests(pending)}\n\n` +
|
||||
"Multiple pending requests found. Approve one explicitly:\n" +
|
||||
"/pair approve <requestId>\n" +
|
||||
"Or approve the most recent:\n" +
|
||||
"/pair approve latest",
|
||||
};
|
||||
}
|
||||
|
||||
export function selectPendingApprovalRequest(params: {
|
||||
pending: PendingPairingEntry[];
|
||||
requested?: string;
|
||||
}): { pending?: PendingPairingEntry; reply?: { text: string } } {
|
||||
if (params.pending.length === 0) {
|
||||
return { reply: { text: "No pending device pairing requests." } };
|
||||
}
|
||||
|
||||
if (!params.requested) {
|
||||
return params.pending.length === 1
|
||||
? { pending: params.pending[0] }
|
||||
: { reply: buildMultiplePendingApprovalReply(params.pending) };
|
||||
}
|
||||
|
||||
if (normalizeLowercaseStringOrEmpty(params.requested) === "latest") {
|
||||
return {
|
||||
pending: [...params.pending].toSorted((a, b) => (b.ts ?? 0) - (a.ts ?? 0))[0],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
pending: params.pending.find((entry) => entry.requestId === params.requested),
|
||||
reply: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function formatApprovedPairingReply(approved: ApprovedPairingEntry): { text: string } {
|
||||
const label = normalizeOptionalString(approved.device.displayName) || approved.device.deviceId;
|
||||
const platform = normalizeOptionalString(approved.device.platform);
|
||||
const platformLabel = platform ? ` (${platform})` : "";
|
||||
return { text: `✅ Paired ${label}${platformLabel}.` };
|
||||
}
|
||||
|
||||
function formatForbiddenPairingRequirement(approved: ForbiddenPairingEntry): string {
|
||||
return approved.scope ?? approved.role ?? "additional approval";
|
||||
}
|
||||
|
||||
export async function approvePendingPairingRequest(params: {
|
||||
requestId: string;
|
||||
callerScopes?: readonly string[];
|
||||
}): Promise<{ text: string }> {
|
||||
const approved =
|
||||
params.callerScopes === undefined
|
||||
? await approveDevicePairing(params.requestId)
|
||||
: await approveDevicePairing(params.requestId, { callerScopes: params.callerScopes });
|
||||
if (!approved) {
|
||||
return { text: "Pairing request not found." };
|
||||
}
|
||||
if (approved.status === "forbidden") {
|
||||
return {
|
||||
text: `⚠️ This command requires ${formatForbiddenPairingRequirement(approved)} to approve this pairing request.`,
|
||||
};
|
||||
}
|
||||
return formatApprovedPairingReply(approved);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue