


























@@ -1,112 +1,20 @@
11import type { OpenClawConfig } from "../config/types.openclaw.js";
2-import {
3-normalizeSortedUniqueStringEntries,
4-normalizeStringEntries,
5-} from "../shared/string-normalization.js";
6-import { isRecord } from "../utils.js";
2+import { normalizeSortedUniqueStringEntries } from "../shared/string-normalization.js";
73import { discoverOpenClawPlugins, type PluginDiscoveryResult } from "./discovery.js";
84import { loadPluginManifestRegistry } from "./manifest-registry.js";
95import type { PluginManifestConfigContracts } from "./manifest.js";
106import type { PluginOrigin } from "./plugin-origin.types.js";
117import { loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry.js";
12-13-export type PluginConfigContractMatch = {
14-path: string;
15-value: unknown;
16-};
8+export {
9+collectPluginConfigContractMatches,
10+type PluginConfigContractMatch,
11+} from "./config-contract-matches.js";
17121813export type PluginConfigContractMetadata = {
1914origin: PluginOrigin;
2015configContracts: PluginManifestConfigContracts;
2116};
221723-type TraversalState = {
24-segments: string[];
25-value: unknown;
26-};
27-28-function normalizePathPattern(pathPattern: string): string[] {
29-return normalizeStringEntries(pathPattern.split("."));
30-}
31-32-function appendPathSegment(path: string, segment: string): string {
33-if (!path) {
34-return segment;
35-}
36-return /^\d+$/.test(segment) ? `${path}[${segment}]` : `${path}.${segment}`;
37-}
38-39-function parseCanonicalArrayIndex(segment: string, length: number): number | null {
40-if (!/^(0|[1-9]\d*)$/.test(segment)) {
41-return null;
42-}
43-const index = Number(segment);
44-return Number.isSafeInteger(index) && index >= 0 && index < length ? index : null;
45-}
46-47-export function collectPluginConfigContractMatches(params: {
48-root: unknown;
49-pathPattern: string;
50-}): PluginConfigContractMatch[] {
51-const pattern = normalizePathPattern(params.pathPattern);
52-if (pattern.length === 0) {
53-return [];
54-}
55-56-let states: TraversalState[] = [{ segments: [], value: params.root }];
57-for (const segment of pattern) {
58-const nextStates: TraversalState[] = [];
59-for (const state of states) {
60-if (segment === "*") {
61-if (Array.isArray(state.value)) {
62-for (const [index, value] of state.value.entries()) {
63-nextStates.push({
64-segments: [...state.segments, String(index)],
65- value,
66-});
67-}
68-continue;
69-}
70-if (isRecord(state.value)) {
71-for (const [key, value] of Object.entries(state.value)) {
72-nextStates.push({
73-segments: [...state.segments, key],
74- value,
75-});
76-}
77-}
78-continue;
79-}
80-if (Array.isArray(state.value)) {
81-const index = parseCanonicalArrayIndex(segment, state.value.length);
82-if (index !== null) {
83-nextStates.push({
84-segments: [...state.segments, segment],
85-value: state.value[index],
86-});
87-}
88-continue;
89-}
90-if (!isRecord(state.value) || !Object.prototype.hasOwnProperty.call(state.value, segment)) {
91-continue;
92-}
93-nextStates.push({
94-segments: [...state.segments, segment],
95-value: state.value[segment],
96-});
97-}
98-states = nextStates;
99-if (states.length === 0) {
100-break;
101-}
102-}
103-104-return states.map((state) => ({
105-path: state.segments.reduce(appendPathSegment, ""),
106-value: state.value,
107-}));
108-}
109-11018export function resolvePluginConfigContractsById(params: {
11119config?: OpenClawConfig;
11220workspaceDir?: string;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。