openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
57 lines (56 loc) • 1.97 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
//#region packages/gateway-protocol/src/install-policy-warning-error-details.ts
const INSTALL_POLICY_WARNING_ACKNOWLEDGEMENT_REQUIRED = "install_policy_warning_acknowledgement_required";
function readFinding(e) {
const t = asNullableRecord(e);
if (!t) return;
const n = normalizeOptionalString(t.ruleId);
const r = normalizeOptionalString(t.message);
const i = t.severity;
if (!n || !r || i !== "info" && i !== "warn" && i !== "critical") return;
const a = i;
const o = normalizeOptionalString(t.file);
const s = normalizeOptionalString(t.evidence);
const c = t.line;
if (t.file !== void 0 && !o || t.evidence !== void 0 && !s || c !== void 0 && (typeof c !== "number" || !Number.isSafeInteger(c) || c <= 0)) return;
return {
ruleId: n,
severity: a,
message: r,
...o ? { file: o } : {},
...c !== void 0 ? { line: c } : {},
...s ? { evidence: s } : {}
};
}
function readInstallPolicyWarningErrorDetails(e) {
const t = asNullableRecord(e);
if (!t) return;
const n = normalizeOptionalString(t.targetName);
const r = normalizeOptionalString(t.reason);
const i = t.targetType;
const a = t.requestMode;
if (t.installPolicyCode !== "install_policy_warning_acknowledgement_required" || !n || !r || i !== "skill" && i !== "plugin" || a !== "install" && a !== "update") return;
const o = i;
const s = a;
let c;
if (t.findings !== void 0) {
if (!Array.isArray(t.findings)) return;
c = [];
for (const e of t.findings) {
const t = readFinding(e);
if (!t) return;
c.push(t);
}
}
return {
installPolicyCode: INSTALL_POLICY_WARNING_ACKNOWLEDGEMENT_REQUIRED,
targetName: n,
targetType: o,
requestMode: s,
reason: r,
...c ? { findings: c } : {}
};
}
//#endregion
export { readInstallPolicyWarningErrorDetails as n, INSTALL_POLICY_WARNING_ACKNOWLEDGEMENT_REQUIRED as t };