demoTools function
Demo data tools for Query-backed dashboards: a store's orders, support
tickets and website traffic for the days up to today. A day's rows depend
only on its date. now defaults to the current time.
Implementation
List<OpenUiTool> demoTools({DateTime Function()? now}) {
final clock = now ?? DateTime.now;
return [
OpenUiTool(
name: 'get_orders',
description: "An online store's orders, one row per order, newest last",
inputSchema: const {
'type': 'object',
'properties': {'days': _days},
},
outputSchema: _rows({
'type': 'object',
'properties': {
'id': {'type': 'string'},
'date': {'type': 'string', 'description': 'YYYY-MM-DD'},
'region': {
'type': 'string',
'enum': ['North', 'South', 'East', 'West'],
},
'channel': {
'type': 'string',
'enum': ['Web', 'Mobile', 'Retail'],
},
'category': {'type': 'string'},
'product': {'type': 'string'},
'units': {'type': 'number'},
'amount': {'type': 'number', 'description': 'Order total in USD'},
},
}),
call: (args) async => {'rows': _orders(_lastDays(args, clock()))},
),
OpenUiTool(
name: 'get_tickets',
description:
'Support tickets opened, one row per ticket; hours and csat are set once a ticket is solved',
inputSchema: const {
'type': 'object',
'properties': {'days': _days},
},
outputSchema: _rows({
'type': 'object',
'properties': {
'id': {'type': 'string'},
'opened': {'type': 'string', 'description': 'YYYY-MM-DD'},
'team': {
'type': 'string',
'enum': ['Billing', 'Technical', 'Accounts', 'Shipping'],
},
'priority': {
'type': 'string',
'enum': ['low', 'normal', 'high', 'urgent'],
},
'status': {
'type': 'string',
'enum': ['open', 'pending', 'solved'],
},
'hours': {'type': 'number', 'description': 'Hours to resolve'},
'csat': {'type': 'number', 'description': 'Satisfaction 1 to 5'},
},
}),
call: (args) async => {'rows': _tickets(_lastDays(args, clock()))},
),
OpenUiTool(
name: 'get_traffic',
description:
'Daily website visits and signups, one row per day and source',
inputSchema: const {
'type': 'object',
'properties': {'days': _days},
},
outputSchema: _rows({
'type': 'object',
'properties': {
'date': {'type': 'string', 'description': 'YYYY-MM-DD'},
'source': {
'type': 'string',
'enum': ['Search', 'Social', 'Email', 'Direct', 'Referral'],
},
'visits': {'type': 'number'},
'signups': {'type': 'number'},
},
}),
call: (args) async => {'rows': _traffic(_lastDays(args, clock()))},
),
];
}