-
Notifications
You must be signed in to change notification settings - Fork 153
feat(genui): support functions in prompts and verify rendering #921
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?
Changes from all commits
a24693d
4134cb3
f9f9e21
1affaab
cb629b6
fb4a577
9c47110
ab3593a
b7bba17
341789f
6d21e7b
5fe5754
6a4ad57
8aff417
f5c991b
ea68855
c6858ab
fc669bd
f27595c
0520535
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../submodules/a2ui/specification/v0_9/json/common_types.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../submodules/a2ui/specification/v0_9/json/server_to_client.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import 'package:flutter/material.dart'; | ||
| import 'package:json_schema_builder/json_schema_builder.dart'; | ||
|
|
||
| import '../../model/a2ui_exceptions.dart'; | ||
| import '../../model/a2ui_schemas.dart'; | ||
| import '../../model/catalog_item.dart'; | ||
| import '../../model/data_model.dart'; | ||
|
|
@@ -233,7 +234,33 @@ Future<void> _handlePress( | |
| try { | ||
| await resultStream.first; | ||
|
Member
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. I know that this is unrelated to this change buuuuttt... Is there any chance this |
||
| } catch (exception, stackTrace) { | ||
| itemContext.reportError(exception, stackTrace); | ||
| genUiLogger.severe( | ||
| 'Error executing function call "$callName" on button press', | ||
| exception, | ||
| stackTrace, | ||
| ); | ||
|
|
||
| if (exception is A2uiFunctionException) { | ||
|
Member
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. Unfortunate that we can't use the |
||
| itemContext.reportError(exception, stackTrace); | ||
| } else if (exception is ArgumentError) { | ||
| itemContext.reportError( | ||
| A2uiFunctionException( | ||
| exception.message.toString(), | ||
| functionName: callName, | ||
| cause: exception, | ||
| ), | ||
| stackTrace, | ||
| ); | ||
|
gspencergoog marked this conversation as resolved.
|
||
| } else { | ||
| itemContext.reportError( | ||
| A2uiFunctionException( | ||
| 'Function execution failed. Please check arguments and try again.', | ||
| functionName: callName, | ||
| cause: exception, | ||
| ), | ||
| stackTrace, | ||
| ); | ||
| } | ||
| } | ||
| } else { | ||
| genUiLogger.warning( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,9 +340,7 @@ final dateTimeInput = CatalogItem( | |
| { | ||
| "id": "root", | ||
| "component": "DateTimeInput", | ||
| "value": { | ||
| "path": "/myDateTime" | ||
| } | ||
| "value": "2026-05-15" | ||
|
Member
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. Why did we need to change this example? |
||
| } | ||
| ] | ||
| ''', | ||
|
|
@@ -354,7 +352,7 @@ final dateTimeInput = CatalogItem( | |
| "value": { | ||
| "path": "/myDate" | ||
| }, | ||
| "enableTime": false | ||
| "variant": "date" | ||
| } | ||
| ] | ||
| ''', | ||
|
|
@@ -366,7 +364,7 @@ final dateTimeInput = CatalogItem( | |
| "value": { | ||
| "path": "/myTime" | ||
| }, | ||
| "enableDate": false | ||
| "variant": "time" | ||
| } | ||
| ] | ||
| ''', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import '../interfaces/a2ui_message_sink.dart'; | |
| import '../interfaces/surface_context.dart'; | ||
| import '../interfaces/surface_host.dart'; | ||
| import '../model/a2ui_client_capabilities.dart'; | ||
| import '../model/a2ui_exceptions.dart'; | ||
| import '../model/a2ui_message.dart'; | ||
| import '../model/catalog.dart'; | ||
| import '../model/chat_message.dart'; | ||
|
|
@@ -120,16 +121,21 @@ interface class SurfaceController implements SurfaceHost, A2uiMessageSink { | |
|
|
||
| /// Reports an error to the AI service. | ||
| void reportError(Object error, StackTrace? stack) { | ||
| var errorCode = 'RUNTIME_ERROR'; | ||
| var message = error.toString(); | ||
| var errorCode = 'INTERNAL_ERROR'; | ||
| var message = 'An unexpected system error occurred.'; | ||
| String? surfaceId; | ||
| String? path; | ||
| String? functionName; | ||
|
|
||
| if (error is A2uiValidationException) { | ||
| errorCode = 'VALIDATION_FAILED'; | ||
| message = error.message; | ||
| surfaceId = error.surfaceId; | ||
| path = error.path; | ||
| } else if (error is A2uiFunctionException) { | ||
| errorCode = 'FUNCTION_EXECUTION_FAILED'; | ||
| message = error.message; | ||
| functionName = error.functionName; | ||
| } | ||
|
|
||
| final Map<String, Object> errorMsg = { | ||
|
|
@@ -138,15 +144,18 @@ interface class SurfaceController implements SurfaceHost, A2uiMessageSink { | |
| 'code': errorCode, | ||
| 'surfaceId': ?surfaceId, | ||
| 'path': ?path, | ||
| 'functionName': ?functionName, | ||
| 'message': message, | ||
| }, | ||
| }; | ||
|
Comment on lines
130
to
150
Member
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. I'm not sure how many more error types we might want to add, but it might make sense to extract this A2ui*Exception -> error map logic to its own separate method (if we don't want to have a |
||
| _onSubmit.add( | ||
| ChatMessage.user( | ||
| '', | ||
| parts: [UiInteractionPart.create(jsonEncode(errorMsg))], | ||
| ), | ||
| ); | ||
| if (!_onSubmit.isClosed) { | ||
| _onSubmit.add( | ||
| ChatMessage.user( | ||
| '', | ||
| parts: [UiInteractionPart.create(jsonEncode(errorMsg))], | ||
| ), | ||
| ); | ||
| } | ||
|
gspencergoog marked this conversation as resolved.
|
||
| } | ||
|
|
||
| void _handleMessageInternal(A2uiMessage message) { | ||
|
|
||
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.
Diff is weird on this file; is this a symlink to a git submodule?
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.
QQ, do we need to modify the test runners to clone this package with submodules recursively, or is that the default?