openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
161 lines (160 loc) • 6.31 kB
JavaScript
import { r as isPathInside } from "../../path-guards-TIjxtj6H.mjs";
import { u as pinConfigDir } from "../../utils-C8YECn2Q.mjs";
import { t as applyProcessEnvKeys } from "../../process-env-DVJdcOcM.mjs";
import { i as createPluginCache, w as withPluginCache } from "../../plugin-cache-B_eRuqTM.mjs";
import { n as sha256Hex } from "../../node-crypto-B6yuTjmm.mjs";
import "../../crypto-digest-B2m8wIBj.mjs";
import { r as resolveEffectiveAgentSkillsLimits } from "../../agent-filter-B8NbzRsF.mjs";
import { r as resolveSkillFileHost } from "../../skill-file-host-DYVvMKod.mjs";
import { r as resolveSkillKey } from "../../frontmatter-CetkUJdW.mjs";
import { c as tryRealpath, n as compactPromptSkills } from "../../local-loader-CaLEAbQc.mjs";
import { r as resolveWorkspaceSkillDirectories } from "../../workspace-skill-roots-CLIzdM6T.mjs";
import { a as resolvePluginSkillRootsFromContributions, i as resolvePluginSkillRoots } from "../../plugin-skills-CL-RMSJw.mjs";
import { n as serveWorkerTasks } from "../../worker-task-server-J1vG-XRl.mjs";
import { t as readWorkspaceSkillStatusFacts } from "../../status-files-DWZk5eSR.mjs";
import { n as mergeSkillRecords, t as appendLowerPrecedenceSkillRecords } from "../../skill-precedence-CohcbttY.mjs";
import { t as isSkillPromptVisible } from "../../skill-index-CXWWhRXT.mjs";
import { n as prepareSkillsForPrompt } from "../../skill-prompt-limits-Cq0hn_ts.mjs";
import { t as readWorkspaceSkillSources } from "../../workspace-skill-source-reader-DY_uZ4r7.mjs";
import { n as resolveWorkspaceSkillSourcePlan, r as splitSkillSourcePlan } from "../../workspace-skill-sources-CkqcUFfT.mjs";
//#region src/skills/loading/skill-snapshot-projection.ts
/** Render already selected entries without repeating discovery or eligibility checks. */
function buildSkillSnapshotProjection(e) {
const { eligible: t, skillFilter: n } = e;
const r = t.filter(isSkillPromptVisible);
const i = e.eligibility?.remote?.note?.trim();
const a = r.map((e) => e.skill);
const o = e.config?.skills?.limits;
const s = resolveEffectiveAgentSkillsLimits(e.config, e.agentId);
const c = prepareSkillsForPrompt({
skills: compactPromptSkills(a, {
config: e.config,
agentId: e.agentId
}),
maxSkillsInPrompt: o?.maxSkillsInPrompt,
maxSkillsPromptChars: s?.maxSkillsPromptChars ?? o?.maxSkillsPromptChars,
remoteNote: i,
preserveOrder: e.preserveEntryOrder
});
const l = new Map(a.map((e) => [e.name, e]));
return {
prompt: c.prompt,
skills: t.map((e) => ({
name: e.skill.name,
source: {
filePath: e.skill.filePath,
fileHost: resolveSkillFileHost(e.skill)
},
gatewayFilePath: resolveSkillFileHost(e.skill) === "gateway" ? e.skill.filePath : void 0,
skillKey: resolveSkillKey(e),
primaryEnv: e.metadata?.primaryEnv,
requiredEnv: e.metadata?.requires?.env?.slice()
})),
...n === void 0 ? {} : { skillFilter: n },
...e.skillOverrides ? { skillOverrides: e.skillOverrides } : {},
...e.eligibility?.nodeSkills ? { nodeSkillsEligibility: e.eligibility.nodeSkills } : {},
resolvedSkills: c.skills.map((e) => l.get(e.name)),
discoverySkills: a,
version: e.snapshotVersion,
promptFormatVersion: 8
};
}
//#endregion
//#region src/skills/runtime/discovery.worker.ts
function applyEnvironment(e) {
applyProcessEnvKeys(Object.keys(e), e);
pinConfigDir();
}
function resolveInputPlan(e, t = createPluginCache()) {
return withPluginCache(t, () => {
const t = e.options;
const n = t?.workspaceOnly ? [] : e.pluginContributions ? resolvePluginSkillRootsFromContributions({
contributions: e.pluginContributions,
pluginSkillsDir: t?.pluginSkillsDir
}) : resolvePluginSkillRoots({
workspaceDir: e.workspaceDir,
config: t?.config,
pluginSkillsDir: t?.pluginSkillsDir,
acpRuntimeAvailable: e.acpRuntimeAvailable
});
return resolveWorkspaceSkillSourcePlan(e.workspaceDir, {
...t,
pluginSkillRoots: n
});
});
}
serveWorkerTasks((e, t) => {
const n = e;
t?.consumeInput();
if (n.kind === "plan") {
applyEnvironment(n.input.environment);
return {
kind: "plan",
plan: resolveInputPlan(n.input)
};
}
if (n.kind === "project") {
applyEnvironment(n.environment);
const { resolvedSkills: e, discoverySkills: t, ...r } = buildSkillSnapshotProjection(n.input);
const i = new Map(n.input.eligible.map((e, t) => [e.skill, t]));
return {
kind: "project",
snapshot: r,
resolvedIndices: e.map((e) => i.get(e)),
discoveryIndices: t.map((e) => i.get(e))
};
}
if (n.kind === "status") {
applyEnvironment(n.environment);
return {
kind: "status",
facts: readWorkspaceSkillStatusFacts(n.input)
};
}
if (n.path === void 0) delete process.env.PATH;
else process.env.PATH = n.path;
const r = createPluginCache();
const i = /* @__PURE__ */ new Map();
const a = /* @__PURE__ */ new Map();
const selectPlan = (e) => {
const t = JSON.stringify(e);
const n = a.get(t) ?? resolveInputPlan(e, r);
a.set(t, n);
return n;
};
return {
kind: "scan",
results: n.requests.map(({ key: e, environment: t, selection: n }) => {
applyEnvironment(t);
const r = n.kind === "planned" ? selectPlan(n.plan.input) : n.plan ? selectPlan(n.plan.input) : n.request.sourcePlan;
const a = {
...n.request,
sourcePlan: n.kind === "selected" && n.plan?.scope === "gateway" ? splitSkillSourcePlan(r).gatewayPlan : r
};
const o = JSON.stringify(t);
let s = i.get(o);
if (!s) {
s = /* @__PURE__ */ new Map();
i.set(o, s);
}
const c = readWorkspaceSkillSources(a, s);
const l = mergeSkillRecords(c.entries, e, false);
appendLowerPrecedenceSkillRecords(l, mergeSkillRecords(c.executionEntries, e, false), () => {});
const u = /* @__PURE__ */ new Set([...a.sourcePlan.roots.map((e) => e.dir), ...a.executionWorkspaceDir ? resolveWorkspaceSkillDirectories(a.executionWorkspaceDir).map((e) => e.dir) : []]);
const d = [...u].map((e) => tryRealpath(e));
for (const { skill: e } of [...c.entries, ...c.executionEntries]) {
const t = tryRealpath(e.baseDir);
if (t && !d.some((e) => e && isPathInside(e, t))) u.add(t);
}
return {
key: e,
sources: c,
watchDirectories: [...u],
plan: n.plan ? r : void 0,
fingerprint: sha256Hex(JSON.stringify([l, c.runtime]))
};
})
};
});
//#endregion
export {};