{"version":3,"file":"index.cjs","names":["readFile"],"sources":["../../../../src/services/mcpSkills/index.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\n\nimport type { DoomMcpPluginContext, DoomMcpSkill } from '@agimon-ai/doompi-core/mcp-facet';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { ServerSkillGroup } from '../serverInventory';\n\nexport const MCP_SKILLS_SERVICE = 'doom/discovered-mcp-skills';\n\nexport interface McpSkillProvider {\n  list(context: DoomMcpPluginContext): readonly DoomMcpSkill[];\n}\n\n/** Explicit remote provider, never a projection of the local resource registry. */\nexport function mountMcpSkills(groups: readonly ServerSkillGroup[], signal: AbortSignal) {\n  return (context: Context): void => {\n    context.provide(MCP_SKILLS_SERVICE, {\n      list(remote) {\n        signal.throwIfAborted();\n        remote.signal.throwIfAborted();\n        const domains = remote.selection.read().domains;\n        const skills = new Map<string, DoomMcpSkill>();\n        for (const group of groups) {\n          if (group.domain !== undefined && !domains.includes(group.domain)) continue;\n          for (const skill of group.skills) {\n            // Match command precedence, including shared copies across domains.\n            if (skills.has(skill.name)) continue;\n            skills.set(skill.name, {\n              name: skill.name,\n              description: skill.description,\n              async read() {\n                const readSignal = AbortSignal.any([signal, remote.signal]);\n                readSignal.throwIfAborted();\n                const text = await readFile(skill.filePath, { encoding: 'utf8', signal: readSignal });\n                readSignal.throwIfAborted();\n                return text;\n              },\n            });\n          }\n        }\n        return [...skills.values()];\n      },\n    } satisfies McpSkillProvider);\n  };\n}\n\nexport function bindMcpSkills(context: DoomMcpPluginContext): readonly DoomMcpSkill[] {\n  const provider = context.services.get<McpSkillProvider>(MCP_SKILLS_SERVICE);\n  if (!provider) throw new Error('Discovered MCP skills are unavailable.');\n  return provider.list(context);\n}\n"],"mappings":";;AAOA,MAAa,qBAAqB;;AAOlC,SAAgB,eAAe,QAAqC,QAAqB;CACvF,QAAQ,YAA2B;EACjC,QAAQ,QAAQ,oBAAoB,EAClC,KAAK,QAAQ;GACX,OAAO,eAAe;GACtB,OAAO,OAAO,eAAe;GAC7B,MAAM,UAAU,OAAO,UAAU,KAAK,CAAC,CAAC;GACxC,MAAM,yBAAS,IAAI,IAA0B;GAC7C,KAAK,MAAM,SAAS,QAAQ;IAC1B,IAAI,MAAM,WAAW,KAAA,KAAa,CAAC,QAAQ,SAAS,MAAM,MAAM,GAAG;IACnE,KAAK,MAAM,SAAS,MAAM,QAAQ;KAEhC,IAAI,OAAO,IAAI,MAAM,IAAI,GAAG;KAC5B,OAAO,IAAI,MAAM,MAAM;MACrB,MAAM,MAAM;MACZ,aAAa,MAAM;MACnB,MAAM,OAAO;OACX,MAAM,aAAa,YAAY,IAAI,CAAC,QAAQ,OAAO,MAAM,CAAC;OAC1D,WAAW,eAAe;OAC1B,MAAM,OAAO,OAAA,GAAMA,iBAAAA,SAAAA,CAAS,MAAM,UAAU;QAAE,UAAU;QAAQ,QAAQ;OAAW,CAAC;OACpF,WAAW,eAAe;OAC1B,OAAO;MACT;KACF,CAAC;IACH;GACF;GACA,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC;EAC5B,EACF,CAA4B;CAC9B;AACF"}