UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) • 2.9 kB
import { l as pathExists } from "./utils-C8YECn2Q.mjs"; import { Et as _enum, Fn as object, Jn as string, Nt as array, xn as literal } from "./schemas-Cy6abvsu.mjs"; import { t as resolveWorkspaceTemplateSearchDirs } from "./workspace-templates-BdeLALx5.mjs"; import { n as readTemplateManifestFile } from "./reader-L_dBhbIJ.mjs"; import path from "node:path"; import fs from "node:fs/promises"; //#region src/agents/agent-roles.ts const AGENT_ROLES = [ "coordinator", "researcher", "writer", "reviewer" ]; function listAgentRoles() { return AGENT_ROLES; } function validateAgentTeamMemberIds(e) { return new Set(e).size === e.length ? void 0 : "Team member ids must be distinct after applying the coordinator and prefix options."; } const memberSchema = object({ id: string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/), role: _enum(AGENT_ROLES) }).strict(); const teamPresetSchema = object({ schemaVersion: literal(1), coordinator: memberSchema, specialists: array(memberSchema).min(1) }).strict().refine(({ coordinator: e, specialists: t }) => validateAgentTeamMemberIds([e.id, ...t.map((e) => e.id)]) === void 0, { message: "Team member ids must be unique" }); async function resolveCatalogFile(...e) { for (const t of await resolveWorkspaceTemplateSearchDirs()) { const n = path.join(t, "roles", ...e); if (await pathExists(n)) return n; } throw new Error(`Bundled agent role is missing: ${e.join("/")}`); } async function loadAgentRole(e) { if (!AGENT_ROLES.some((t) => t === e)) throw new Error(`Unknown agent role "${e}". Available roles: ${AGENT_ROLES.join(", ")}.`); const t = await readTemplateManifestFile(await resolveCatalogFile(e, "CLAW.md")); if (!t.ok) throw new Error(t.diagnostics.map(({ message: e }) => e).join("\n")); const { manifest: n } = t; const r = n.agent.identity; const i = n.workspace.bootstrapFiles["AGENTS.md"]?.source; if (n.agent.id !== e || !r?.name || !r.emoji || !r.theme || !i || !t.templateMarkdownBody) throw new Error(`Agent role "${e}" requires its matching id, complete identity, AGENTS.md, and SOUL body.`); return { manifest: n, identity: { name: r.name, emoji: r.emoji, theme: r.theme }, files: { "AGENTS.md": await fs.readFile(path.join(t.source.packageRoot, i), "utf8"), "SOUL.md": t.templateMarkdownBody.toString("utf8"), "IDENTITY.md": `# Identity\n\n- **Name:** ${r.name}\n- **Creature:** ${e} assistant\n- **Vibe:** ${r.theme}\n- **Emoji:** ${r.emoji}\n- **Theme:** ${r.theme}\n` } }; } async function loadAgentTeamPreset(e = "team") { if (e !== "team") throw new Error(`Unknown agent team preset "${e}". Available presets: team.`); const t = await resolveCatalogFile("presets", `${e}.json`); return teamPresetSchema.parse(JSON.parse(await fs.readFile(t, "utf8"))); } //#endregion export { validateAgentTeamMemberIds as i, loadAgentRole as n, loadAgentTeamPreset as r, listAgentRoles as t };