diff --git a/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte b/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte index 8a9edb8843..b898fe59b7 100644 --- a/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte +++ b/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte @@ -17,6 +17,7 @@ export let id = ''; export let model = null; export let messages = []; + export let actions = []; export let onAdd = (e) => {}; let floatingInput = false; @@ -30,20 +31,11 @@ let responseDone = false; let controller = null; - const autoScroll = async () => { - const responseContainer = document.getElementById('response-container'); - if (responseContainer) { - // Scroll to bottom only if the scroll is at the bottom give 50px buffer - if ( - responseContainer.scrollHeight - responseContainer.clientHeight <= - responseContainer.scrollTop + 50 - ) { - responseContainer.scrollTop = responseContainer.scrollHeight; - } - } - }; + $: if (actions.length === 0) { + actions = DEFAULT_ACTIONS; + } - const ACTIONS = [ + const DEFAULT_ACTIONS = [ { id: 'ask', label: $i18n.t('Ask'), @@ -59,6 +51,19 @@ } ]; + const autoScroll = async () => { + const responseContainer = document.getElementById('response-container'); + if (responseContainer) { + // Scroll to bottom only if the scroll is at the bottom give 50px buffer + if ( + responseContainer.scrollHeight - responseContainer.clientHeight <= + responseContainer.scrollTop + 50 + ) { + responseContainer.scrollTop = responseContainer.scrollHeight; + } + } + }; + const actionHandler = async (actionId) => { if (!model) { toast.error('Model not selected'); @@ -70,14 +75,14 @@ .map((line) => `> ${line}`) .join('\n'); - let selectedAction = ACTIONS.find((action) => action.id === actionId); + let selectedAction = actions.find((action) => action.id === actionId); if (!selectedAction) { toast.error('Action not found'); return; } let prompt = selectedAction?.prompt ?? ''; - if (selectedAction.input) { + if (prompt.includes('{{INPUT_CONTENT}}') && !floatingInput) { prompt = prompt.replace('{{INPUT_CONTENT}}', floatingInputValue); floatingInputValue = ''; } @@ -212,14 +217,14 @@
- {#each ACTIONS as action} + {#each actions as action} {/each} diff --git a/src/lib/components/chat/Messages/ContentRenderer.svelte b/src/lib/components/chat/Messages/ContentRenderer.svelte index 630e4bd7a0..6c5d0abb60 100644 --- a/src/lib/components/chat/Messages/ContentRenderer.svelte +++ b/src/lib/components/chat/Messages/ContentRenderer.svelte @@ -194,6 +194,7 @@ 0