openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
90 lines (89 loc) • 3.4 kB
JavaScript
import { B as isRecord, r as defineStrayPluginEntryConfigMigration } from "./runtime-doctor-migrations-JGL9tD-z.js";
import "./src-CSCqKRHJ.js";
import { c as number, g as unknown, h as union, i as boolean, l as object, o as email, p as string, s as literal, t as _enum } from "./schemas-DkgI5ZNg.js";
import "./string-coerce-runtime-DkwxSzQP.js";
import "./fs-safe-FDj8DqK5.js";
//#region extensions/reef/protocol/encoding.ts
const decoder = new TextDecoder("utf-8", { fatal: true });
//#endregion
//#region extensions/reef/protocol/guard.ts
const GUARD_RULES_MAX_CHARS = 2e3;
//#endregion
//#region extensions/reef/src/config-schema.ts
const HandleSchema = string().regex(/^[a-z0-9][a-z0-9_-]{0,62}$/);
const GuardRuleTextSchema = string().max(GUARD_RULES_MAX_CHARS).regex(/\S/, "rules text must not be blank");
const RelayUrlSchema = string().regex(/^[hH][tT][tT][pP][sS]?:\/\/[^\\/?#@]+\/?$/, "Reef relay URL must be an HTTP(S) origin without credentials, path, query, or hash").url();
const OpenAiOAuthProfileIdSchema = string().regex(/^openai:[^\s:/][^\s/]*$/);
const GuardCommonSchema = {
pinnedModel: string().min(1),
policyVersion: string().min(1),
timeoutMs: number().int().min(100).max(12e4),
rules: object({
outbound: GuardRuleTextSchema.optional(),
inbound: GuardRuleTextSchema.optional()
}).strict().optional()
};
const GuardSchema = union([object({
provider: literal("openai"),
authMode: literal("oauth"),
authProfileId: OpenAiOAuthProfileIdSchema,
...GuardCommonSchema
}).strict(), object({
provider: _enum(["anthropic", "openai"]),
authMode: literal("api-key").optional(),
apiKeyEnv: string().regex(/^[A-Z_][A-Z0-9_]*$/),
...GuardCommonSchema
}).strict()]);
const ReefChannelConfigSchema = object({
enabled: boolean().default(true),
configWrites: boolean().optional(),
relayUrl: RelayUrlSchema.default("https://reefwire.ai"),
handle: HandleSchema.optional(),
email: email().optional(),
guard: GuardSchema.optional(),
stateDir: string().min(1).optional(),
requestPolicy: _enum([
"code-only",
"friends-of-friends",
"open"
]).default("code-only"),
friends: unknown().optional()
}).strict();
//#endregion
//#region extensions/reef/config-doctor-api.ts
function hasRetiredReefPolicyConfig(e) {
return isRecord(e) && ["dmPolicy", "allowFrom"].some((t) => Object.hasOwn(e, t));
}
const reefStrayEntryConfigMigration = defineStrayPluginEntryConfigMigration({
pluginId: "reef",
channelId: "reef",
validateMergedChannelConfig: (e) => ReefChannelConfigSchema.safeParse(e).success
});
const legacyConfigRules = [{
path: ["channels", "reef"],
message: "channels.reef dmPolicy/allowFrom are legacy; run \"openclaw doctor --fix\" to remove them. Peer trust is SQLite-backed.",
match: hasRetiredReefPolicyConfig
}, reefStrayEntryConfigMigration.legacyConfigRule];
function normalizeCompatibilityConfig({ cfg: e }) {
const t = e.channels?.reef;
let n = e;
const r = [];
if (hasRetiredReefPolicyConfig(t)) {
const t = structuredClone(e);
const i = t.channels?.reef;
if (isRecord(i)) {
for (const e of ["dmPolicy", "allowFrom"]) if (Object.hasOwn(i, e)) {
delete i[e];
r.push(`Removed retired Reef ${e} field.`);
}
n = t;
}
}
const i = reefStrayEntryConfigMigration.normalizeConfig({ cfg: n });
return {
config: i.config,
changes: [...r, ...i.changes]
};
}
//#endregion
export { legacyConfigRules, normalizeCompatibilityConfig };