cache the summary
This commit is contained in:
@@ -350,7 +350,7 @@ const deleteConversation = () => {
|
||||
:class="showMetaSection ? 'top-8' : 'top-4'"
|
||||
>
|
||||
<div class="flex items-center gap-1 ml-auto">
|
||||
<ConversationSummary ref="summaryRef" :conversation-id="chat.id" />
|
||||
<ConversationSummary ref="summaryRef" :chat="chat" />
|
||||
<span class="font-normal leading-4 text-xxs">
|
||||
<TimeAgo
|
||||
:last-activity-timestamp="chat.timestamp"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useStore } from 'dashboard/composables/store';
|
||||
import { useAccount } from 'dashboard/composables/useAccount';
|
||||
import { useMessageFormatter } from 'shared/composables/useMessageFormatter';
|
||||
import { FEATURE_FLAGS } from 'dashboard/featureFlags';
|
||||
@@ -8,38 +9,56 @@ import TasksAPI from 'dashboard/api/captain/tasks';
|
||||
import Button from 'dashboard/components-next/button/Button.vue';
|
||||
|
||||
const props = defineProps({
|
||||
conversationId: {
|
||||
type: [Number, String],
|
||||
chat: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const { t } = useI18n();
|
||||
const store = useStore();
|
||||
const { isCloudFeatureEnabled } = useAccount();
|
||||
const { formatMessage } = useMessageFormatter();
|
||||
|
||||
const isExpanded = ref(false);
|
||||
const isLoading = ref(false);
|
||||
const summary = ref('');
|
||||
const error = ref('');
|
||||
|
||||
const captainTasksEnabled = computed(() => {
|
||||
return isCloudFeatureEnabled(FEATURE_FLAGS.CAPTAIN_TASKS);
|
||||
});
|
||||
|
||||
const cachedSummary = computed(() => props.chat?.cached_summary || '');
|
||||
const cachedSummaryAt = computed(() => props.chat?.cached_summary_at || 0);
|
||||
const lastActivityAt = computed(() => props.chat?.last_activity_at || 0);
|
||||
|
||||
const isStale = computed(() => {
|
||||
if (!cachedSummaryAt.value) return true;
|
||||
return lastActivityAt.value > cachedSummaryAt.value;
|
||||
});
|
||||
|
||||
const formattedSummary = computed(() => {
|
||||
return summary.value ? formatMessage(summary.value) : '';
|
||||
return cachedSummary.value ? formatMessage(cachedSummary.value) : '';
|
||||
});
|
||||
|
||||
const fetchSummary = async () => {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const result = await TasksAPI.summarize(props.conversationId);
|
||||
const result = await TasksAPI.summarize(props.chat.id, {
|
||||
forceRegenerate: false,
|
||||
});
|
||||
const {
|
||||
data: { message: generatedMessage },
|
||||
data: { message: generatedSummary },
|
||||
} = result;
|
||||
summary.value = generatedMessage || '';
|
||||
|
||||
if (generatedSummary) {
|
||||
store.dispatch('updateConversationCachedSummary', {
|
||||
conversationId: props.chat.id,
|
||||
cachedSummary: generatedSummary,
|
||||
cachedSummaryAt: Math.floor(Date.now() / 1000),
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.name !== 'AbortError' && e.name !== 'CanceledError') {
|
||||
error.value = e.response?.data?.error || t('CHAT_LIST.SUMMARY.ERROR');
|
||||
@@ -55,7 +74,8 @@ const toggleSummary = async () => {
|
||||
return;
|
||||
}
|
||||
isExpanded.value = true;
|
||||
if (!summary.value && !error.value) {
|
||||
// Only fetch if no cached summary
|
||||
if (!cachedSummary.value && !error.value) {
|
||||
await fetchSummary();
|
||||
}
|
||||
};
|
||||
@@ -68,10 +88,10 @@ const onButtonClick = e => {
|
||||
defineExpose({
|
||||
isExpanded,
|
||||
isLoading,
|
||||
summary,
|
||||
error,
|
||||
formattedSummary,
|
||||
captainTasksEnabled,
|
||||
isStale,
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user