Documentation
¶
Overview ¶
Package genui provides Generative UI components for AI agents.
Index ¶
- Constants
- type AgentOutput
- type AgentResponse
- type ComponentType
- type ConfirmDialogData
- type OptionItem
- type OptionsListData
- type OutputType
- type ScheduleCardData
- type ScheduleData
- type TimePickerData
- type UIAction
- type UIComponent
- func NewConfirmDialog(title, message string, payload any, danger bool) *UIComponent
- func NewConfirmDialogWithLabels(title, message, confirmLabel, cancelLabel string, payload any, danger bool) *UIComponent
- func NewDatePicker(label string, defaultDate time.Time) *UIComponent
- func NewDeleteConfirmDialog(itemType, itemName string, payload any) *UIComponent
- func NewDurationPicker() *UIComponent
- func NewEndTimePicker(startTime time.Time) *UIComponent
- func NewErrorAlert(message string) *UIComponent
- func NewMemoCard(id, content string, createdTs int64, tags []string) *UIComponent
- func NewOptionsList(title string, options []OptionItem, multiSelect bool) *UIComponent
- func NewOptionsListWithDescription(title, description string, options []OptionItem, multiSelect bool) *UIComponent
- func NewProgressBar(label string, progress int, total int) *UIComponent
- func NewQuickActionPicker(actions []string) *UIComponent
- func NewReminderPicker() *UIComponent
- func NewScheduleCard(schedule *ScheduleData, status string) *UIComponent
- func NewScheduleCardFromRaw(id, title string, startTs, endTs int64, duration int, location, status string) *UIComponent
- func NewSuccessBanner(message string) *UIComponent
- func NewTextComponent(text string) *UIComponent
- func NewTimePicker(label string, defaultDate time.Time) *UIComponent
- func NewTimePickerWithRange(label string, defaultDate, minDate, maxDate time.Time, showTime bool) *UIComponent
- func NewTimeSlotPicker(title string, slots []time.Time) *UIComponent
- type UIGenerator
- func (g *UIGenerator) GenerateConfirmation(title, message string, payload any, danger bool) *AgentResponse
- func (g *UIGenerator) GenerateError(message string) *AgentResponse
- func (g *UIGenerator) GenerateFromAgentOutput(output *AgentOutput) *AgentResponse
- func (g *UIGenerator) GenerateOptionSelection(title string, options []OptionItem) *AgentResponse
- func (g *UIGenerator) GenerateSchedulePreview(schedule *ScheduleData) *AgentResponse
- func (g *UIGenerator) GenerateSuccess(message string) *AgentResponse
- func (g *UIGenerator) GenerateTimeSelection(suggestedTime any) *AgentResponse
Constants ¶
const ( TextSchedulePreviewPrompt = "已为您解析日程,请确认:" TextTimeSelectionPrompt = "请选择具体时间:" )
UI text constants for i18n readiness.
const ( CardStatusPreview = "preview" CardStatusConfirmed = "confirmed" CardStatusConflict = "conflict" )
CardStatus defines the status of a schedule card.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentOutput ¶
type AgentOutput struct {
SuggestedTime time.Time
Payload any
Schedule *ScheduleData
Type OutputType
Text string
Title string
Message string
Options []OptionItem
Danger bool
}
AgentOutput represents the raw output from an agent.
type AgentResponse ¶
type AgentResponse struct {
Text string `json:"text,omitempty"`
Components []UIComponent `json:"components,omitempty"`
Streaming bool `json:"streaming,omitempty"`
}
AgentResponse represents an enhanced agent response with UI components.
type ComponentType ¶
type ComponentType string
ComponentType defines the type of UI component.
const ( ComponentText ComponentType = "text" ComponentScheduleCard ComponentType = "schedule_card" ComponentMemoCard ComponentType = "memo_card" ComponentConfirmDialog ComponentType = "confirm_dialog" ComponentOptionsList ComponentType = "options_list" ComponentTimePicker ComponentType = "time_picker" ComponentProgressBar ComponentType = "progress_bar" ComponentErrorAlert ComponentType = "error_alert" ComponentSuccessBanner ComponentType = "success_banner" )
type ConfirmDialogData ¶
type ConfirmDialogData struct {
Title string `json:"title"`
Message string `json:"message"`
ConfirmText string `json:"confirm_text"`
CancelText string `json:"cancel_text"`
Danger bool `json:"danger"` // Red button for dangerous actions
}
ConfirmDialogData represents data for a confirmation dialog.
type OptionItem ¶
type OptionItem struct {
Value any `json:"value,omitempty"`
ID string `json:"id"`
Label string `json:"label"`
Description string `json:"description,omitempty"`
Icon string `json:"icon,omitempty"`
Selected bool `json:"selected"`
}
OptionItem represents a single option in an options list.
type OptionsListData ¶
type OptionsListData struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
Options []OptionItem `json:"options"`
MultiSelect bool `json:"multi_select"`
}
OptionsListData represents data for an options list component.
type OutputType ¶
type OutputType string
OutputType defines the type of agent output.
const ( OutputTypeText OutputType = "text" OutputTypeSchedulePreview OutputType = "schedule_preview" OutputTypeConfirmation OutputType = "confirmation" OutputTypeTimeAmbiguous OutputType = "time_ambiguous" OutputTypeMultipleOptions OutputType = "multiple_options" OutputTypeSuccess OutputType = "success" OutputTypeError OutputType = "error" )
type ScheduleCardData ¶
type ScheduleCardData struct {
ID string `json:"id,omitempty"`
Title string `json:"title"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
Status string `json:"status"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
Duration int `json:"duration"`
}
ScheduleCardData represents data for a schedule card component.
type ScheduleData ¶
type ScheduleData struct {
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
ID string `json:"id,omitempty"`
Title string `json:"title"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
Duration int `json:"duration"`
}
ScheduleData represents schedule information for card display.
type TimePickerData ¶
type TimePickerData struct {
Label string `json:"label"`
Format string `json:"format,omitempty"`
DefaultDate int64 `json:"default_date,omitempty"`
MinDate int64 `json:"min_date,omitempty"`
MaxDate int64 `json:"max_date,omitempty"`
ShowTime bool `json:"show_time"`
}
TimePickerData represents data for a time picker component.
type UIAction ¶
type UIAction struct {
Payload any `json:"payload,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Label string `json:"label"`
Style string `json:"style"`
}
UIAction represents an action button on a component.
type UIComponent ¶
type UIComponent struct {
Type ComponentType `json:"type"`
ID string `json:"id"`
Data any `json:"data"`
Actions []UIAction `json:"actions,omitempty"`
}
UIComponent represents a generic UI component.
func NewConfirmDialog ¶
func NewConfirmDialog(title, message string, payload any, danger bool) *UIComponent
NewConfirmDialog creates a new confirmation dialog component.
func NewConfirmDialogWithLabels ¶
func NewConfirmDialogWithLabels(title, message, confirmLabel, cancelLabel string, payload any, danger bool) *UIComponent
NewConfirmDialogWithLabels creates a confirmation dialog with custom button labels.
func NewDatePicker ¶
func NewDatePicker(label string, defaultDate time.Time) *UIComponent
NewDatePicker creates a date-only picker (without time selection).
func NewDeleteConfirmDialog ¶
func NewDeleteConfirmDialog(itemType, itemName string, payload any) *UIComponent
NewDeleteConfirmDialog creates a confirmation dialog for delete operations.
func NewDurationPicker ¶
func NewDurationPicker() *UIComponent
NewDurationPicker creates an options list for selecting duration.
func NewEndTimePicker ¶
func NewEndTimePicker(startTime time.Time) *UIComponent
NewEndTimePicker creates a time picker for selecting end time.
func NewErrorAlert ¶
func NewErrorAlert(message string) *UIComponent
NewErrorAlert creates an error alert component.
func NewMemoCard ¶
func NewMemoCard(id, content string, createdTs int64, tags []string) *UIComponent
NewMemoCard creates a memo card component.
func NewOptionsList ¶
func NewOptionsList(title string, options []OptionItem, multiSelect bool) *UIComponent
NewOptionsList creates a new options list component.
func NewOptionsListWithDescription ¶
func NewOptionsListWithDescription(title, description string, options []OptionItem, multiSelect bool) *UIComponent
NewOptionsListWithDescription creates an options list with a description.
func NewProgressBar ¶
func NewProgressBar(label string, progress int, total int) *UIComponent
NewProgressBar creates a progress bar component.
func NewQuickActionPicker ¶
func NewQuickActionPicker(actions []string) *UIComponent
NewQuickActionPicker creates an options list for quick actions.
func NewReminderPicker ¶
func NewReminderPicker() *UIComponent
NewReminderPicker creates an options list for selecting reminder time.
func NewScheduleCard ¶
func NewScheduleCard(schedule *ScheduleData, status string) *UIComponent
NewScheduleCard creates a new schedule card component.
func NewScheduleCardFromRaw ¶
func NewScheduleCardFromRaw(id, title string, startTs, endTs int64, duration int, location, status string) *UIComponent
NewScheduleCardFromRaw creates a schedule card from raw data.
func NewSuccessBanner ¶
func NewSuccessBanner(message string) *UIComponent
NewSuccessBanner creates a success banner component.
func NewTextComponent ¶
func NewTextComponent(text string) *UIComponent
NewTextComponent creates a simple text component.
func NewTimePicker ¶
func NewTimePicker(label string, defaultDate time.Time) *UIComponent
NewTimePicker creates a new time picker component.
func NewTimePickerWithRange ¶
func NewTimePickerWithRange(label string, defaultDate, minDate, maxDate time.Time, showTime bool) *UIComponent
NewTimePickerWithRange creates a time picker with custom date range.
func NewTimeSlotPicker ¶
func NewTimeSlotPicker(title string, slots []time.Time) *UIComponent
NewTimeSlotPicker creates an options list for selecting time slots.
type UIGenerator ¶
type UIGenerator struct{}
UIGenerator generates UI components from agent outputs.
func (*UIGenerator) GenerateConfirmation ¶
func (g *UIGenerator) GenerateConfirmation(title, message string, payload any, danger bool) *AgentResponse
GenerateConfirmation generates a confirmation dialog.
func (*UIGenerator) GenerateError ¶
func (g *UIGenerator) GenerateError(message string) *AgentResponse
GenerateError generates an error alert.
func (*UIGenerator) GenerateFromAgentOutput ¶
func (g *UIGenerator) GenerateFromAgentOutput(output *AgentOutput) *AgentResponse
GenerateFromAgentOutput generates UI components from agent output.
func (*UIGenerator) GenerateOptionSelection ¶
func (g *UIGenerator) GenerateOptionSelection(title string, options []OptionItem) *AgentResponse
GenerateOptionSelection generates an options list.
func (*UIGenerator) GenerateSchedulePreview ¶
func (g *UIGenerator) GenerateSchedulePreview(schedule *ScheduleData) *AgentResponse
GenerateSchedulePreview generates a schedule preview card.
func (*UIGenerator) GenerateSuccess ¶
func (g *UIGenerator) GenerateSuccess(message string) *AgentResponse
GenerateSuccess generates a success banner.
func (*UIGenerator) GenerateTimeSelection ¶
func (g *UIGenerator) GenerateTimeSelection(suggestedTime any) *AgentResponse
GenerateTimeSelection generates a time picker.