mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 10:47:27 +00:00
refactor(shared): reuse requirement remote context type
This commit is contained in:
@@ -2,6 +2,7 @@ import { resolveEmojiAndHomepage } from "./entry-metadata.js";
|
||||
import {
|
||||
evaluateRequirementsFromMetadataWithRemote,
|
||||
type RequirementConfigCheck,
|
||||
type RequirementRemote,
|
||||
type Requirements,
|
||||
type RequirementsMetadata,
|
||||
} from "./requirements.js";
|
||||
@@ -17,11 +18,7 @@ export function evaluateEntryMetadataRequirements(params: {
|
||||
} | null;
|
||||
hasLocalBin: (bin: string) => boolean;
|
||||
localPlatform: string;
|
||||
remote?: {
|
||||
hasBin?: (bin: string) => boolean;
|
||||
hasAnyBin?: (bins: string[]) => boolean;
|
||||
platforms?: string[];
|
||||
};
|
||||
remote?: RequirementRemote;
|
||||
isEnvSatisfied: (envName: string) => boolean;
|
||||
isConfigSatisfied: (pathStr: string) => boolean;
|
||||
}): {
|
||||
|
||||
@@ -16,6 +16,26 @@ export type RequirementsMetadata = {
|
||||
os?: string[];
|
||||
};
|
||||
|
||||
export type RequirementRemote = {
|
||||
hasBin?: (bin: string) => boolean;
|
||||
hasAnyBin?: (bins: string[]) => boolean;
|
||||
platforms?: string[];
|
||||
};
|
||||
|
||||
type RequirementsEvaluationContext = {
|
||||
always: boolean;
|
||||
hasLocalBin: (bin: string) => boolean;
|
||||
localPlatform: string;
|
||||
isEnvSatisfied: (envName: string) => boolean;
|
||||
isConfigSatisfied: (pathStr: string) => boolean;
|
||||
};
|
||||
|
||||
type RequirementsEvaluationRemoteContext = {
|
||||
hasRemoteBin?: (bin: string) => boolean;
|
||||
hasRemoteAnyBin?: (bins: string[]) => boolean;
|
||||
remotePlatforms?: string[];
|
||||
};
|
||||
|
||||
export function resolveMissingBins(params: {
|
||||
required: string[];
|
||||
hasLocalBin: (bin: string) => boolean;
|
||||
@@ -91,17 +111,12 @@ export function buildConfigChecks(params: {
|
||||
});
|
||||
}
|
||||
|
||||
export function evaluateRequirements(params: {
|
||||
always: boolean;
|
||||
required: Requirements;
|
||||
hasLocalBin: (bin: string) => boolean;
|
||||
hasRemoteBin?: (bin: string) => boolean;
|
||||
hasRemoteAnyBin?: (bins: string[]) => boolean;
|
||||
localPlatform: string;
|
||||
remotePlatforms?: string[];
|
||||
isEnvSatisfied: (envName: string) => boolean;
|
||||
isConfigSatisfied: (pathStr: string) => boolean;
|
||||
}): { missing: Requirements; eligible: boolean; configChecks: RequirementConfigCheck[] } {
|
||||
export function evaluateRequirements(
|
||||
params: RequirementsEvaluationContext &
|
||||
RequirementsEvaluationRemoteContext & {
|
||||
required: Requirements;
|
||||
},
|
||||
): { missing: Requirements; eligible: boolean; configChecks: RequirementConfigCheck[] } {
|
||||
const missingBins = resolveMissingBins({
|
||||
required: params.required.bins,
|
||||
hasLocalBin: params.hasLocalBin,
|
||||
@@ -148,17 +163,12 @@ export function evaluateRequirements(params: {
|
||||
return { missing, eligible, configChecks };
|
||||
}
|
||||
|
||||
export function evaluateRequirementsFromMetadata(params: {
|
||||
always: boolean;
|
||||
metadata?: RequirementsMetadata;
|
||||
hasLocalBin: (bin: string) => boolean;
|
||||
hasRemoteBin?: (bin: string) => boolean;
|
||||
hasRemoteAnyBin?: (bins: string[]) => boolean;
|
||||
localPlatform: string;
|
||||
remotePlatforms?: string[];
|
||||
isEnvSatisfied: (envName: string) => boolean;
|
||||
isConfigSatisfied: (pathStr: string) => boolean;
|
||||
}): {
|
||||
export function evaluateRequirementsFromMetadata(
|
||||
params: RequirementsEvaluationContext &
|
||||
RequirementsEvaluationRemoteContext & {
|
||||
metadata?: RequirementsMetadata;
|
||||
},
|
||||
): {
|
||||
required: Requirements;
|
||||
missing: Requirements;
|
||||
eligible: boolean;
|
||||
@@ -186,19 +196,12 @@ export function evaluateRequirementsFromMetadata(params: {
|
||||
return { required, ...result };
|
||||
}
|
||||
|
||||
export function evaluateRequirementsFromMetadataWithRemote(params: {
|
||||
always: boolean;
|
||||
metadata?: RequirementsMetadata;
|
||||
hasLocalBin: (bin: string) => boolean;
|
||||
localPlatform: string;
|
||||
remote?: {
|
||||
hasBin?: (bin: string) => boolean;
|
||||
hasAnyBin?: (bins: string[]) => boolean;
|
||||
platforms?: string[];
|
||||
};
|
||||
isEnvSatisfied: (envName: string) => boolean;
|
||||
isConfigSatisfied: (pathStr: string) => boolean;
|
||||
}): {
|
||||
export function evaluateRequirementsFromMetadataWithRemote(
|
||||
params: RequirementsEvaluationContext & {
|
||||
metadata?: RequirementsMetadata;
|
||||
remote?: RequirementRemote;
|
||||
},
|
||||
): {
|
||||
required: Requirements;
|
||||
missing: Requirements;
|
||||
eligible: boolean;
|
||||
|
||||
Reference in New Issue
Block a user