openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
59 lines (58 loc) • 2.48 kB
JavaScript
import { t as dedupeByKey } from "./dedupe-by-key-Cpowmfct.mjs";
import { t as listChannelCatalogEntries } from "./channel-catalog-registry-DPZYoC27.mjs";
import { r as listRawChannelPluginCatalogEntries } from "./catalog-B7x9RZv9.mjs";
import { Option } from "commander";
//#region src/channels/plugins/cli-add-options.ts
function channelCliOptionSwitchKey(e) {
const t = new Option(e);
return t.long ?? t.short ?? t.flags;
}
function compareChannels(e, t) {
const n = e.order ?? Number.MAX_SAFE_INTEGER;
const r = t.order ?? Number.MAX_SAFE_INTEGER;
return n === r ? (e.id ?? "").localeCompare(t.id ?? "") : n - r;
}
function channelSetupOptions(e) {
if (e.setup) return e.setup.fields.map((e) => e.cli);
return [...e.cliAddOptions ?? []];
}
function resolveChannelSetupCliOptionMetadata(e, t = {}) {
const n = listChannelCatalogEntries({ origin: "bundled" }).map((e) => e.channel).toSorted(compareChannels);
const r = listRawChannelPluginCatalogEntries({
excludeWorkspace: true,
excludeOrigins: ["bundled"]
}).flatMap((e) => e.channel ? [e.channel] : []).toSorted(compareChannels);
const i = [...n, ...r];
const a = e?.trim().toLowerCase();
const o = a ? i.find((e) => e.id?.toLowerCase() === a) ?? i.find((e) => e.aliases?.some((e) => e.toLowerCase() === a)) : void 0;
const s = (t.includeAll ? i : o ? [o] : []).flatMap(channelSetupOptions);
const c = dedupeByKey(s, (e) => channelCliOptionSwitchKey(e.flags));
const l = /* @__PURE__ */ new Map();
if (o && !o.setup) for (const e of o.cliAddOptions ?? []) {
if (!e.valueType) continue;
const t = new Option(e.flags);
l.set(t.attributeName(), {
longFlag: t.long ?? e.flags,
valueType: e.valueType
});
}
return {
options: c,
optionCandidates: s,
selectedChannel: o,
valueMetadataByAttributeName: l
};
}
/**
* True only when a selected channel resolved and its registered option set leaves
* `--use-env` out: core adds that flag to the legacy option list, while a channel
* publishing its own `setup` contract has to declare the matching field. Unselected
* and unknown ids stay false so the generic advice is untouched for them.
*/
function channelOmitsEnvBackedSetupOption(e) {
const { selectedChannel: t } = resolveChannelSetupCliOptionMetadata(e);
if (!t?.setup) return false;
return !t.setup.fields.some((e) => channelCliOptionSwitchKey(e.cli.flags) === "--use-env");
}
//#endregion
export { resolveChannelSetupCliOptionMetadata as n, channelOmitsEnvBackedSetupOption as t };