Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(llm): improve layout with send button & context window
Elian Doran3c697927446f
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 84bc0dbed5..c58fb7ccb6 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1631,7 +1631,8 @@"tokens_used_with_cost": "{{prompt}} prompt + {{completion}} completion = {{total}} tokens (~${{cost}})","tokens_used_with_model": "{{model}}: {{prompt}} prompt + {{completion}} completion = {{total}} tokens","tokens_used_with_model_and_cost": "{{model}}: {{prompt}} prompt + {{completion}} completion = {{total}} tokens (~${{cost}})",- "tokens": "tokens"+ "tokens": "tokens",+ "context_used": "{{percentage}}% used"},"sidebar_chat": {"title": "AI Chat",diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsxindex 3bf9fd3b9d..6e8ac503b2 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx@@ -1,6 +1,7 @@import type { RefObject } from "preact";import { t } from "../../../services/i18n.js";+import ActionButton from "../../react/ActionButton.js";import Dropdown from "../../react/Dropdown.js";import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleableItem } from "../../react/FormList.js";import type { UseLlmChatReturn } from "./useLlmChat.js";@@ -70,25 +71,16 @@ export default function ChatInputBar({return (<form className="llm-chat-input-form" onSubmit={handleSubmit}>- <div className="llm-chat-input-row">- <textarea- ref={chat.textareaRef as RefObject<HTMLTextAreaElement>}- className="llm-chat-input"- value={chat.input}- onInput={(e) => chat.setInput((e.target as HTMLTextAreaElement).value)}- placeholder={t("llm_chat.placeholder")}- disabled={chat.isStreaming}- onKeyDown={handleKeyDown}- rows={3}- />- <button- type="submit"- className="llm-chat-send-btn"- disabled={chat.isStreaming || !chat.input.trim()}- >- {chat.isStreaming ? t("llm_chat.sending") : t("llm_chat.send")}- </button>- </div>+ <textarea+ ref={chat.textareaRef as RefObject<HTMLTextAreaElement>}+ className="llm-chat-input"+ value={chat.input}+ onInput={(e) => chat.setInput((e.target as HTMLTextAreaElement).value)}+ placeholder={t("llm_chat.placeholder")}+ disabled={chat.isStreaming}+ onKeyDown={handleKeyDown}+ rows={3}+ /><div className="llm-chat-options"><div className="llm-chat-model-selector"><span className="bx bx-chip" />@@ -148,16 +140,28 @@ export default function ChatInputBar({disabled={chat.isStreaming}/></Dropdown>+ {chat.lastPromptTokens > 0 && (+ <div+ className="llm-chat-context-indicator"+ title={`${formatTokenCount(chat.lastPromptTokens)} / ${formatTokenCount(contextWindow)} ${t("llm_chat.tokens")}`}+ >+ <div+ className="llm-chat-context-pie"+ style={{+ background: `conic-gradient(${pieColor} ${percentage}%, var(--accented-background-color) ${percentage}%)`+ }}+ />+ <span className="llm-chat-context-text">{t("llm_chat.context_used", { percentage: percentage.toFixed(0) })}</span>+ </div>+ )}</div>- {chat.lastPromptTokens > 0 && (- <div- className="llm-chat-context-pie"- title={`${formatTokenCount(chat.lastPromptTokens)} / ${formatTokenCount(contextWindow)} ${t("llm_chat.tokens")} (${percentage.toFixed(0)}%)`}- style={{- background: `conic-gradient(${pieColor} ${percentage}%, var(--accented-background-color) ${percentage}%)`- }}- />- )}+ <ActionButton+ icon={chat.isStreaming ? "bx bx-loader-alt bx-spin" : "bx bx-send"}+ text={chat.isStreaming ? t("llm_chat.sending") : t("llm_chat.send")}+ onClick={handleSubmit}+ disabled={chat.isStreaming || !chat.input.trim()}+ className="llm-chat-send-btn"+ /></div></form>);diff --git a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.cssindex 901c9e6adc..3060689c43 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css@@ -218,12 +218,6 @@border-top: 1px solid var(--main-border-color);}-.llm-chat-input-row {- display: flex;- gap: 0.5rem;- align-items: flex-end;-}-.llm-chat-input {flex: 1;min-height: 60px;@@ -249,60 +243,20 @@cursor: not-allowed;}-.llm-chat-send-btn {- padding: 0.75rem 1.5rem;- background: var(--button-background-color);- border: 1px solid var(--button-border-color);- border-radius: 8px;- cursor: pointer;- font-family: inherit;- font-size: inherit;- color: var(--button-text-color);- transition: background-color 0.15s ease;-}--.llm-chat-send-btn:hover:not(:disabled) {- background: var(--button-hover-background-color, var(--button-background-color));-}--.llm-chat-send-btn:disabled {- opacity: 0.5;- cursor: not-allowed;-}-/* Options row */.llm-chat-options {- display: flex;- gap: 1rem;- padding-left: 0.25rem;-}--.llm-chat-toggle {display: flex;align-items: center;- gap: 0.375rem;- font-size: 0.85rem;- color: var(--muted-text-color);- cursor: pointer;- user-select: none;-}--.llm-chat-toggle input[type="checkbox"] {- margin: 0;- cursor: pointer;-}--.llm-chat-toggle .bx {- font-size: 1rem;+ gap: 0.75rem;}-.llm-chat-toggle:has(input:checked) {- color: var(--main-text-color);+.llm-chat-send-btn {+ margin-left: auto;+ font-size: 1.25rem;}-.llm-chat-toggle:has(input:disabled) {- opacity: 0.5;- cursor: not-allowed;+.llm-chat-send-btn.disabled {+ opacity: 0.4;}/* Model selector */@@ -577,12 +531,23 @@font-family: var(--monospace-font-family, monospace);}-/* Context window pie indicator */+/* Context window indicator */+.llm-chat-context-indicator {+ display: flex;+ align-items: center;+ gap: 0.375rem;+ margin-left: 0.5rem;+ cursor: help;+}+.llm-chat-context-pie {- width: 16px;- height: 16px;+ width: 14px;+ height: 14px;border-radius: 50%;- margin-left: auto;- cursor: help;flex-shrink: 0;}++.llm-chat-context-text {+ font-size: 0.75rem;+ color: var(--muted-text-color);+}