From fd769018ce49fd6a95fef01489b8926e03828feb Mon Sep 17 00:00:00 2001 From: Per Stark Date: Wed, 29 Jan 2025 15:50:43 +0100 Subject: [PATCH] feat: additional variables to database structs & display --- assets/style.css | 53 +++++++++++++++++++ src/ingress/types/ingress_input.rs | 16 +++--- src/ingress/types/ingress_object.rs | 4 +- src/storage/types/file_info.rs | 2 + src/storage/types/text_content.rs | 4 ++ templates/icons/chat_icon.html | 5 ++ templates/icons/document_icon.html | 5 ++ templates/icons/globe_icon.html | 5 ++ templates/index/signed_in/active_jobs.html | 29 ++++++---- templates/index/signed_in/base.html | 2 +- templates/index/signed_in/quick_actions.html | 2 +- templates/index/signed_in/recent_content.html | 34 +++++++----- 12 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 templates/icons/chat_icon.html create mode 100644 templates/icons/document_icon.html create mode 100644 templates/icons/globe_icon.html diff --git a/assets/style.css b/assets/style.css index ca64e68..5c461a2 100644 --- a/assets/style.css +++ b/assets/style.css @@ -2643,6 +2643,9 @@ .my-4 { margin-block: calc(var(--spacing) * 4); } + .my-10 { + margin-block: calc(var(--spacing) * 10); + } .my-12 { margin-block: calc(var(--spacing) * 12); } @@ -3482,6 +3485,9 @@ width: 1.2em; height: 1.2em; } + .h-1 { + height: calc(var(--spacing) * 1); + } .h-5 { height: calc(var(--spacing) * 5); } @@ -3500,12 +3506,24 @@ .w-32 { width: calc(var(--spacing) * 32); } + .w-200 { + width: calc(var(--spacing) * 200); + } .w-full { width: 100%; } .max-w-\(--breakpoint-sm\) { max-width: var(--breakpoint-sm); } + .max-w-\[150px\] { + max-width: 150px; + } + .max-w-\[160px\] { + max-width: 160px; + } + .max-w-\[200px\] { + max-width: 200px; + } .flex-1 { flex: 1; } @@ -3654,6 +3672,14 @@ margin-block-end: calc(calc(var(--spacing) * 8) * calc(1 - var(--tw-space-y-reverse))); } } + .truncate { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + .overflow-clip { + overflow: clip; + } .overflow-hidden { overflow: hidden; } @@ -3827,6 +3853,9 @@ --tw-tracking: var(--tracking-wide); letter-spacing: var(--tracking-wide); } + .\!text-nowrap { + text-wrap: nowrap !important; + } .text-nowrap { text-wrap: nowrap; } @@ -3836,9 +3865,15 @@ .break-all { word-break: break-all; } + .overflow-ellipsis { + text-overflow: ellipsis; + } .text-ellipsis { text-overflow: ellipsis; } + .whitespace-nowrap { + white-space: nowrap; + } .link-primary { color: var(--color-primary); &:hover { @@ -3881,6 +3916,9 @@ .text-transparent { color: transparent; } + .capitalize { + text-transform: capitalize; + } .lowercase { text-transform: lowercase; } @@ -3911,6 +3949,9 @@ .underline { text-decoration-line: underline; } + .accent-accent { + accent-color: var(--color-accent); + } .accent-accent-content { accent-color: var(--color-accent-content); } @@ -4135,6 +4176,18 @@ content: var(--tw-content); } } + .\[\&\:before\]\:content-\[\'Url\:_\'\] { + &:before { + --tw-content: 'Url: '; + content: var(--tw-content); + } + } + .\[\&\:before\]\:content-\[\'source\:_\'\] { + &:before { + --tw-content: 'source: '; + content: var(--tw-content); + } + } } @layer base { *, ::after, ::before, ::backdrop, ::file-selector-button { diff --git a/src/ingress/types/ingress_input.rs b/src/ingress/types/ingress_input.rs index a3556e4..a122f92 100644 --- a/src/ingress/types/ingress_input.rs +++ b/src/ingress/types/ingress_input.rs @@ -41,13 +41,15 @@ pub fn create_ingress_objects( }); } Err(_) => { - info!("Treating input as plain text"); - object_list.push(IngressObject::Text { - text: input_content.to_string(), - instructions: input.instructions.clone(), - category: input.category.clone(), - user_id: user_id.into(), - }); + if input_content.len() > 2 { + info!("Treating input as plain text"); + object_list.push(IngressObject::Text { + text: input_content.to_string(), + instructions: input.instructions.clone(), + category: input.category.clone(), + user_id: user_id.into(), + }); + } } } } diff --git a/src/ingress/types/ingress_object.rs b/src/ingress/types/ingress_object.rs index ce09aff..96cd140 100644 --- a/src/ingress/types/ingress_object.rs +++ b/src/ingress/types/ingress_object.rs @@ -14,7 +14,6 @@ use serde::{Deserialize, Serialize}; use std::fmt::Write; use tiktoken_rs::{o200k_base, CoreBPE}; -/// Knowledge object type, containing the content or reference to it, as well as metadata #[derive(Debug, Serialize, Deserialize, Clone)] pub enum IngressObject { Url { @@ -62,6 +61,7 @@ impl IngressObject { instructions.into(), category.into(), None, + Some(url.into()), user_id.into(), )) } @@ -75,6 +75,7 @@ impl IngressObject { instructions.into(), category.into(), None, + None, user_id.into(), )), IngressObject::File { @@ -89,6 +90,7 @@ impl IngressObject { instructions.into(), category.into(), Some(file_info.to_owned()), + None, user_id.into(), )) } diff --git a/src/storage/types/file_info.rs b/src/storage/types/file_info.rs index e6e575c..539ce10 100644 --- a/src/storage/types/file_info.rs +++ b/src/storage/types/file_info.rs @@ -39,6 +39,7 @@ pub enum FileError { stored_object!(FileInfo, "file", { sha256: String, path: String, + file_name: String, mime_type: String }); @@ -77,6 +78,7 @@ impl FileInfo { id: uuid.to_string(), created_at: now, updated_at: now, + file_name, sha256, path: Self::persist_file(&uuid, file, &sanitized_file_name, user_id) .await? diff --git a/src/storage/types/text_content.rs b/src/storage/types/text_content.rs index 201b2f7..8f50e70 100644 --- a/src/storage/types/text_content.rs +++ b/src/storage/types/text_content.rs @@ -7,6 +7,8 @@ use super::file_info::FileInfo; stored_object!(TextContent, "text_content", { text: String, file_info: Option, + + url: Option, instructions: String, category: String, user_id: String @@ -18,6 +20,7 @@ impl TextContent { instructions: String, category: String, file_info: Option, + url: Option, user_id: String, ) -> Self { let now = Utc::now(); @@ -27,6 +30,7 @@ impl TextContent { updated_at: now, text, file_info, + url, instructions, category, user_id, diff --git a/templates/icons/chat_icon.html b/templates/icons/chat_icon.html new file mode 100644 index 0000000..bb10543 --- /dev/null +++ b/templates/icons/chat_icon.html @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/templates/icons/document_icon.html b/templates/icons/document_icon.html new file mode 100644 index 0000000..2e128b3 --- /dev/null +++ b/templates/icons/document_icon.html @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/templates/icons/globe_icon.html b/templates/icons/globe_icon.html new file mode 100644 index 0000000..30ec0ee --- /dev/null +++ b/templates/icons/globe_icon.html @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/templates/index/signed_in/active_jobs.html b/templates/index/signed_in/active_jobs.html index ee7cc03..3b0d49a 100644 --- a/templates/index/signed_in/active_jobs.html +++ b/templates/index/signed_in/active_jobs.html @@ -1,26 +1,33 @@ {% block active_jobs_section %} {% if active_jobs %} -
    +
    • Active Jobs
    • {% for item in active_jobs %}
    • - - - + {% if item.content.Url %} + {% include "icons/globe_icon.html" %} + {% elif item.content.File %} + {% include "icons/document_icon.html" %} + {% else %} + {% include "icons/chat_icon.html" %} + {% endif %}
      -
      - {{item.created_at|datetimeformat(format="short", tz=user.timezone)}}
      -
      +
      {{item.status}}
      +
      + {{item.created_at|datetimeformat(format="short", tz=user.timezone)}}

      - {{item.content}} + {% if item.content.Url %} + {{item.content.Url.url}} + {% elif item.content.File %} + {{item.content.File.file_info.file_name}} + {% else %} + {{item.content.Text.text}} + {% endif %}

      diff --git a/templates/index/signed_in/base.html b/templates/index/signed_in/base.html index 145323f..82f183f 100644 --- a/templates/index/signed_in/base.html +++ b/templates/index/signed_in/base.html @@ -4,7 +4,7 @@ {% include "index/signed_in/quick_actions.html" %} -
      +
      {% include "index/signed_in/active_jobs.html" %} {% include "index/signed_in/recent_content.html" %} diff --git a/templates/index/signed_in/quick_actions.html b/templates/index/signed_in/quick_actions.html index 1e6b270..c092624 100644 --- a/templates/index/signed_in/quick_actions.html +++ b/templates/index/signed_in/quick_actions.html @@ -1,4 +1,4 @@ -
      +
      diff --git a/templates/index/signed_in/recent_content.html b/templates/index/signed_in/recent_content.html index 503f225..426b323 100644 --- a/templates/index/signed_in/recent_content.html +++ b/templates/index/signed_in/recent_content.html @@ -1,26 +1,32 @@ {% block latest_content_section %} -
        +
        • Recently added content
        • {% for item in latest_text_contents %}
        • - - - - + {% if item.url %} + {% include "icons/globe_icon.html" %} + {% elif item.file_info %} + {% include "icons/document_icon.html" %} + {% else %} + {% include "icons/chat_icon.html" %} + {% endif %}
          -
          - {{item.created_at|datetimeformat(format="short", tz=user.timezone)}}
          -
          - {{item.instructions}} +
          + {% if item.url %} + {{item.url}} + {% elif item.file_info%} + {{item.file_info.file_name}} + {% else %} + {{item.text}} + {% endif %}
          +
          + {{item.created_at|datetimeformat(format="short", tz=user.timezone)}}
          -

          - {{item.text}} +

          + {{item.instructions}}