Repository navigation
fix(dart-agent): compile Event userMessage and nested action slots in Express #3636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
607581c
379b118
75d1097
a9b4d56
e06b0de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -472,6 +472,10 @@ class _Component { | |
|
|
||
| String get _id => '${json['id']}'; | ||
|
|
||
| /// The helper of the component's catalog, set once [write] resolves it, | ||
| /// through which nested schemas are reached. | ||
| CatalogSchemaHelper? _helper; | ||
|
|
||
| String write() { | ||
| final id = json['id']! as String; | ||
| final String varName = variables[id]!; | ||
|
|
@@ -486,6 +490,7 @@ class _Component { | |
| component: true, | ||
| subject: "Component '$id'", | ||
| ); | ||
| _helper = helper; | ||
| final List<String> properties = helper.properties(type); | ||
| for (final String key in json.keys) { | ||
| if (key == 'id' || key == 'component' || key == 'checks') continue; | ||
|
|
@@ -515,7 +520,7 @@ class _Component { | |
| } | ||
| arguments | ||
| ..addAll(List.filled(skipped, '_')) | ||
| ..add(_property(value, helper.propertySchema(type, property))); | ||
| ..add(_value(value, helper.propertySchema(type, property))); | ||
| skipped = 0; | ||
| } | ||
| if (json['checks'] case final Object checks) arguments.add(_checks(checks)); | ||
|
|
@@ -524,12 +529,8 @@ class _Component { | |
| return '$varName = $type(${arguments.join(', ')})'; | ||
| } | ||
|
|
||
| String _property(Object value, Map<String, Object?>? schema) { | ||
| if (isAction(schema)) return _action(value); | ||
| return _value(value, schema); | ||
| } | ||
|
|
||
| String _value(Object? value, Map<String, Object?>? schema) { | ||
| if (isAction(schema) && value != null) return _action(value); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler now finds nested slots with So if a catalog writes the item schema as 🤖 Agent-generated
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (isComponentId(schema) && value is String) return _reference(value); | ||
| if (isChildList(schema)) { | ||
| if (value is List && value.every((Object? v) => v is String)) { | ||
|
|
@@ -549,8 +550,11 @@ class _Component { | |
| Map() => | ||
| _binding(value) ?? | ||
| _call(value) ?? | ||
| _mapLiteral(value, (key) => _propertySchema(schema, key)), | ||
| List() => _list(value, _itemSchema(schema)), | ||
| _mapLiteral( | ||
| value, | ||
| (key) => _helper?.resolvePropertySchema(schema, key), | ||
| ), | ||
| List() => _list(value, _helper?.resolveItemSchema(schema)), | ||
| _ => _literal(value), | ||
| }; | ||
| } | ||
|
|
@@ -560,21 +564,33 @@ class _Component { | |
| /// as written. | ||
| String _reference(String id) => variables[id] ?? _string(id); | ||
|
|
||
| /// `Event(name, context)` for an event, the call itself for a local | ||
| /// function, and the map literal otherwise. | ||
| /// `Event(name, context?, userMessage=?)` for an event, the call itself | ||
| /// for a local function, and the map literal otherwise. | ||
| String _action(Object value) { | ||
| switch (value) { | ||
| case {'event': final Map<Object?, Object?> event} when value.length == 1: | ||
| final Object? name = event['name']; | ||
| final Object? context = event['context']; | ||
| final Object? userMessage = event['userMessage']; | ||
| const keys = {'name', 'context', 'userMessage'}; | ||
| final bool isEvent = | ||
| name is String && | ||
| event.keys.every((k) => k == 'name' || k == 'context') && | ||
| (context == null || (context is Map && context.isNotEmpty)); | ||
| event.keys.every(keys.contains) && | ||
| (context == null || (context is Map && context.isNotEmpty)) && | ||
| // Before v1.0 an event has no userMessage, and the compiler | ||
| // rejects `userMessage=`, so the object stays a map literal. | ||
| (userMessage == null || | ||
| (_v1 && | ||
| (userMessage is String || | ||
| _binding(_asMap(userMessage)) != null || | ||
| _call(_asMap(userMessage)) != null))); | ||
| if (isEvent) { | ||
| return context == null | ||
| ? 'Event(${_string(name)})' | ||
| : 'Event(${_string(name)}, ${_value(context, null)})'; | ||
| final arguments = <String>[ | ||
| _string(name), | ||
| if (context != null) _value(context, null), | ||
| if (userMessage != null) 'userMessage=${_value(userMessage, null)}', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This writes Should 🤖 Agent-generated
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(Note: the lowered v0.9 conformance cases in |
||
| ]; | ||
| return 'Event(${arguments.join(', ')})'; | ||
| } | ||
| case {'functionCall': final Map<Object?, Object?> call} | ||
| when value.length == 1: | ||
|
|
@@ -856,24 +872,5 @@ bool _equal(Object? a, Object? b) => switch ((a, b)) { | |
| _ => a == b, | ||
| }; | ||
|
|
||
| Map<String, Object?>? _propertySchema( | ||
| Map<String, Object?>? schema, | ||
| String key, | ||
| ) { | ||
| if (schema == null) return null; | ||
| if (schema['properties'] case final Map<Object?, Object?> properties) { | ||
| if (properties[key] case final Map<Object?, Object?> property) { | ||
| return property.cast<String, Object?>(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| Map<String, Object?>? _itemSchema(Map<String, Object?>? schema) => | ||
| switch (schema?['items']) { | ||
| final Map<Object?, Object?> items => items.cast<String, Object?>(), | ||
| _ => null, | ||
| }; | ||
|
|
||
| A2uiValidationError _noNotation(String what) => | ||
| A2uiValidationError('$what has no Express notation.'); | ||
Uh oh!
There was an error while loading. Please reload this page.