mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:18:28 +00:00
refactor(shared): reuse runtime entry requirement evaluator
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { evaluateEntryMetadataRequirements } from "../shared/entry-status.js";
|
import { evaluateEntryMetadataRequirementsForCurrentPlatform } from "../shared/entry-status.js";
|
||||||
import type { RequirementConfigCheck, Requirements } from "../shared/requirements.js";
|
import type { RequirementConfigCheck, Requirements } from "../shared/requirements.js";
|
||||||
import { CONFIG_DIR } from "../utils.js";
|
import { CONFIG_DIR } from "../utils.js";
|
||||||
import {
|
import {
|
||||||
@@ -179,27 +179,29 @@ function buildSkillStatus(
|
|||||||
const allowBundled = resolveBundledAllowlist(config);
|
const allowBundled = resolveBundledAllowlist(config);
|
||||||
const blockedByAllowlist = !isBundledSkillAllowed(entry, allowBundled);
|
const blockedByAllowlist = !isBundledSkillAllowed(entry, allowBundled);
|
||||||
const always = entry.metadata?.always === true;
|
const always = entry.metadata?.always === true;
|
||||||
|
const isEnvSatisfied = (envName: string) =>
|
||||||
|
Boolean(
|
||||||
|
process.env[envName] ||
|
||||||
|
skillConfig?.env?.[envName] ||
|
||||||
|
(skillConfig?.apiKey && entry.metadata?.primaryEnv === envName),
|
||||||
|
);
|
||||||
|
const isConfigSatisfied = (pathStr: string) => isConfigPathTruthy(config, pathStr);
|
||||||
const bundled =
|
const bundled =
|
||||||
bundledNames && bundledNames.size > 0
|
bundledNames && bundledNames.size > 0
|
||||||
? bundledNames.has(entry.skill.name)
|
? bundledNames.has(entry.skill.name)
|
||||||
: entry.skill.source === "openclaw-bundled";
|
: entry.skill.source === "openclaw-bundled";
|
||||||
|
|
||||||
|
const requirementStatus = evaluateEntryMetadataRequirementsForCurrentPlatform({
|
||||||
|
always,
|
||||||
|
metadata: entry.metadata,
|
||||||
|
frontmatter: entry.frontmatter,
|
||||||
|
hasLocalBin: hasBinary,
|
||||||
|
remote: eligibility?.remote,
|
||||||
|
isEnvSatisfied,
|
||||||
|
isConfigSatisfied,
|
||||||
|
});
|
||||||
const { emoji, homepage, required, missing, requirementsSatisfied, configChecks } =
|
const { emoji, homepage, required, missing, requirementsSatisfied, configChecks } =
|
||||||
evaluateEntryMetadataRequirements({
|
requirementStatus;
|
||||||
always,
|
|
||||||
metadata: entry.metadata,
|
|
||||||
frontmatter: entry.frontmatter,
|
|
||||||
hasLocalBin: hasBinary,
|
|
||||||
localPlatform: process.platform,
|
|
||||||
remote: eligibility?.remote,
|
|
||||||
isEnvSatisfied: (envName) =>
|
|
||||||
Boolean(
|
|
||||||
process.env[envName] ||
|
|
||||||
skillConfig?.env?.[envName] ||
|
|
||||||
(skillConfig?.apiKey && entry.metadata?.primaryEnv === envName),
|
|
||||||
),
|
|
||||||
isConfigSatisfied: (pathStr) => isConfigPathTruthy(config, pathStr),
|
|
||||||
});
|
|
||||||
const eligible = !disabled && !blockedByAllowlist && requirementsSatisfied;
|
const eligible = !disabled && !blockedByAllowlist && requirementsSatisfied;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { evaluateEntryMetadataRequirements } from "../shared/entry-status.js";
|
import { evaluateEntryMetadataRequirementsForCurrentPlatform } from "../shared/entry-status.js";
|
||||||
import type { RequirementConfigCheck, Requirements } from "../shared/requirements.js";
|
import type { RequirementConfigCheck, Requirements } from "../shared/requirements.js";
|
||||||
import { CONFIG_DIR } from "../utils.js";
|
import { CONFIG_DIR } from "../utils.js";
|
||||||
import { hasBinary, isConfigPathTruthy, resolveHookConfig } from "./config.js";
|
import { hasBinary, isConfigPathTruthy, resolveHookConfig } from "./config.js";
|
||||||
@@ -87,18 +87,21 @@ function buildHookStatus(
|
|||||||
const disabled = managedByPlugin ? false : hookConfig?.enabled === false;
|
const disabled = managedByPlugin ? false : hookConfig?.enabled === false;
|
||||||
const always = entry.metadata?.always === true;
|
const always = entry.metadata?.always === true;
|
||||||
const events = entry.metadata?.events ?? [];
|
const events = entry.metadata?.events ?? [];
|
||||||
|
const isEnvSatisfied = (envName: string) =>
|
||||||
|
Boolean(process.env[envName] || hookConfig?.env?.[envName]);
|
||||||
|
const isConfigSatisfied = (pathStr: string) => isConfigPathTruthy(config, pathStr);
|
||||||
|
|
||||||
|
const requirementStatus = evaluateEntryMetadataRequirementsForCurrentPlatform({
|
||||||
|
always,
|
||||||
|
metadata: entry.metadata,
|
||||||
|
frontmatter: entry.frontmatter,
|
||||||
|
hasLocalBin: hasBinary,
|
||||||
|
remote: eligibility?.remote,
|
||||||
|
isEnvSatisfied,
|
||||||
|
isConfigSatisfied,
|
||||||
|
});
|
||||||
const { emoji, homepage, required, missing, requirementsSatisfied, configChecks } =
|
const { emoji, homepage, required, missing, requirementsSatisfied, configChecks } =
|
||||||
evaluateEntryMetadataRequirements({
|
requirementStatus;
|
||||||
always,
|
|
||||||
metadata: entry.metadata,
|
|
||||||
frontmatter: entry.frontmatter,
|
|
||||||
hasLocalBin: hasBinary,
|
|
||||||
localPlatform: process.platform,
|
|
||||||
remote: eligibility?.remote,
|
|
||||||
isEnvSatisfied: (envName) => Boolean(process.env[envName] || hookConfig?.env?.[envName]),
|
|
||||||
isConfigSatisfied: (pathStr) => isConfigPathTruthy(config, pathStr),
|
|
||||||
});
|
|
||||||
|
|
||||||
const eligible = !disabled && requirementsSatisfied;
|
const eligible = !disabled && requirementsSatisfied;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import {
|
|||||||
type RequirementsMetadata,
|
type RequirementsMetadata,
|
||||||
} from "./requirements.js";
|
} from "./requirements.js";
|
||||||
|
|
||||||
|
export type EntryMetadataRequirementsParams = Parameters<
|
||||||
|
typeof evaluateEntryMetadataRequirements
|
||||||
|
>[0];
|
||||||
|
|
||||||
export function evaluateEntryMetadataRequirements(params: {
|
export function evaluateEntryMetadataRequirements(params: {
|
||||||
always: boolean;
|
always: boolean;
|
||||||
metadata?: (RequirementsMetadata & { emoji?: string; homepage?: string }) | null;
|
metadata?: (RequirementsMetadata & { emoji?: string; homepage?: string }) | null;
|
||||||
@@ -51,3 +55,12 @@ export function evaluateEntryMetadataRequirements(params: {
|
|||||||
configChecks,
|
configChecks,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function evaluateEntryMetadataRequirementsForCurrentPlatform(
|
||||||
|
params: Omit<EntryMetadataRequirementsParams, "localPlatform">,
|
||||||
|
): ReturnType<typeof evaluateEntryMetadataRequirements> {
|
||||||
|
return evaluateEntryMetadataRequirements({
|
||||||
|
...params,
|
||||||
|
localPlatform: process.platform,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user