# Pull Request Template ## Description This PR includes an update to the Captain navigation structure. ## Route Structure ```javascript 1. captain_assistants_responses_index → /captain/:assistantId/faqs 2. captain_assistants_documents_index → /captain/:assistantId/documents 3. captain_assistants_scenarios_index → /captain/:assistantId/scenarios 4. captain_assistants_playground_index → /captain/:assistantId/playground 5. captain_assistants_inboxes_index → /captain/:assistantId/inboxes 6. captain_tools_index → /captain/tools 7. captain_assistants_settings_index → /captain/:assistantId/settings 8. captain_assistants_guardrails_index → /captain/:assistantId/settings/guardrails 9. captain_assistants_guidelines_index → /captain/:assistantId/settings/guidelines 10. captain_assistants_index → /captain/:navigationPath ``` **How it works:** 1. User clicks sidebar item → Routes to `captain_assistants_index` with `navigationPath` 2. `AssistantsIndexPage` validates route and gets last active assistant, if not redirects to assistant create page. 3. Routes to actual page: `/captain/:assistantId/:page` 4. Page loads with correct assistant context Fixes https://linear.app/chatwoot/issue/CW-5832/updating-captain-navigation ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
122 lines
2.9 KiB
Vue
122 lines
2.9 KiB
Vue
<script setup>
|
|
import { ref, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import NextButton from 'dashboard/components-next/button/Button.vue';
|
|
import MessageList from './MessageList.vue';
|
|
import CaptainAssistant from 'dashboard/api/captain/assistant';
|
|
|
|
const { assistantId } = defineProps({
|
|
assistantId: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
});
|
|
|
|
const { t } = useI18n();
|
|
const messages = ref([]);
|
|
const newMessage = ref('');
|
|
const isLoading = ref(false);
|
|
|
|
const formatMessagesForApi = () => {
|
|
return messages.value.map(message => ({
|
|
role: message.sender,
|
|
content: message.content,
|
|
}));
|
|
};
|
|
|
|
const resetConversation = () => {
|
|
messages.value = [];
|
|
newMessage.value = '';
|
|
};
|
|
|
|
// Watch for assistant ID changes and reset conversation
|
|
watch(
|
|
() => assistantId,
|
|
(newId, oldId) => {
|
|
if (oldId && newId !== oldId) {
|
|
resetConversation();
|
|
}
|
|
}
|
|
);
|
|
|
|
const sendMessage = async () => {
|
|
if (!newMessage.value.trim() || isLoading.value) return;
|
|
|
|
const userMessage = {
|
|
content: newMessage.value,
|
|
sender: 'user',
|
|
timestamp: new Date().toISOString(),
|
|
};
|
|
messages.value.push(userMessage);
|
|
const currentMessage = newMessage.value;
|
|
newMessage.value = '';
|
|
|
|
try {
|
|
isLoading.value = true;
|
|
const { data } = await CaptainAssistant.playground({
|
|
assistantId,
|
|
messageContent: currentMessage,
|
|
messageHistory: formatMessagesForApi(),
|
|
});
|
|
|
|
messages.value.push({
|
|
content: data.response,
|
|
sender: 'assistant',
|
|
timestamp: new Date().toISOString(),
|
|
});
|
|
} catch (error) {
|
|
// eslint-disable-next-line no-console
|
|
console.error('Error getting assistant response:', error);
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="flex flex-col h-full rounded-lg p-4 border border-n-slate-4 text-n-slate-11"
|
|
>
|
|
<div class="mb-4">
|
|
<div class="flex justify-between items-center mb-1">
|
|
<h3 class="text-lg font-medium">
|
|
{{ t('CAPTAIN.PLAYGROUND.HEADER') }}
|
|
</h3>
|
|
<NextButton
|
|
ghost
|
|
sm
|
|
icon="i-lucide-rotate-ccw"
|
|
@click="resetConversation"
|
|
/>
|
|
</div>
|
|
<p class="text-sm text-n-slate-11">
|
|
{{ t('CAPTAIN.PLAYGROUND.DESCRIPTION') }}
|
|
</p>
|
|
</div>
|
|
|
|
<MessageList :messages="messages" :is-loading="isLoading" />
|
|
|
|
<div
|
|
class="flex items-center bg-n-solid-1 outline outline-n-container rounded-lg p-3"
|
|
>
|
|
<input
|
|
v-model="newMessage"
|
|
class="flex-1 bg-transparent border-none focus:outline-none text-sm mb-0"
|
|
:placeholder="t('CAPTAIN.PLAYGROUND.MESSAGE_PLACEHOLDER')"
|
|
@keyup.enter="sendMessage"
|
|
/>
|
|
<NextButton
|
|
ghost
|
|
sm
|
|
:disabled="!newMessage.trim()"
|
|
icon="i-lucide-send"
|
|
@click="sendMessage"
|
|
/>
|
|
</div>
|
|
|
|
<p class="text-xs text-n-slate-11 pt-2 text-center">
|
|
{{ t('CAPTAIN.PLAYGROUND.CREDIT_NOTE') }}
|
|
</p>
|
|
</div>
|
|
</template>
|