UI générative avec Lyra Gen
Des réponses de modèle rendues sous forme de vrais contrôles Lyra validés.
Lyra Gen transforme la réponse structurée d’un modèle en composants Lyra accessibles grâce à un catalogue vérifié. Le contenu généré ne peut nommer que des rôles du catalogue, jamais des balises, scripts ou actions arbitraires ; votre application conserve la requête au modèle, les données, les actions et le stockage.
Exemple
Choisissez un sous-ensemble vérifié du catalogue, puis validez une vue générée avant de l’afficher.
import '@aceshooting/lyra-ui/theme.css';
import { initialCatalog, subsetCatalog } from '@aceshooting/lyra-gen/catalog.js';
import { validateView } from '@aceshooting/lyra-gen/runtime.js';
import { LyraGenViewElement } from '@aceshooting/lyra-gen/gen-view.js';
const selected = subsetCatalog(initialCatalog, ['stack', 'heading', 'text']);
if (!selected.ok) throw new Error('The requested catalog is unavailable.');
const catalog = selected.value;
const result = validateView({
version: '1', catalog: { id: catalog.id, version: catalog.version },
surfaceId: 'answer-1', revision: 0,
root: { id: 'summary', type: 'stack', children: [
{ id: 'title', type: 'heading', text: 'Quarterly summary' },
{ id: 'detail', type: 'text', text: 'Revenue increased this quarter.' },
] },
}, catalog);
if (!result.ok) throw new Error('The generated view was rejected.');
const view = new LyraGenViewElement();
view.catalog = catalog;
view.document = result.value;
document.body.append(view);