Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b49f458
-
polina-c Dec 24, 2025
62e769d
-
polina-c Dec 24, 2025
5b70ebc
Update mesage.dart
polina-c Dec 24, 2025
47f4ef5
Update mesage.dart
polina-c Dec 24, 2025
ed024ad
-
polina-c Dec 24, 2025
0f37256
Update genai_primitives.dart
polina-c Dec 24, 2025
918e4d9
Update genai_primitives_test.dart
polina-c Dec 24, 2025
daaa464
-
polina-c Dec 24, 2025
0452bea
-
polina-c Dec 24, 2025
87cc5dd
-
polina-c Dec 24, 2025
724ba2b
-
polina-c Dec 24, 2025
2ea87b5
-
polina-c Dec 24, 2025
5887cc4
-
polina-c Dec 24, 2025
f6af083
-
polina-c Dec 24, 2025
f259308
Update genai_primitives_test.dart
polina-c Dec 24, 2025
5110939
-
polina-c Dec 24, 2025
31e666a
Update message_parts.dart
polina-c Dec 24, 2025
6a245e8
-
polina-c Dec 26, 2025
52eb3a7
Update message_parts.dart
polina-c Dec 26, 2025
af0d06b
ci: add workflow_dispatch to enable manual CI triggers (#633)
andrewkolos Jan 5, 2026
4ebab33
Add A2UI support section to README (#648)
jacobsimionato Jan 5, 2026
0d4e92d
Update dartantic_ai dependency (#649)
gspencergoog Jan 5, 2026
910f4c5
Post publish commit to add sections to CHANGELOGs (#650)
gspencergoog Jan 5, 2026
4bf48a4
[docs] Suggest using `flutter pub add` for adding dependencies (#645)
parlough Jan 6, 2026
9f14e62
Improve error handling for catalog example loading (#653)
nan-yu Jan 6, 2026
c29fca4
-
polina-c Jan 9, 2026
56e12a8
Update message.dart
polina-c Jan 9, 2026
36593a0
---
polina-c Jan 9, 2026
167109f
--
polina-c Jan 9, 2026
dee7e6b
-
polina-c Jan 9, 2026
1eb2b23
-
polina-c Jan 9, 2026
b3c3014
Create custom_part_test.dart
polina-c Jan 9, 2026
aebee60
Update custom_part_test.dart
polina-c Jan 9, 2026
62a421d
-
polina-c Jan 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/flutter_packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
name: Flutter GenUI CI

on:
workflow_dispatch:
push:
branches:
- main
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ graph TD
genui_google_generative_ai --> genui
```

## A2UI Support

The Flutter Gen UI SDK uses the [A2UI protocol](https://a2ui.org) to represent UI content internally. The [genui_a2ui](packages/genui_a2ui/) package allows it to act as a renderer for UIs generated by an A2UI backend agent, similar to the [other A2UI renderers](https://github.com/google/A2UI/tree/main/renderers) which are maintained within the A2UI repository.

The Flutter Gen UI SDK currently supports A2UI v0.8.

## Getting started

See the [genui getting started guide](packages/genui/README.md#getting-started-with-genui).
Expand Down
124 changes: 76 additions & 48 deletions packages/genai_primitives/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,26 @@ import 'dart:typed_data';
import 'package:genai_primitives/genai_primitives.dart';
import 'package:json_schema_builder/json_schema_builder.dart';

void main() {
print('--- GenAI Primitives Example ---');
enum Role { system, user, model }

class ChatMessage {
final Role role;
final Message content;

const ChatMessage({required this.role, required this.content});

const ChatMessage.system(Message content)
: this(role: Role.system, content: content);

const ChatMessage.user(Message content)
: this(role: Role.user, content: content);

const ChatMessage.model(Message content)
: this(role: Role.model, content: content);
}

void main({void Function(Object? object) output = print}) {
output('--- GenAI Primitives Example ---');

// 1. Define a Tool
final ToolDefinition<Object> getWeatherTool = ToolDefinition(
Expand All @@ -29,92 +47,102 @@ void main() {
),
);

print('\n[Tool Definition]');
print(const JsonEncoder.withIndent(' ').convert(getWeatherTool.toJson()));
output('\n[Tool Definition]');
output(const JsonEncoder.withIndent(' ').convert(getWeatherTool.toJson()));

// 2. Create a conversation history
final history = <ChatMessage>[
// System message
ChatMessage.system(
'You are a helpful weather assistant. '
'Use the get_weather tool when needed.',
Message.fromText(
'You are a helpful weather assistant. '
'Use the get_weather tool when needed.',
),
),

// User message asking for weather
ChatMessage.user('What is the weather in London?'),
ChatMessage.user(Message.fromText('What is the weather in London?')),
];

print('\n[Initial Conversation]');
output('\n[Initial Conversation]');
for (final msg in history) {
print('${msg.role.name}: ${msg.text}');
output('${msg.role.name}: ${msg.content.text}');
}

// 3. Simulate Model Response with Tool Call
final modelResponse = ChatMessage.model(
'', // Empty text for tool call
parts: [
const TextPart('Thinking: User wants weather for London...'),
const ToolPart.call(
callId: 'call_123',
toolName: 'get_weather',
arguments: {'location': 'London', 'unit': 'celsius'},
),
],
Message.fromText(
'', // Empty text for tool call
parts: [
const TextPart('Thinking: User wants weather for London...'),
const ToolPart.call(
callId: 'call_123',
toolName: 'get_weather',
arguments: {'location': 'London', 'unit': 'celsius'},
),
],
),
);
history.add(modelResponse);

print('\n[Model Response with Tool Call]');
if (modelResponse.hasToolCalls) {
for (final ToolPart call in modelResponse.toolCalls) {
print('Tool Call: ${call.toolName}(${call.arguments})');
output('\n[Model Response with Tool Call]');
if (modelResponse.content.hasToolCalls) {
for (final ToolPart call in modelResponse.content.toolCalls) {
output('Tool Call: ${call.toolName}(${call.arguments})');
}
}

// 4. Simulate Tool Execution & Result
final toolResult = ChatMessage.user(
'', // User role is typically used for tool results in many APIs
parts: [
const ToolPart.result(
callId: 'call_123',
toolName: 'get_weather',
result: {'temperature': 15, 'condition': 'Cloudy'},
),
],
Message.fromText(
'', // User role is typically used for tool results in many APIs
parts: [
const ToolPart.result(
callId: 'call_123',
toolName: 'get_weather',
result: {'temperature': 15, 'condition': 'Cloudy'},
),
],
),
);
history.add(toolResult);

print('\n[Tool Result]');
print('Result: ${toolResult.toolResults.first.result}');
output('\n[Tool Result]');
output('Result: ${toolResult.content.toolResults.first.result}');

// 5. Simulate Final Model Response with Data (e.g. an image generated or
// returned)
final finalResponse = ChatMessage.model(
'Here is a chart of the weather trend:',
parts: [
DataPart(
Uint8List.fromList([0x89, 0x50, 0x4E, 0x47]), // Fake PNG header
mimeType: 'image/png',
name: 'weather_chart.png',
),
],
Message.fromText(
'Here is a chart of the weather trend:',
parts: [
DataPart(
Uint8List.fromList([0x89, 0x50, 0x4E, 0x47]), // Fake PNG header
mimeType: 'image/png',
name: 'weather_chart.png',
),
],
),
);
history.add(finalResponse);

print('\n[Final Model Response with Data]');
print('Text: ${finalResponse.text}');
if (finalResponse.parts.any((p) => p is DataPart)) {
final DataPart dataPart = finalResponse.parts.whereType<DataPart>().first;
print(
output('\n[Final Model Response with Data]');
output('Text: ${finalResponse.content.text}');
if (finalResponse.content.parts.any((p) => p is DataPart)) {
final DataPart dataPart = finalResponse.content.parts
.whereType<DataPart>()
.first;
output(
'Attachment: ${dataPart.name} '
'(${dataPart.mimeType}, ${dataPart.bytes.length} bytes)',
);
}

// 6. Demonstrate JSON serialization of the whole history
print('\n[Full History JSON]');
print(
output('\n[Full History JSON]');
output(
const JsonEncoder.withIndent(
' ',
).convert(history.map((m) => m.toJson()).toList()),
).convert(history.map((m) => m.content.toJson()).toList()),
);
}
2 changes: 1 addition & 1 deletion packages/genai_primitives/lib/genai_primitives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
/// A set of primitives for working with generative AI.
library;

export 'src/chat_message.dart';
export 'src/message.dart';
export 'src/message_parts.dart';
export 'src/tool_definition.dart';
141 changes: 0 additions & 141 deletions packages/genai_primitives/lib/src/chat_message.dart

This file was deleted.

Loading
Loading