mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-04 02:14:02 +00:00
* refactor: share talk event metric extraction * refactor: reuse shared coercion helpers * refactor: reuse shared primitive guards * refactor: reuse shared record guard * refactor: reuse shared primitive helpers * refactor: reuse shared string guards * refactor: reuse shared non-empty string guard * refactor: share plugin primitive coercion helpers * refactor: reuse plugin coercion helpers * refactor: reuse plugin coercion helpers in more plugins * refactor: reuse channel coercion helpers * refactor: reuse monitor coercion helpers * refactor: reuse provider coercion helpers * refactor: reuse core coercion helpers * refactor: reuse runtime coercion helpers * refactor: reuse helper coercion in codex paths * refactor: reuse helper coercion in runtime paths * refactor: reuse codex app-server coercion helpers * refactor: reuse codex record helpers * refactor: reuse migration and qa record helpers * refactor: reuse feishu and core helper guards * refactor: reuse browser and policy coercion helpers * refactor: reuse memory wiki record helper * refactor: share boolean coercion helpers * refactor: reuse finite number coercion * refactor: reuse trimmed string list helpers * refactor: reuse string list normalization * refactor: reuse remaining string list helpers * refactor: reuse string entry normalizer * refactor: share sorted string helpers * refactor: share string list normalization * test: preserve command registry browser imports * refactor: reuse trimmed list helpers * refactor: reuse string dedupe helpers * refactor: reuse local dedupe helpers * refactor: reuse more string dedupe helpers * refactor: reuse command string dedupe helpers * refactor: dedupe memory path lists with helper * refactor: expose string dedupe helpers to plugins * refactor: reuse core string dedupe helpers * refactor: reuse shared unique value helpers * refactor: reuse unique helpers in agent utilities * refactor: reuse unique helpers in config plumbing * refactor: reuse unique helpers in extensions * refactor: reuse unique helpers in core utilities * refactor: reuse unique helpers in qa plugins * refactor: reuse unique helpers in memory plugins * refactor: reuse unique helpers in channel plugins * refactor: reuse unique helpers in core tails * refactor: reuse unique helper in comfy workflow * refactor: reuse unique helpers in test utilities * refactor: expose unique value helper to plugins * refactor: reuse unique helpers for numeric lists * refactor: replace index dedupe filters * refactor: reuse string entry normalization * refactor: reuse string normalization in plugin helpers * refactor: reuse string normalization in extension helpers * refactor: reuse string normalization in channel parsers * refactor: reuse string normalization in memory search * refactor: reuse string normalization in provider parsers * refactor: reuse string normalization in qa helpers * refactor: reuse string normalization in infra parsers * refactor: reuse string normalization in messaging parsers * refactor: reuse string normalization in core parsers * refactor: reuse string normalization in extension parsers * refactor: reuse string normalization in remaining parsers * refactor: reuse string normalization in final parser spots * refactor: reuse string normalization in qa media helpers * refactor: reuse normalization in provider and media lists * refactor: reuse normalization for remaining set filters * refactor: reuse normalization in policy allowlists * refactor: reuse normalization in session and owner lists * refactor: centralize primitive string lists * refactor: reuse lowercase entry helpers * refactor: reuse sorted string helpers * refactor: reuse unique trimmed helpers * refactor: reuse string normalization helpers * refactor: reuse catalog string helpers * refactor: reuse remaining string helpers * refactor: simplify remaining list normalization * refactor: reuse codex auth order normalization * chore: refresh plugin sdk api baseline * fix: make shared string sorting deterministic * chore: refresh plugin sdk api baseline * fix: align host env security ordering
87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { normalizeStringEntries, sortUniqueStrings } from "../shared/string-normalization.js";
|
|
import { resolveEnabledBundledManifestContractPlugins } from "./bundled-manifest-contract-plugins.js";
|
|
import { loadBundledDocumentExtractorEntriesFromDir } from "./document-extractor-public-artifacts.js";
|
|
import type { PluginDocumentExtractorEntry } from "./document-extractor-types.js";
|
|
|
|
function compareExtractors(
|
|
left: PluginDocumentExtractorEntry,
|
|
right: PluginDocumentExtractorEntry,
|
|
): number {
|
|
const leftOrder = left.autoDetectOrder ?? Number.MAX_SAFE_INTEGER;
|
|
const rightOrder = right.autoDetectOrder ?? Number.MAX_SAFE_INTEGER;
|
|
if (leftOrder !== rightOrder) {
|
|
return leftOrder - rightOrder;
|
|
}
|
|
return left.id.localeCompare(right.id) || left.pluginId.localeCompare(right.pluginId);
|
|
}
|
|
|
|
function resolveExplicitAllowedDocumentExtractorPluginIds(params: {
|
|
config?: OpenClawConfig;
|
|
onlyPluginIds?: readonly string[];
|
|
}): string[] | null {
|
|
const allow = params.config?.plugins?.allow;
|
|
if (!Array.isArray(allow) || allow.length === 0) {
|
|
return null;
|
|
}
|
|
const onlyPluginIdSet =
|
|
params.onlyPluginIds && params.onlyPluginIds.length > 0 ? new Set(params.onlyPluginIds) : null;
|
|
const deniedPluginIds = new Set(params.config?.plugins?.deny ?? []);
|
|
const entries = params.config?.plugins?.entries ?? {};
|
|
return sortUniqueStrings(
|
|
normalizeStringEntries(allow)
|
|
.filter((pluginId) => !onlyPluginIdSet || onlyPluginIdSet.has(pluginId))
|
|
.filter((pluginId) => !deniedPluginIds.has(pluginId))
|
|
.filter((pluginId) => entries[pluginId]?.enabled !== false),
|
|
);
|
|
}
|
|
|
|
export function resolvePluginDocumentExtractors(params?: {
|
|
config?: OpenClawConfig;
|
|
workspaceDir?: string;
|
|
env?: NodeJS.ProcessEnv;
|
|
onlyPluginIds?: readonly string[];
|
|
}): PluginDocumentExtractorEntry[] {
|
|
const extractors: PluginDocumentExtractorEntry[] = [];
|
|
const loadErrors: unknown[] = [];
|
|
const explicitAllowedPluginIds = resolveExplicitAllowedDocumentExtractorPluginIds({
|
|
config: params?.config,
|
|
onlyPluginIds: params?.onlyPluginIds,
|
|
});
|
|
const pluginIds =
|
|
explicitAllowedPluginIds ??
|
|
resolveEnabledBundledManifestContractPlugins({
|
|
config: params?.config,
|
|
workspaceDir: params?.workspaceDir,
|
|
env: params?.env,
|
|
onlyPluginIds: params?.onlyPluginIds,
|
|
contract: "documentExtractors",
|
|
compatMode: {
|
|
allowlist: false,
|
|
enablement: "allowlist",
|
|
vitest: true,
|
|
},
|
|
}).map((plugin) => plugin.id);
|
|
for (const pluginId of pluginIds) {
|
|
let loaded: PluginDocumentExtractorEntry[] | null;
|
|
try {
|
|
loaded = loadBundledDocumentExtractorEntriesFromDir({
|
|
dirName: pluginId,
|
|
pluginId,
|
|
});
|
|
} catch (error) {
|
|
loadErrors.push(error);
|
|
continue;
|
|
}
|
|
if (loaded) {
|
|
extractors.push(...loaded);
|
|
}
|
|
}
|
|
if (extractors.length === 0 && loadErrors.length > 0) {
|
|
throw new Error("Unable to load document extractor plugins", {
|
|
cause: loadErrors.length === 1 ? loadErrors[0] : new AggregateError(loadErrors),
|
|
});
|
|
}
|
|
return extractors.toSorted(compareExtractors);
|
|
}
|