1
/**2
* Display resolution for roster presets, shared by every surface that renders3
* preset names: shipped presets resolve through locale dictionary keys, and4
* user-authored metadata is never translated. A pure fold with no imports, so5
* browser bundles inline it and the Host uses the same single home for which6
* shipped id carries which copy key.7
* @module @deepseek-ai/dsh-agent-preset-registry/display8
*/10
/** Dictionary keys carrying one shipped preset's display copy. */11
export type BuiltInPresetCopyKey =12
| 'presetStandardName' | 'presetStandardDescription'13
| 'presetPtcName' | 'presetPtcDescription'14
| 'presetMinimalName' | 'presetMinimalDescription'15
| 'presetCordisName' | 'presetCordisDescription'17
/** Preset roster fields needed to resolve display copy. */18
export interface PresetDisplaySource {19
/** Stable preset id. */20
readonly id: string21
/** Unlocalized name published by the preset. */22
readonly name?: string23
/** Unlocalized description published by the preset. */24
readonly description?: string25
}27
/** Display copy resolved for the active locale. */28
export interface PresetDisplayText {29
/** Localized built-in name or the preset's own fallback name. */30
readonly name: string31
/** Localized built-in description or the preset's own description. */32
readonly description?: string33
}35
interface PresetLocaleKeys {36
readonly name: BuiltInPresetCopyKey37
readonly description: BuiltInPresetCopyKey38
}40
const BUILT_IN_PRESET_KEYS: Readonly<Partial<Record<string, PresetLocaleKeys>>> = {41
standard: { name: 'presetStandardName', description: 'presetStandardDescription' },42
ptc: { name: 'presetPtcName', description: 'presetPtcDescription' },43
minimal: { name: 'presetMinimalName', description: 'presetMinimalDescription' },44
cordis: { name: 'presetCordisName', description: 'presetCordisDescription' },45
}47
/**48
* Whether a roster row is one of the shipped presets whose copy the dictionaries carry.49
* A shipped preset publishes no `name`; a declaration that names itself owns its copy.50
* @param preset - roster row.51
* @returns true for a shipped preset id without a published name.52
*/53
export function isBuiltInPreset(preset: PresetDisplaySource): boolean {54
return preset.name === undefined && BUILT_IN_PRESET_KEYS[preset.id] !== undefined55
}57
/**58
* Resolve preset display copy without making user-authored metadata translatable.59
* @param preset - roster row whose copy is being rendered.60
* @param t - active locale lookup covering {@link BuiltInPresetCopyKey}.61
* @returns localized copy for a known shipped preset, otherwise declaration metadata.62
*/63
export function presetDisplayText(64
preset: PresetDisplaySource,65
t: (key: BuiltInPresetCopyKey) => string,66
): PresetDisplayText {67
const keys = isBuiltInPreset(preset) ? BUILT_IN_PRESET_KEYS[preset.id] : undefined68
if (keys !== undefined) return { name: t(keys.name), description: t(keys.description) }69
return {70
name: preset.name ?? preset.id,71
...preset.description === undefined ? {} : { description: preset.description },72
}73
}