<& /Admin/Elements/Header, Title => loc('Create Queue with AI') &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
% if ( $enabled ) { <&| /Widgets/TitleBox, title => loc('AI Queue Creation Assistant'), content_class => 'p-0' &>
% if ( @$history ) { % # Render the welcome message first, then the stored conversation
<% $ai_avatar_html |n %>
<% loc("Hello! I'm here to help you set up a new queue. Tell me about the work your team handles. What kind of requests come in, and how does your team process them?") %>
% for my $entry ( @$history ) { % if ( $entry->{role} eq 'user' ) {
<% $user_avatar_html |n %>
<% $entry->{content} |h %>
% } else {
<% $ai_avatar_html |n %>
<% $entry->{content} |h %>
% } % } % } else {
<% $ai_avatar_html |n %>
<% loc("Hello! I'm here to help you set up a new queue. Tell me about the work your team handles. What kind of requests come in, and how does your team process them?") %>
% }
% } else {
<% loc("The AI queue creation assistant is not enabled. To enable it, set [_1] in your AI provider configuration.", 'queue_creation_assistant => 1') %>
% }
<%init> my @results; my $config = RT->Config->Get('RT_AI_Provider'); my $default_config = $config ? ( $config->{Default} || {} ) : {}; my $enabled = $default_config->{queue_creation_assistant} ? 1 : 0; my $session_id = ''; my $user_avatar_html = ''; my $ai_avatar_html = ''; my $history = []; if ( $enabled ) { # Start a new chat if requested via ?new=1, then redirect to clean URL if ( $ARGS{new} ) { my $new_id = time() . '-' . int(rand(100000)); $session{'AIChat_session_id'} = $new_id; RT::Interface::Web::Session::Set( Key => 'AIChat_session_id', Value => $new_id ); $session{'AIChat_history'} = []; RT::Interface::Web::Session::Set( Key => 'AIChat_history', Value => [] ); RT::Interface::Web::Redirect( RT->Config->Get('WebURL') . 'Admin/Queues/CreateWithAI.html' ); } else { $session_id = $session{'AIChat_session_id'} || ''; unless ( $session_id ) { $session_id = time() . '-' . int(rand(100000)); $session{'AIChat_session_id'} = $session_id; RT::Interface::Web::Session::Set( Key => 'AIChat_session_id', Value => $session_id ); $session{'AIChat_history'} = []; RT::Interface::Web::Session::Set( Key => 'AIChat_history', Value => [] ); } } $history = $session{'AIChat_history'} || []; # User avatar — RT picks uploaded image or initials fallback my $user = $session{CurrentUser}->UserObj; $user_avatar_html = $m->scomp('/Elements/ShowUser', User => $user, ShowOnlyUserAvatar => 1, Link => 0, ShowPopover => 0, ); # AI avatar $ai_avatar_html = 'AI'; }