feat: Add granular UI tool controls for create and update#558
Conversation
There was a problem hiding this comment.
Code Review
This pull request effectively introduces granular controls for UI surface creation and updates by adding a SurfaceUpdateMode. The refactoring of SurfaceUpdateTool and the updates to the AI content generators are well-executed and align with the goal of preventing unintended UI modifications. The code is clear and the changes are consistent across the different packages. I have two suggestions to improve maintainability and adopt more modern Dart syntax.
| final String surfaceIdDescription; | ||
| switch (updateMode) { | ||
| case SurfaceUpdateMode.create: | ||
| surfaceIdDescription = | ||
| 'The unique identifier for the new UI surface to create. This ' | ||
| '*must* be a new, unique identifier.'; | ||
| break; | ||
| case SurfaceUpdateMode.update: | ||
| surfaceIdDescription = | ||
| 'The unique identifier for the existing UI surface to update.'; | ||
| break; | ||
| case SurfaceUpdateMode.both: | ||
| surfaceIdDescription = | ||
| 'The unique identifier for the UI surface to create or ' | ||
| 'update. If you are adding a new surface this *must* be a ' | ||
| 'new, unique identified that has never been used for any ' | ||
| 'existing surfaces shown.', | ||
| ), | ||
| 'components': S.list( | ||
| description: 'A list of component definitions.', | ||
| minItems: 1, | ||
| items: S.object( | ||
| description: | ||
| 'Represents a *single* component in a UI widget tree. ' | ||
| 'This component could be one of many supported types.', | ||
| properties: { | ||
| 'id': S.string(), | ||
| 'weight': S.integer( | ||
| description: | ||
| 'Optional layout weight for use in Row/Column children.', | ||
| ), | ||
| 'component': S.object( | ||
| description: | ||
| '''A wrapper object that MUST contain exactly one key, which is the name of the component type (e.g., 'Text'). The value is an object containing the properties for that specific component.''', | ||
| properties: { | ||
| for (var entry | ||
| in ((catalog.definition as ObjectSchema) | ||
| .properties!['components']! | ||
| as ObjectSchema) | ||
| .properties! | ||
| .entries) | ||
| entry.key: entry.value, | ||
| }, | ||
| ), | ||
| }, | ||
| required: ['id', 'component'], | ||
| 'existing surfaces shown.'; | ||
| break; | ||
| } |
There was a problem hiding this comment.
For improved conciseness and readability, you could refactor this switch statement into a switch expression, which is a feature available in modern Dart. This would make the assignment of surfaceIdDescription more direct and the code more idiomatic.
final String surfaceIdDescription = switch (updateMode) {
SurfaceUpdateMode.create =>
'The unique identifier for the new UI surface to create. This '
'*must* be a new, unique identifier.',
SurfaceUpdateMode.update =>
'The unique identifier for the existing UI surface to update.',
SurfaceUpdateMode.both =>
'The unique identifier for the UI surface to create or '
'update. If you are adding a new surface this *must* be a '
'new, unique identified that has never been used for any '
'existing surfaces shown.',
};| 'A message which can be sent before or after surfaceUpdate to ' | ||
| 'begin rendering a surface with a given ID. Any surfaceUpdate messages ' | ||
| 'sent before this message will be cached but not trigger any rendering ' | ||
| ' yet. The surfaceId *must* match associated surfaceUpdate or ' |
There was a problem hiding this comment.
Heads up, there seem to be an unnecessary extra empty space at the beginning of this line!
Introduces
SurfaceUpdateModeto provide distinctcreateandupdatecapabilities for UI surfaces. This change refactorsSurfaceUpdateToolto be configurable and updates the AI content generators to provide separatesurfaceCreateandsurfaceUpdatetools based on theGenUiConfiguration.This allows developers to control whether the AI can only create new UI surfaces, only update existing ones, or both, preventing unintended UI modifications.
Fixes #463