/** * The modules a package offers a composition: how a declared `dsh.plugins` * entry is named as a row and derived into a row id, and its wire view. * @module @deepseek-ai/dsh-plugin-manager/modules */ import type { PluginProbe } from '@deepseek-ai/dsh-app-boot' import type { JsonValue } from '@deepseek-ai/dsh-util-values' import { optional } from './helpers.ts' import type { PluginPackageAddableView } from './types.ts' /** * The row `name` for one declared addable module. * @param packageName - the package. * @param declared - the `dsh.plugins[].name`, `.` for the main export. * @returns the bare package for `.`, else `/`. */ export function moduleSpecifier(packageName: string, declared: string): string { if (declared === '.') return packageName return `${packageName}/${declared.replace(/^\.\//, '')}` } /** * The row id derived from a package name and module: the unscoped name, then the subpath. * @param packageName - the package. * @param declared - the `dsh.plugins[].name`, `.` for the main export. * @returns the row id. */ export function derivedRowId(packageName: string, declared: string): string { const base = packageName.replace(/^@/, '') return declared === '.' ? base : `${base}/${declared.replace(/^\.\//, '')}` } /** * The wire view of one probed addable module. * @param packageName - the package. * @param entry - the probe's record of the declared module. * @returns the view. */ export function addableView(packageName: string, entry: PluginProbe['addable'][number]): PluginPackageAddableView { return { moduleName: moduleSpecifier(packageName, entry.name), declaredName: entry.name, ...optional('title', entry.title), // The probe read both from JSON: a manifest field and a child's report. ...optional('config', entry.config as JsonValue | undefined), ok: entry.ok, ...optional('error', entry.error), ...optional('configSchema', entry.configSchema as JsonValue | undefined), } }