* 验证模板
(template: PromptTemplate)
| 468 | * 验证模板 |
| 469 | */ |
| 470 | private validateTemplate(template: PromptTemplate): void { |
| 471 | if (!template.id || !template.name || !template.template) { |
| 472 | throw new Error('模板缺少必要字段: id, name, template'); |
| 473 | } |
| 474 | |
| 475 | if (this.templates.has(template.id)) { |
| 476 | throw new Error(`模板ID已存在: ${template.id}`); |
| 477 | } |
| 478 | |
| 479 | // 验证变量定义 |
| 480 | template.variables.forEach(variable => { |
| 481 | if (!variable.name || !variable.type) { |
| 482 | throw new Error('变量缺少必要字段: name, type'); |
| 483 | } |
| 484 | }); |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * 验证变量 |