mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-28 17:43:05 +00:00
Secrets: fast-path core target discovery
This commit is contained in:
@@ -466,6 +466,10 @@ const CORE_SECRET_TARGET_REGISTRY: SecretTargetRegistryEntry[] = [
|
||||
|
||||
let cachedSecretTargetRegistry: SecretTargetRegistryEntry[] | null = null;
|
||||
|
||||
export function getCoreSecretTargetRegistry(): SecretTargetRegistryEntry[] {
|
||||
return CORE_SECRET_TARGET_REGISTRY;
|
||||
}
|
||||
|
||||
export function getSecretTargetRegistry(): SecretTargetRegistryEntry[] {
|
||||
if (cachedSecretTargetRegistry) {
|
||||
return cachedSecretTargetRegistry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { getPath } from "./path-utils.js";
|
||||
import { getSecretTargetRegistry } from "./target-registry-data.js";
|
||||
import { getCoreSecretTargetRegistry, getSecretTargetRegistry } from "./target-registry-data.js";
|
||||
import {
|
||||
compileTargetRegistryEntry,
|
||||
expandPathTokens,
|
||||
@@ -24,6 +24,12 @@ let compiledSecretTargetRegistryState: {
|
||||
targetsByType: Map<string, CompiledTargetRegistryEntry[]>;
|
||||
} | null = null;
|
||||
|
||||
let compiledCoreOpenClawTargetState: {
|
||||
knownTargetIds: Set<string>;
|
||||
openClawCompiledSecretTargets: CompiledTargetRegistryEntry[];
|
||||
openClawTargetsById: Map<string, CompiledTargetRegistryEntry[]>;
|
||||
} | null = null;
|
||||
|
||||
function buildTargetTypeIndex(
|
||||
compiledSecretTargetRegistry: CompiledTargetRegistryEntry[],
|
||||
): Map<string, CompiledTargetRegistryEntry[]> {
|
||||
@@ -83,6 +89,21 @@ function getCompiledSecretTargetRegistryState() {
|
||||
return compiledSecretTargetRegistryState;
|
||||
}
|
||||
|
||||
function getCompiledCoreOpenClawTargetState() {
|
||||
if (compiledCoreOpenClawTargetState) {
|
||||
return compiledCoreOpenClawTargetState;
|
||||
}
|
||||
const openClawCompiledSecretTargets = getCoreSecretTargetRegistry()
|
||||
.filter((entry) => entry.configFile === "openclaw.json")
|
||||
.map(compileTargetRegistryEntry);
|
||||
compiledCoreOpenClawTargetState = {
|
||||
knownTargetIds: new Set(openClawCompiledSecretTargets.map((entry) => entry.id)),
|
||||
openClawCompiledSecretTargets,
|
||||
openClawTargetsById: buildConfigTargetIdIndex(openClawCompiledSecretTargets),
|
||||
};
|
||||
return compiledCoreOpenClawTargetState;
|
||||
}
|
||||
|
||||
function normalizeAllowedTargetIds(targetIds?: Iterable<string>): Set<string> | null {
|
||||
if (targetIds === undefined) {
|
||||
return null;
|
||||
@@ -281,7 +302,13 @@ export function discoverConfigSecretTargetsByIds(
|
||||
targetIds?: Iterable<string>,
|
||||
): DiscoveredConfigSecretTarget[] {
|
||||
const allowedTargetIds = normalizeAllowedTargetIds(targetIds);
|
||||
const registryState = getCompiledSecretTargetRegistryState();
|
||||
const registryState =
|
||||
allowedTargetIds !== null &&
|
||||
Array.from(allowedTargetIds).every((targetId) =>
|
||||
getCompiledCoreOpenClawTargetState().knownTargetIds.has(targetId),
|
||||
)
|
||||
? getCompiledCoreOpenClawTargetState()
|
||||
: getCompiledSecretTargetRegistryState();
|
||||
const discoveryEntries = resolveDiscoveryEntries({
|
||||
allowedTargetIds,
|
||||
defaultEntries: registryState.openClawCompiledSecretTargets,
|
||||
|
||||
Reference in New Issue
Block a user