linshenkx/prompt-optimizer · critical · ServiceDependencyError
No templates available for type: ${templateType}
Error message
No templates available for type: ${templateType} What it means
getDefaultTemplateId tries several strategies to find a default template for a type; if all lookups fail (including a fallback search), it throws ServiceDependencyError stating no templates exist for that type. This surfaces whenever template resolution needs a default that isn't present.
Source
Thrown at packages/core/src/services/prompt/service.ts:1081
return fallbackTemplates[0].id;
}
}
// 最后的回退:获取所有模板中第一个可用的内置模板
const allTemplates = await this.templateManager.listTemplates();
const availableTemplate = allTemplates.find((t) => t.isBuiltin);
if (availableTemplate) {
console.warn(
`Using fallback builtin template: ${availableTemplate.id} for type ${templateType}`,
);
return availableTemplate.id;
}
} catch (fallbackError) {
console.error(`Fallback template search failed:`, fallbackError);
}
// 如果所有方法都失败,抛出错误
throw new ServiceDependencyError('TemplateManager', `No templates available for type: ${templateType}`);
}
// saveOptimizationHistory 方法已移除
// 历史记录保存现在由UI层的historyManager.createNewChain方法处理
// saveTestHistory 方法已移除
// 测试功能不再保存历史记录,保持架构一致性
// 测试是临时性验证,不应与优化历史记录混合
// 注意:迭代历史记录由UI层管理,而非核心服务层
// 原因:
// 1. 迭代需要现有的chainId,这个信息由UI层的状态管理器维护
// 2. 迭代与用户交互紧密结合,需要实时更新UI状态
// 3. 版本管理逻辑在UI层更容易处理
//
// 相比之下,优化操作会创建新的链,所以可以在核心层处理
// 这种混合架构是经过权衡的设计决策
View on GitHub (pinned to 3e677b1d9f)
Solutions
- Seed/import the built-in default templates for the required types
- Inspect stored templates and confirm their type field matches what the service queries ('optimize', 'userOptimize', 'iterate')
- Check the fallback search error logged to console — the underlying query failure explains why nothing was found
- Repair or reset template storage if data is corrupted
Defensive patterns
Strategy: fallback
Validate before calling
const templates = await templateManager.listTemplates();
if (!templates.some(t => t.type === 'optimize')) {
await seedDefaultTemplates();
} Type guard
const hasTemplatesForType = (
list: { type: string }[], type: string
): boolean => list.some(t => t.type === type); Try / catch
try {
const id = await svc.getDefaultTemplateId('optimize');
} catch (e) {
if (e instanceof ServiceDependencyError && /No templates available/.test(e.message)) {
await seedDefaultTemplates();
return svc.getDefaultTemplateId('optimize');
}
throw e;
} Prevention
- Run template seeding as part of app initialization and assert it succeeded
- Back up template storage before migrations
- Add a smoke test that queries one template of each required type on boot
When it happens
Trigger: Requesting a default template for 'optimize', 'userOptimize', or 'iterate' when the template store contains zero templates of that type — e.g. empty database/storage or templates with mismatched type tags.
Common situations: First run without seeding built-in templates; storage wiped or reset; templates persisted under a different type key after a version migration; filtered/paginated query bugs returning empty result sets.
Related errors
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/dc692f646fde729c.
Report an issue: GitHub.