dsh-brain/src/entries/skills.ts

54 lines
1.9 KiB
TypeScript

/**
* Skill sub-plugin entry — local skill management.
*
* Owns the skill agent tools and the skills / market / clients routes (plus
* their legacy /cloud-memory aliases): inventory, install plans, market
* search, update/rollback, and the cross-software client registry. Sync
* itself belongs to the cloud-sync entry; the admin's write gate still
* consults the shared sync engine through the kernel.
*/
import type { CloudMemoryContext } from '../context-types.ts'
import { brainKernel, VERSION } from '../kernel.ts'
import { legacyAliases } from '../routes.ts'
import { createSkillRoutes } from '../skills/routes.ts'
import { createSkillTools } from '../tools.ts'
export const name = 'dsh-brain-skills'
/** Services required before `apply` runs. */
export const inject = ['tools', 'webServer']
/** Register the sub-plugin with the host. */
export function apply(ctx: CloudMemoryContext, config: unknown): void {
const logger = ctx.logger('dsh-brain')
const kernel = brainKernel(config, logger)
kernel.activate('skills')
ctx.effect(() => () => kernel.deactivate('skills'), 'dsh-brain-skills: activation')
ctx.inject(['tools'], (toolsCtx) => {
const tools = (toolsCtx as CloudMemoryContext).tools
if (tools === undefined) return
for (const tool of createSkillTools(kernel.toolDeps())) {
toolsCtx.effect(() => tools.register(tool), `dsh-brain-skills: tool ${tool.name}`)
}
})
const webServer = ctx.webServer
if (webServer === undefined) {
logger.warn('webServer service unavailable; skill routes stay disabled')
return
}
const routes = createSkillRoutes({
version: VERSION,
admin: kernel.skillAdmin,
groups: kernel.skillGroups,
market: kernel.market,
updates: kernel.updater,
clients: kernel.clients,
})
routes.push(...legacyAliases(routes))
for (const route of routes) {
ctx.effect(() => webServer.register(route), `dsh-brain-skills: route ${route.path}`)
}
}