Update copilot
This commit is contained in:
@@ -159,7 +159,14 @@ watch(
|
||||
:conversation-inbox-type="conversationInboxType"
|
||||
/>
|
||||
</template>
|
||||
<CopilotThinkingGroup v-else :messages="item.messages" />
|
||||
<CopilotThinkingGroup
|
||||
v-else
|
||||
:messages="item.messages"
|
||||
:has-assistant-message-after="
|
||||
groupedMessages[groupedMessages.indexOf(item) + 1]?.message
|
||||
?.role === 'assistant'
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<CopilotLoader v-if="isCaptainTyping" />
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import Icon from '../icon/Icon.vue';
|
||||
import CopilotThinkingBlock from 'dashboard/components/copilot/CopilotThinkingBlock.vue';
|
||||
|
||||
defineProps({ messages: { type: Array, required: true } });
|
||||
const props = defineProps({
|
||||
messages: { type: Array, required: true },
|
||||
hasAssistantMessageAfter: { type: Boolean, default: false },
|
||||
});
|
||||
const { t } = useI18n();
|
||||
const isExpanded = ref(false);
|
||||
const isExpanded = ref(!props.hasAssistantMessageAfter);
|
||||
|
||||
watch(
|
||||
() => props.hasAssistantMessageAfter,
|
||||
newValue => {
|
||||
if (newValue) {
|
||||
isExpanded.value = false;
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="flex flex-col gap-2 pl-4">
|
||||
<button
|
||||
class="flex items-center gap-2 text-xs text-n-slate-10 hover:text-n-slate-11"
|
||||
@click="isExpanded = !isExpanded"
|
||||
|
||||
@@ -132,7 +132,7 @@ const handleClose = () => {
|
||||
<template>
|
||||
<div
|
||||
v-if="isSidebarOpen"
|
||||
class="border-l border-n-weak w-[18rem] min-w-[18rem]"
|
||||
class="border-l border-n-weak w-[20rem] min-w-[20rem]"
|
||||
>
|
||||
<Copilot
|
||||
:messages="messages"
|
||||
|
||||
@@ -12,13 +12,13 @@ defineProps({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-2 p-2 rounded bg-n-background">
|
||||
<div class="flex flex-col gap-1 px-2 rounded bg-n-background">
|
||||
<div
|
||||
v-if="reasoning"
|
||||
class="text-xs text-n-slate-11 border-t border-n-weak pt-2"
|
||||
class="text-xs text-n-slate-11 border-t border-n-weak"
|
||||
>
|
||||
{{ reasoning }}
|
||||
</div>
|
||||
<p class="text-sm text-n-slate-12">{{ content }}</p>
|
||||
<p class="text-sm text-n-slate-11">{{ content }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -35,7 +35,7 @@ const closeConversationPanel = () => {
|
||||
<template>
|
||||
<div
|
||||
v-if="showConversationSidebar"
|
||||
class="ltr:border-l rtl:border-r border-n-weak h-full overflow-hidden z-10 w-[18rem] min-w-[18rem] flex flex-col"
|
||||
class="ltr:border-l rtl:border-r border-n-weak h-full overflow-hidden z-10 w-[20rem] min-w-[20rem] flex flex-col"
|
||||
>
|
||||
<div class="flex flex-1 flex-col overflow-auto">
|
||||
<div
|
||||
|
||||
@@ -2,6 +2,7 @@ class Captain::ProcessCopilotMessageJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(assistant_id:, message:, options: {})
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Starting job for assistant_id=#{assistant_id}")
|
||||
ensure_assistant(assistant_id)
|
||||
ensure_user(options[:user_id])
|
||||
process_message(message, options)
|
||||
@@ -10,17 +11,22 @@ class Captain::ProcessCopilotMessageJob < ApplicationJob
|
||||
private
|
||||
|
||||
def ensure_assistant(assistant_id)
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Finding assistant with id=#{assistant_id}")
|
||||
@assistant = Captain::Assistant.find(assistant_id)
|
||||
@account = @assistant.account
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Found assistant for account_id=#{@account.id}")
|
||||
end
|
||||
|
||||
def ensure_user(user_id)
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Finding user with id=#{user_id}")
|
||||
@user = @account.users.find(user_id)
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Found user #{@user.name}")
|
||||
end
|
||||
|
||||
def process_message(message, options)
|
||||
return unless @assistant
|
||||
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Processing message with conversation_id=#{options[:conversation_id]}")
|
||||
conversation = find_conversation(options[:conversation_id])
|
||||
generate_chat_response(message, conversation, options[:previous_history])
|
||||
end
|
||||
@@ -32,6 +38,7 @@ class Captain::ProcessCopilotMessageJob < ApplicationJob
|
||||
end
|
||||
|
||||
def generate_chat_response(message, conversation, previous_history)
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Generating chat response for conversation_id=#{conversation&.display_id}")
|
||||
Captain::Copilot::ChatService.new(
|
||||
@assistant,
|
||||
previous_messages: previous_history || [],
|
||||
@@ -45,6 +52,7 @@ class Captain::ProcessCopilotMessageJob < ApplicationJob
|
||||
end
|
||||
|
||||
def broadcast_response(data)
|
||||
Rails.logger.info("[Captain::ProcessCopilotMessageJob] Broadcasting response to account_id=#{@account.id} user_id=#{@user.id}")
|
||||
ActionCable.server.broadcast(
|
||||
"copilot_#{@account.id}_#{@user.id}",
|
||||
{ event: 'copilot.response', data: data }
|
||||
|
||||
@@ -28,9 +28,12 @@ class Captain::Copilot::ChatService < Llm::BaseOpenAiService
|
||||
end
|
||||
|
||||
def build_initial_messages(config)
|
||||
Rails.logger.info("[CAPTAIN][CopilotChatService] Building initial messages for conversation_id=#{@conversation_id}")
|
||||
messages = [system_message]
|
||||
messages += (config[:previous_messages] || [])
|
||||
Rails.logger.info("[CAPTAIN][CopilotChatService] Added #{config[:previous_messages]&.length || 0} previous messages")
|
||||
messages << current_viewing_history if @conversation_id
|
||||
Rails.logger.info("[CAPTAIN][CopilotChatService] Total messages built: #{messages.length}")
|
||||
messages
|
||||
end
|
||||
|
||||
@@ -53,6 +56,7 @@ class Captain::Copilot::ChatService < Llm::BaseOpenAiService
|
||||
private
|
||||
|
||||
def system_message
|
||||
Rails.logger.info("[CAPTAIN][CopilotChatService] Generating system message for product=#{@assistant.config['product_name']} language=#{@language}")
|
||||
{
|
||||
role: 'system',
|
||||
content: Captain::Llm::SystemPromptsService.copilot_response_generator(@assistant.config['product_name'], @language, @assistant.account_id)
|
||||
@@ -60,6 +64,7 @@ class Captain::Copilot::ChatService < Llm::BaseOpenAiService
|
||||
end
|
||||
|
||||
def current_viewing_history
|
||||
Rails.logger.info("[CAPTAIN][CopilotChatService] Fetching viewing history for conversation_id=#{@conversation_id}")
|
||||
return unless @conversation_id
|
||||
|
||||
{
|
||||
|
||||
@@ -12,11 +12,11 @@ class Captain::Tools::Copilot::GetContactService < Captain::Tools::BaseService
|
||||
type: 'object',
|
||||
properties: {
|
||||
contact_id: {
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
description: 'The ID of the contact to retrieve'
|
||||
},
|
||||
account_id: {
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
description: 'The ID of the account the contact belongs to'
|
||||
}
|
||||
},
|
||||
|
||||
@@ -12,11 +12,11 @@ class Captain::Tools::Copilot::GetConversationService < Captain::Tools::BaseServ
|
||||
type: 'object',
|
||||
properties: {
|
||||
conversation_id: {
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
description: 'The ID of the conversation to retrieve'
|
||||
},
|
||||
account_id: {
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
description: 'The ID of the account the conversation belongs to'
|
||||
}
|
||||
},
|
||||
|
||||
@@ -12,7 +12,7 @@ class Captain::Tools::Copilot::SearchContactService < Captain::Tools::BaseServic
|
||||
type: 'object',
|
||||
properties: {
|
||||
account_id: {
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
description: 'The ID of the account to search contacts in'
|
||||
},
|
||||
email: {
|
||||
|
||||
@@ -12,11 +12,11 @@ class Captain::Tools::Copilot::SearchConversationService < Captain::Tools::BaseS
|
||||
type: 'object',
|
||||
properties: {
|
||||
account_id: {
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
description: 'The ID of the account to search conversations in'
|
||||
},
|
||||
contact_id: {
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
description: 'Filter conversations by contact ID'
|
||||
},
|
||||
status: {
|
||||
|
||||
Reference in New Issue
Block a user