openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 2.01 kB
JavaScript
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { t as isNonEmptyProtocolString } from "./protocol-value-normalization-CXHG8cRQ.mjs";
import { n as PLUGIN_DECLARED_SURFACE_GROUPS } from "./plugin-declared-surface-groups-vgGtKZVv.mjs";
//#region packages/gateway-protocol/src/capability-consent-error-details.ts
const PLUGIN_CAPABILITY_CONSENT_REQUIRED = "PLUGIN_CAPABILITY_CONSENT_REQUIRED";
function hasOnlyKeys(e, t) {
return Object.keys(e).every((e) => t.includes(e));
}
function readDeclaredSurfaceWidening(e) {
const t = asNullableRecord(e);
if (!t || !hasOnlyKeys(t, PLUGIN_DECLARED_SURFACE_GROUPS)) return;
const n = {};
for (const e of PLUGIN_DECLARED_SURFACE_GROUPS) {
const r = t[e];
if (r === void 0) continue;
if (!Array.isArray(r) || !r.every(isNonEmptyProtocolString)) return;
n[e] = r;
}
return n;
}
function buildCapabilityConsentErrorDetails(e) {
return {
capabilityConsentCode: PLUGIN_CAPABILITY_CONSENT_REQUIRED,
...e
};
}
/** Keep the startup-path reader registry-free and preserve wire-significant whitespace. */
function readCapabilityConsentErrorDetails(e) {
const t = asNullableRecord(e);
if (!t || t.capabilityConsentCode !== "PLUGIN_CAPABILITY_CONSENT_REQUIRED" || !hasOnlyKeys(t, [
"capabilityConsentCode",
"pluginId",
"reviewToken",
"widened",
"acceptedAt"
]) || !isNonEmptyProtocolString(t.pluginId) || !isNonEmptyProtocolString(t.reviewToken) || t.acceptedAt !== void 0 && !isNonEmptyProtocolString(t.acceptedAt)) return;
const n = t.widened === void 0 ? void 0 : readDeclaredSurfaceWidening(t.widened);
if (t.widened !== void 0 && !n) return;
return {
capabilityConsentCode: PLUGIN_CAPABILITY_CONSENT_REQUIRED,
pluginId: t.pluginId,
reviewToken: t.reviewToken,
...n ? { widened: n } : {},
...t.acceptedAt !== void 0 ? { acceptedAt: t.acceptedAt } : {}
};
}
//#endregion
export { buildCapabilityConsentErrorDetails as n, readCapabilityConsentErrorDetails as r, PLUGIN_CAPABILITY_CONSENT_REQUIRED as t };