UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

109 lines (108 loc) 5.24 kB
import "./src-vebZIeLe.js"; import { t as stableStringify } from "./stable-stringify-C8X7niaI.js"; import { t as pruneMapToMaxSize } from "./map-size-CNcWiFKu.js"; import { i as matchesSkillFilter } from "./agent-filter-DZ-Tmqcd.js"; import { r as loadSkillLibrarySelection } from "./selection-NYtFFG08.js"; import { r as getSkillsSnapshotVersion, s as shouldRefreshSnapshotForVersion } from "./refresh-state-DHnXO3IV.js"; import { a as loadWorkspaceSkills, c as fingerprintSkillSnapshotConfig, o as normalizeWorkspaceSkillRoots, r as loadMergedWorkspaceSkills } from "./workspace-skill-loader-_a5Sci8B.js"; import { t as buildSkillSnapshot } from "./workspace-skill-prompt-B50WpU6M.js"; import { n as ensureSkillsWatcher } from "./refresh-CXKcO8lY.js"; //#region src/skills/runtime/snapshot-hydration.ts function hydrateResolvedSkills(snapshot, rebuild) { if (snapshot.resolvedSkills !== void 0) return snapshot; return { ...snapshot, resolvedSkills: rebuild().resolvedSkills }; } //#endregion //#region src/skills/runtime/session-snapshot.ts const skillSnapshotCache = /* @__PURE__ */ new Map(); const SKILL_SNAPSHOT_CACHE_MAX = 10; function cacheSkillSnapshot(cacheKey, snapshot) { skillSnapshotCache.set(cacheKey, snapshot); pruneMapToMaxSize(skillSnapshotCache, SKILL_SNAPSHOT_CACHE_MAX); return snapshot; } function resolveReusableWorkspaceSkillSnapshot(params) { const normalizedRoots = normalizeWorkspaceSkillRoots({ agentWorkspaceDir: params.workspaceDir, ...params.executionSkillsDir ? { executionSkillsDir: params.executionSkillsDir } : {} }); const skillRoots = normalizedRoots.executionSkillsDir ? { agentWorkspaceDir: normalizedRoots.agentWorkspaceDir, executionSkillsDir: normalizedRoots.executionSkillsDir } : void 0; const watcherWorkspaceDir = skillRoots?.agentWorkspaceDir ?? params.workspaceDir; if (params.watch !== false) ensureSkillsWatcher({ workspaceDir: watcherWorkspaceDir, ...skillRoots ? { executionSkillsDir: skillRoots.executionSkillsDir } : {}, config: params.config, ...params.pluginMetadataSnapshot ? { pluginMetadataSnapshot: params.pluginMetadataSnapshot } : {} }); const snapshotVersion = params.snapshotVersion ?? getSkillsSnapshotVersion(watcherWorkspaceDir); const promptFormatChanged = params.existingSnapshot?.promptFormatVersion !== 4; const skillVersionChanged = shouldRefreshSnapshotForVersion(params.existingSnapshot?.version, snapshotVersion); const nodeSkillsEligibilityChanged = stableStringify(params.existingSnapshot?.nodeSkillsEligibility) !== stableStringify(params.eligibility?.nodeSkills); const skillOverridesChanged = stableStringify(params.existingSnapshot?.skillOverrides) !== stableStringify(params.skillOverrides); const skillRootsChanged = stableStringify(params.existingSnapshot?.skillRoots) !== stableStringify(skillRoots); const librarySelections = params.librarySelections ?? params.existingSnapshot?.librarySelections; const shouldRefresh = stableStringify(librarySelections) !== stableStringify(params.existingSnapshot?.librarySelections) || promptFormatChanged || skillVersionChanged || nodeSkillsEligibilityChanged || skillRootsChanged || !matchesSkillFilter(params.existingSnapshot?.skillFilter, params.skillFilter) || skillOverridesChanged; const buildSnapshot = () => { let entries = skillRoots ? loadMergedWorkspaceSkills({ ...skillRoots, config: params.config, agentId: params.agentId, skillFilter: params.skillFilter, skillOverrides: params.skillOverrides, eligibility: params.eligibility, pluginMetadataSnapshot: params.pluginMetadataSnapshot }) : void 0; if (librarySelections?.length) entries = [...entries ?? loadWorkspaceSkills(params.workspaceDir, { config: params.config, agentId: params.agentId, eligibility: params.eligibility, pluginMetadataSnapshot: params.pluginMetadataSnapshot }), ...loadSkillLibrarySelection(librarySelections)]; return { ...buildSkillSnapshot(params.workspaceDir, { config: params.config, ...entries ? { entries, preserveEntryOrder: true } : {}, agentId: params.agentId, skillFilter: params.skillFilter, skillOverrides: params.skillOverrides, eligibility: params.eligibility, pluginMetadataSnapshot: params.pluginMetadataSnapshot, snapshotVersion }), ...skillRoots ? { skillRoots } : {}, ...librarySelections ? { librarySelections } : {} }; }; const buildSnapshotCacheKey = () => JSON.stringify([ params.workspaceDir, librarySelections, skillRoots, snapshotVersion, params.skillFilter, params.skillOverrides, params.agentId, params.eligibility, fingerprintSkillSnapshotConfig(params.config) ]); const cachedRebuild = (snapshotCacheKey = buildSnapshotCacheKey()) => { const cachedSnapshot = skillSnapshotCache.get(snapshotCacheKey); if (cachedSnapshot) return cachedSnapshot; return cacheSkillSnapshot(snapshotCacheKey, buildSnapshot()); }; return { snapshot: !params.existingSnapshot || shouldRefresh ? cachedRebuild() : params.hydrateExisting === false ? params.existingSnapshot : hydrateResolvedSkills(params.existingSnapshot, cachedRebuild), shouldRefresh, snapshotVersion }; } //#endregion export { resolveReusableWorkspaceSkillSnapshot as t };