kletso_ui_schema 0.2.1 copy "kletso_ui_schema: ^0.2.1" to clipboard
kletso_ui_schema: ^0.2.1 copied to clipboard

Protocol package for Kletso: JSON Schemas, hand-written Dart models and conformance fixtures for kletso.ui/v1 surfaces, kletso.events/v1 and the realtime frames.

example/kletso_ui_schema_example.dart

// Parse and validate a `kletso.ui/v1` surface, the JSON document a Kletso
// agent emits when it renders UI. Run with `dart run example/kletso_ui_schema_example.dart`.
import 'dart:io';

import 'package:kletso_ui_schema/kletso_ui_schema.dart';

void main() {
  final json = <String, Object?>{
    'schema': 'kletso.ui/v1',
    'surfaceId': 'sfc_q2a7',
    'root': 'col',
    'fallbackText': 'Your ideal outing comes with…',
    'components': {
      'col': {
        'type': 'column',
        'props': {
          'children': ['q'],
        },
      },
      'q': {
        'type': 'ds.passportQuestion',
        'props': {
          'id': 'Q2',
          'step': 2,
          'total': 5,
          'text': 'Your ideal outing comes with…',
          'options': [
            {'label': 'Just me', 'emoji': '🧍'},
            {'label': 'My usual crew', 'emoji': '👯'},
          ],
        },
      },
    },
  };

  final surface = KletsoSurface.fromJson(json);
  stdout.writeln(
    'surface ${surface.surfaceId}: root=${surface.root}, '
    '${surface.components.length} components',
  );
  for (final entry in surface.components.entries) {
    stdout.writeln('  ${entry.key} → ${entry.value.type}');
  }

  // Structural problems surface as a typed exception with a JSON path.
  try {
    KletsoSurface.fromJson(<String, Object?>{...json, 'root': 'missing'});
  } on KletsoSchemaException catch (e) {
    stdout.writeln('rejected: $e');
  }
}
0
likes
160
points
402
downloads

Documentation

API reference

Publisher

verified publisherkletso.ai

Weekly Downloads

Protocol package for Kletso: JSON Schemas, hand-written Dart models and conformance fixtures for kletso.ui/v1 surfaces, kletso.events/v1 and the realtime frames.

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #chat #chatbot #sdk #generative-ui

License

MIT (license)

Dependencies

meta

More

Packages that depend on kletso_ui_schema