Skip to content

Commit c5c3b44

Browse files
committed
fix: update timestamp of session on new message sent. Close history tab, when we're creating new session
1 parent 611a655 commit c5c3b44

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

custom/SessionsHistory.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"
77
>
88
<h3 :class="h3Style">{{ $t('Chat history') }}</h3>
9-
<Button @click="agentStore.createPreSession()" :disabled="agentStore.isResponseInProgress" class="w-[360px] mx-4 my-2 mb-4 rounded-3xl text-gray-800 dark:text-gray-200">
9+
<Button @click="agentStore.createPreSession(); agentStore.setSessionHistoryOpen(false)" :disabled="agentStore.isResponseInProgress" class="w-[360px] mx-4 my-2 mb-4 rounded-3xl text-gray-800 dark:text-gray-200">
1010
<IconPlusOutline class="w-5 h-5" />
1111
{{ $t('New chat') }}
1212
</Button>
1313
<div class="w-full border-b border-gray-200 dark:border-gray-700"/>
1414
<div class="absolute w-full h-full flex flex-col items-center justify-center bg-gray-100/50 dark:bg-gray-700/50 z-10" v-if="agentStore.isResponseInProgress">
1515
<Spinner class="w-8 h-8" v-if="agentStore.isResponseInProgress" />
16-
<p class="mt-2 text-gray-800 dark:text-gray-200">generation in progress...</p>
16+
<p class="mt-2 text-gray-800 dark:text-gray-200">{{ $t('Generation in progress...') }}</p>
1717
</div>
1818
<div v-for="group in groupedSessions" :key="group.dayKey" class="w-full py-2">
1919
<div class="px-4 pb-2 text-xs font-semibold uppercase tracking-[0.2em] text-gray-500 dark:text-gray-400">
@@ -38,7 +38,7 @@
3838
v-if="!groupedSessions || groupedSessions.length === 0"
3939
class="w-full h-full flex items-center justify-center text-gray-800 dark:text-gray-200"
4040
>
41-
There is no previous chat sessions
41+
{{ $t('There are no previous chat sessions') }}
4242
</p>
4343
</div>
4444
</template>

custom/useAgentStore.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ export const useAgentStore = defineStore('agent', () => {
120120
});
121121
const blockCloseOfChat = ref(false);
122122

123+
function sortSessionsListByTimestamp(sessionsList: ISessionsListItem[]) {
124+
return [...sessionsList].sort((a: ISessionsListItem, b: ISessionsListItem) => b.timestamp.localeCompare(a.timestamp));
125+
}
126+
123127
async function sendMessage() {
124128
const message = trimmedUserMessage.value;
125129
if (!message || isResponseInProgress.value) {
@@ -128,6 +132,11 @@ export const useAgentStore = defineStore('agent', () => {
128132
if (!currentSession.value || currentSession.value.sessionId === 'pre-session') {
129133
await createNewSession(message);
130134
}
135+
currentSession.value.timestamp = new Date().toISOString();
136+
sessionList.value = sortSessionsListByTimestamp(sessionList.value.map((s: ISessionsListItem) => s.sessionId === currentSession.value?.sessionId ? {
137+
...s,
138+
timestamp: currentSession.value?.timestamp || s.timestamp,
139+
} : s));
131140
lastMessage.value = message;
132141
currentChat.value?.sendMessage({
133142
text: message,

index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
8787
return {ok: true};
8888
}
8989

90+
private async updateSessionDate(sessionId: string) {
91+
await this.adminforth.resource(this.options.sessionResource.resourceId).update(sessionId, {
92+
[this.options.sessionResource.createdAtField]: new Date().toISOString(),
93+
});
94+
return {ok: true};
95+
}
96+
9097
private async getSessionTurns(sessionId: string) {
9198
const turns = await this.adminforth.resource(this.options.turnResource.resourceId).list(
9299
[Filters.EQ(this.options.turnResource.sessionIdField, sessionId)],
@@ -150,6 +157,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
150157
const userTimeZone = (body.timeZone as string | undefined) ?? 'UTC';
151158
const sessionId = body.sessionId || adminUser?.pk || adminUser?.username || 'default';
152159
const turnId = await this.createNewTurn(sessionId, prompt);
160+
await this.updateSessionDate(sessionId);
153161
let fullResponse = "";
154162
let isStreamClosed = false;
155163
const sequenceDebugCollector = createSequenceDebugCollector();

0 commit comments

Comments
 (0)