Support item template route metadata

This commit is contained in:
2026-06-27 02:00:55 +02:00
parent 2d3d668359
commit dc94b1c4c1
6 changed files with 179 additions and 30 deletions
+18 -4
View File
@@ -177,15 +177,29 @@ def _template_axis_errors(path: str, node: dict[str, Any]) -> list[tuple[str, st
axis_names = set(axes) if isinstance(axes, dict) else set()
errors: list[tuple[str, str]] = []
for index, template in enumerate(templates):
if not isinstance(template, str):
errors.append((f"{path}.item_templates[{index}]", "template is not a string"))
template_path = f"{path}.item_templates[{index}]"
if isinstance(template, dict):
template_text = str(
template.get("template")
or template.get("prompt")
or template.get("text")
or template.get("description")
or template.get("name")
or ""
).strip()
elif isinstance(template, str):
template_text = template
else:
template_text = ""
if not template_text:
errors.append((template_path, "template must be a string or object with template/text"))
continue
tokens = set(TEMPLATE_TOKEN_RE.findall(template))
tokens = set(TEMPLATE_TOKEN_RE.findall(template_text))
missing = sorted(token for token in tokens if token not in axis_names)
if missing:
errors.append(
(
f"{path}.item_templates[{index}]",
template_path,
"missing item_axes for placeholders: " + ", ".join(missing),
)
)