-
Notifications
You must be signed in to change notification settings - Fork 81
feat: Add granular UI tool controls for create and update #558
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
base: main
Are you sure you want to change the base?
feat: Add granular UI tool controls for create and update #558
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.',
};
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