feat: caching chat history & dto

This commit is contained in:
Per Stark
2026-02-14 19:43:34 +01:00
parent f93c06b347
commit 679308aa1d
10 changed files with 350 additions and 32 deletions

View File

@@ -12,16 +12,34 @@
</label>
</form>
<script>
document.getElementById('chat-input').addEventListener('keydown', function (e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
htmx.trigger('#chat-form', 'submit');
}
});
// Clear textarea after successful submission
document.getElementById('chat-form').addEventListener('htmx:afterRequest', function (e) {
if (e.detail.successful) { // Check if the request was successful
document.getElementById('chat-input').value = ''; // Clear the textarea
}
});
</script>
(function () {
const newChatStreamId = 'ai-stream-{{ user_message.id }}';
document.getElementById('chat-input').addEventListener('keydown', function (e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
htmx.trigger('#chat-form', 'submit');
}
});
// Clear textarea after successful submission
document.getElementById('chat-form').addEventListener('htmx:afterRequest', function (e) {
if (e.detail.successful) { // Check if the request was successful
document.getElementById('chat-input').value = ''; // Clear the textarea
}
});
const refreshSidebarAfterFirstResponse = function (e) {
const streamEl = document.getElementById(newChatStreamId);
if (!streamEl || e.target !== streamEl) return;
htmx.ajax('GET', '/chat/sidebar', {
target: '.drawer-side',
swap: 'outerHTML'
});
document.body.removeEventListener('htmx:sseClose', refreshSidebarAfterFirstResponse);
};
document.body.addEventListener('htmx:sseClose', refreshSidebarAfterFirstResponse);
})();
</script>