diff --git a/app/controllers/api/v1/accounts/integrations/captain_controller.rb b/app/controllers/api/v1/accounts/integrations/captain_controller.rb index 15e81b726..6813d14b5 100644 --- a/app/controllers/api/v1/accounts/integrations/captain_controller.rb +++ b/app/controllers/api/v1/accounts/integrations/captain_controller.rb @@ -2,10 +2,22 @@ class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::Ba before_action :hook def proxy + request_url = build_request_url(request_path) response = HTTParty.send(request_method, request_url, body: permitted_params[:body].to_json, headers: headers) render plain: response.body, status: response.code end + def copilot + request_url = build_request_url(build_request_path("/assistants/#{hook.settings['assistant_id']}/copilot")) + params = { + previous_messages: copilot_params[:previous_messages], + conversation_history: conversation_history, + message: copilot_params[:message] + } + response = HTTParty.send(:post, request_url, body: params.to_json, headers: headers) + render plain: response.body, status: response.code + end + private def headers @@ -17,15 +29,19 @@ class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::Ba } end + def build_request_path(route) + "api/accounts/#{hook.settings['account_id']}#{route}" + end + def request_path request_route = with_leading_hash_on_route(params[:route]) return 'api/sessions/profile' if request_route == '/sessions/profile' - "api/accounts/#{hook.settings['account_id']}#{request_route}" + build_request_path(request_route) end - def request_url + def build_request_url(request_path) base_url = InstallationConfig.find_by(name: 'CAPTAIN_API_URL').value URI.join(base_url, request_path).to_s end @@ -47,6 +63,15 @@ class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::Ba request_route.start_with?('/') ? request_route : "/#{request_route}" end + def conversation_history + conversation = Current.account.conversations.find_by!(display_id: copilot_params[:conversation_id]) + conversation.to_llm_text + end + + def copilot_params + params.permit(:previous_messages, :conversation_id, :message) + end + def permitted_params params.permit(:method, :route, body: {}) end diff --git a/app/javascript/dashboard/api/integrations.js b/app/javascript/dashboard/api/integrations.js index 59a3e244a..b78a2ea7e 100644 --- a/app/javascript/dashboard/api/integrations.js +++ b/app/javascript/dashboard/api/integrations.js @@ -36,6 +36,10 @@ class IntegrationsAPI extends ApiClient { requestCaptain(body) { return axios.post(`${this.baseUrl()}/integrations/captain/proxy`, body); } + + requestCaptainCopilot(body) { + return axios.post(`${this.baseUrl()}/integrations/captain/copilot`, body); + } } export default new IntegrationsAPI(); diff --git a/app/javascript/dashboard/assets/scss/_woot.scss b/app/javascript/dashboard/assets/scss/_woot.scss index e3474e616..fdd467f5f 100644 --- a/app/javascript/dashboard/assets/scss/_woot.scss +++ b/app/javascript/dashboard/assets/scss/_woot.scss @@ -72,6 +72,19 @@ --slate-11: 96 100 108; --slate-12: 28 32 36; + --iris-1: 253 253 255; + --iris-2: 248 248 255; + --iris-3: 240 241 254; + --iris-4: 230 231 255; + --iris-5: 218 220 255; + --iris-6: 203 205 255; + --iris-7: 184 186 248; + --iris-8: 155 158 240; + --iris-9: 91 91 214; + --iris-10: 81 81 205; + --iris-11: 87 83 198; + --iris-12: 39 41 98; + --ruby-1: 255 252 253; --ruby-2: 255 247 248; --ruby-3: 254 234 237; @@ -147,6 +160,19 @@ --slate-11: 176 180 186; --slate-12: 237 238 240; + --iris-1: 19 19 30; + --iris-2: 23 22 37; + --iris-3: 32 34 72; + --iris-4: 38 42 101; + --iris-5: 48 51 116; + --iris-6: 61 62 130; + --iris-7: 74 74 149; + --iris-8: 89 88 177; + --iris-9: 91 91 214; + --iris-10: 84 114 228; + --iris-11: 158 177 255; + --iris-12: 224 223 254; + --ruby-1: 25 17 19; --ruby-2: 30 21 23; --ruby-3: 58 20 30; diff --git a/app/javascript/dashboard/components-next/copilot/Copilot.story.vue b/app/javascript/dashboard/components-next/copilot/Copilot.story.vue new file mode 100644 index 000000000..ece5ec31f --- /dev/null +++ b/app/javascript/dashboard/components-next/copilot/Copilot.story.vue @@ -0,0 +1,60 @@ + + + + + + + diff --git a/app/javascript/dashboard/components-next/copilot/Copilot.vue b/app/javascript/dashboard/components-next/copilot/Copilot.vue new file mode 100644 index 000000000..3839532f2 --- /dev/null +++ b/app/javascript/dashboard/components-next/copilot/Copilot.vue @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + diff --git a/app/javascript/dashboard/components-next/copilot/CopilotAgentMessage.vue b/app/javascript/dashboard/components-next/copilot/CopilotAgentMessage.vue new file mode 100644 index 000000000..ef8c2faf4 --- /dev/null +++ b/app/javascript/dashboard/components-next/copilot/CopilotAgentMessage.vue @@ -0,0 +1,31 @@ + + + + + + + {{ $t('CAPTAIN.COPILOT.YOU') }} + + {{ message.content }} + + + + diff --git a/app/javascript/dashboard/components-next/copilot/CopilotAssistantMessage.vue b/app/javascript/dashboard/components-next/copilot/CopilotAssistantMessage.vue new file mode 100644 index 000000000..a14508150 --- /dev/null +++ b/app/javascript/dashboard/components-next/copilot/CopilotAssistantMessage.vue @@ -0,0 +1,27 @@ + + + + + + + {{ $t('CAPTAIN.NAME') }} + + {{ message.content }} + + + + diff --git a/app/javascript/dashboard/components-next/copilot/CopilotInput.vue b/app/javascript/dashboard/components-next/copilot/CopilotInput.vue new file mode 100644 index 000000000..bf14945b5 --- /dev/null +++ b/app/javascript/dashboard/components-next/copilot/CopilotInput.vue @@ -0,0 +1,34 @@ + + + + + + + + + + diff --git a/app/javascript/dashboard/components-next/copilot/CopilotLoader.story.vue b/app/javascript/dashboard/components-next/copilot/CopilotLoader.story.vue new file mode 100644 index 000000000..3a5de84c7 --- /dev/null +++ b/app/javascript/dashboard/components-next/copilot/CopilotLoader.story.vue @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/javascript/dashboard/components-next/copilot/CopilotLoader.vue b/app/javascript/dashboard/components-next/copilot/CopilotLoader.vue new file mode 100644 index 000000000..723439f33 --- /dev/null +++ b/app/javascript/dashboard/components-next/copilot/CopilotLoader.vue @@ -0,0 +1,22 @@ + + + + + + + {{ $t('CAPTAIN.COPILOT.LOADER') }} + + + + + + + + + diff --git a/app/javascript/dashboard/components/ChatList.vue b/app/javascript/dashboard/components/ChatList.vue index 0108e02df..953d5f2cc 100644 --- a/app/javascript/dashboard/components/ChatList.vue +++ b/app/javascript/dashboard/components/ChatList.vue @@ -785,7 +785,7 @@ watch(conversationFilters, (newVal, oldVal) => { class="flex flex-col flex-shrink-0 border-r conversations-list-wrap rtl:border-r-0 rtl:border-l border-slate-50 dark:border-slate-800/50" :class="[ { hidden: !showConversationList }, - isOnExpandedLayout ? 'basis-full' : 'flex-basis-clamp', + isOnExpandedLayout ? 'basis-full' : 'w-[360px]', ]" > @@ -916,12 +916,3 @@ watch(conversationFilters, (newVal, oldVal) => { - - diff --git a/app/javascript/dashboard/components/copilot/CopilotContainer.vue b/app/javascript/dashboard/components/copilot/CopilotContainer.vue new file mode 100644 index 000000000..940408ef8 --- /dev/null +++ b/app/javascript/dashboard/components/copilot/CopilotContainer.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/app/javascript/dashboard/components/widgets/conversation/ConversationBox.vue b/app/javascript/dashboard/components/widgets/conversation/ConversationBox.vue index 210357a8b..f56b2a581 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ConversationBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ConversationBox.vue @@ -1,14 +1,14 @@ + + + + + + + + + + + + diff --git a/app/javascript/dashboard/i18n/locale/en/conversation.json b/app/javascript/dashboard/i18n/locale/en/conversation.json index 9a6a64d6d..f9c3b784a 100644 --- a/app/javascript/dashboard/i18n/locale/en/conversation.json +++ b/app/javascript/dashboard/i18n/locale/en/conversation.json @@ -219,6 +219,10 @@ "DELETE": "Delete", "CANCEL": "Cancel" } + }, + "SIDEBAR": { + "CONTACT": "Contact", + "COPILOT": "Copilot" } }, "EMAIL_TRANSCRIPT": { diff --git a/app/javascript/dashboard/i18n/locale/en/integrations.json b/app/javascript/dashboard/i18n/locale/en/integrations.json index f6e8cbc3a..e04164902 100644 --- a/app/javascript/dashboard/i18n/locale/en/integrations.json +++ b/app/javascript/dashboard/i18n/locale/en/integrations.json @@ -299,5 +299,13 @@ "ERROR": "There was an error unlinking the issue, please try again" } } + }, + "CAPTAIN": { + "NAME": "Captain", + "COPILOT": { + "SEND_MESSAGE": "Send message...", + "LOADER": "Captain is thinking", + "YOU": "You" + } } } diff --git a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue index e998a85a1..8739b4f26 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue @@ -92,9 +92,7 @@ onMounted(() => { - + - + hook.settings['account_email'], + 'X-User-Token' => hook.settings['access_token'], + 'Content-Type' => 'application/json' + }) + .to_return(status: 200, body: 'Success', headers: {}) + + post copilot_api_v1_account_integrations_captain_url(account_id: account.id), + params: { + message: 'hello', + previous_messages: [], + conversation_id: conversation.display_id + }, + headers: agent.create_new_auth_token, + as: :json + + expect(response).to have_http_status(:success) + expect(response.body).to eq('Success') + end + end + end + end end diff --git a/spec/services/llm_formatter/conversation_llm_formatter_spec.rb b/spec/services/llm_formatter/conversation_llm_formatter_spec.rb new file mode 100644 index 000000000..3838b8126 --- /dev/null +++ b/spec/services/llm_formatter/conversation_llm_formatter_spec.rb @@ -0,0 +1,51 @@ +require 'rails_helper' + +RSpec.describe LlmFormatter::ConversationLlmFormatter do + let(:account) { create(:account) } + let(:conversation) { create(:conversation, account: account) } + let(:formatter) { described_class.new(conversation) } + + describe '#format' do + context 'when conversation has no messages' do + it 'returns basic conversation info with no messages' do + expected_output = [ + "Conversation ID: ##{conversation.display_id}", + "Channel: #{conversation.inbox.channel.name}", + 'Message History:', + 'No messages in this conversation' + ].join("\n") + + expect(formatter.format).to eq(expected_output) + end + end + + context 'when conversation has messages' do + it 'formats messages in chronological order with sender labels' do + create( + :message, + conversation: conversation, + message_type: 'incoming', + content: 'Hello, I need help' + ) + + create( + :message, + conversation: conversation, + message_type: 'outgoing', + content: 'How can I assist you today?' + ) + + expected_output = [ + "Conversation ID: ##{conversation.display_id}", + "Channel: #{conversation.inbox.channel.name}", + 'Message History:', + 'User: Hello, I need help', + 'Support agent: How can I assist you today?', + '' + ].join("\n") + + expect(formatter.format).to eq(expected_output) + end + end + end +end diff --git a/theme/colors.js b/theme/colors.js index 150106c65..47fd65c8d 100644 --- a/theme/colors.js +++ b/theme/colors.js @@ -300,6 +300,21 @@ export const colors = { 12: 'rgb(var(--slate-12) / )', }, + iris: { + 1: 'rgb(var(--iris-1) / )', + 2: 'rgb(var(--iris-2) / )', + 3: 'rgb(var(--iris-3) / )', + 4: 'rgb(var(--iris-4) / )', + 5: 'rgb(var(--iris-5) / )', + 6: 'rgb(var(--iris-6) / )', + 7: 'rgb(var(--iris-7) / )', + 8: 'rgb(var(--iris-8) / )', + 9: 'rgb(var(--iris-9) / )', + 10: 'rgb(var(--iris-10) / )', + 11: 'rgb(var(--iris-11) / )', + 12: 'rgb(var(--iris-12) / )', + }, + ruby: { 1: 'rgb(var(--ruby-1) / )', 2: 'rgb(var(--ruby-2) / )',