UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 2.64 kB
import"./utils-Dlk0IYAa.mjs";import{l as pathExists}from"./fs-safe-Bxzu1j4h.mjs";import{Et as _enum,Fn as object,Jn as string,Nt as array,xn as literal}from"./schemas-DuCQi-Qb.mjs";import{t as resolveWorkspaceTemplateSearchDirs}from"./workspace-templates-NCJsC1GY.mjs";import{n as readTemplateManifestFile}from"./reader-j_g75PYq.mjs";import path from"node:path";import fs from"node:fs/promises"; //!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(` `));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`)))}export{validateAgentTeamMemberIds as i,loadAgentRole as n,loadAgentTeamPreset as r,listAgentRoles as t};