Commit graph

2118 commits

Author SHA1 Message Date
sabaimran
acfdc8da77 Explicitly set the connection age to 0 in the django settings. Seems to be some strange behavior with async gunicorn + django db 2024-06-04 20:31:51 +05:30
Debanjum Singh Solanky
85a343363b Release Khoj version 1.13.0 2024-06-04 11:57:44 +05:30
Debanjum Singh Solanky
b757ba664f Sanitize chat messages to render in Obsidian, Desktop, Web apps
Use DOMPurify to escape any unsafe HTML in chat message before adding
it to DOM via innerHTML updates to a HTML element
2024-06-04 10:53:30 +05:30
Debanjum Singh Solanky
9f80c2ab76 Enforce Content-Security-Policy (CSP) in Obsidian, Desktop, Web apps
Prevent XSS attacks by enforcing Content-Security-Policy (CSP) in apps.
Do not allow loading images, other assets from untrusted domains.

- Only allow loading assets from trusted domains
  like 'self', khoj.dev, ipapi for geolocation, google (fonts, img)
  - images from khoj domain, google (for profile pic)
  - assets from khoj domain
  - Do not allow iframe src
  - Allow unsafe-inline script and styles for now as markdown-it escapes html
    in user, khoj chat

- Add hostURL to CSP of the Desktop, Obsidian apps
  Given web client is served by khoj server, it doesn't need to
  explicitly allow for khoj.dev domain. So if user self-hosting, it'll
  automatically allow the domain in the CSP (via 'self')

  Whereas the Obsidian, Desktop clients allow configure the server URL.
  Note *switching server URL breaks CSP until app is reloaded*
2024-06-04 10:53:30 +05:30
Debanjum Singh Solanky
bbcdb8413d Add null checks, fix build errors in Khoj plugin on newer Obsidian 2024-06-03 18:03:11 +05:30
Debanjum Singh Solanky
d8ace4d34c Highlight the agents, automation tab when active on the web app 2024-06-03 16:57:03 +05:30
sabaimran
4679f07336 Clean up some of the design of agents, inspired by dicussion #792 2024-06-03 12:52:07 +05:30
Debanjum Singh Solanky
8cdab5f31a Update slash command UX in chat UI of desktop app to match web app
Make commands in popup menu on typing slash in chat input selectable
2024-06-02 17:27:37 +05:30
Debanjum Singh Solanky
7828bd6f2e Hide command popup & focus on chatInput on selecting command in web app
Style command popup cursor and add highlight to indicate using slash
command
2024-06-02 17:27:37 +05:30
Debanjum
cf8c9c2a3d
Serve image assets from Khoj domain, not directly from S3 bucket (#734)
- Serve generated images from Khoj domain instead of directly from AWS S3
- Rename assets URL from Khoj S3 bucket to assets.khoj.dev
2024-06-02 17:24:35 +05:30
sabaimran
5bb3689562 Do not stream responses in the scheduled_chat response 2024-06-02 11:31:15 +05:30
sabaimran
5132b01ab1 Remove intent_type from telemetry update in api_chat 2024-06-02 10:21:38 +05:30
Raghav Tirumale
a3934b3aaa
Improved Command Menu and Help Command (#774)
* The command menu (triggered by "/") now has a clickable list of possible commands, that automatically fill into the chat when pressed.
* The `/help` command now searches `khoj.dev` pages to provide useful assistance to the user.

---------

Co-authored-by: raghavt3 <raghavt3@illinois.edu>
Co-authored-by: sabaimran <65192171+sabaimran@users.noreply.github.com>
2024-06-01 22:33:31 +05:30
sabaimran
89178bcebd Fix formatting issues for task email in mobile 2024-06-01 14:19:12 +05:30
Debanjum
b499b3fe2a
Upgrade Khoj Obsidian: Chat from Side Pane, Stream Intermediate Steps, Copy Message to Clipboard (#736)
### Details
- **Chat with Khoj from right pane on Obsidian**
  - Modal was too ephemeral, couldn't have it open for reference, quick jump to Khoj chat
- **Stream intermediate steps taken by Khoj** for generating response to the chat pane
  Gives more transparency into Khoj 'thinking' process, e.g internet, notes searches performed, documents read etc. 
  The feedback allows us to tune our messages to elicit better responses by Khoj
- Add ability to **copy message to clipboard, paste chat messages directly into current file**
- Jump to **Search**, **Find Similar** functions from navigation bar on the Khoj Obsidian side pane
- Improve spacing, use consistent colors in chat message references and buttons

Resolves #789, #754
2024-06-01 13:29:21 +05:30
sabaimran
8b9c26c468 Remove unused method 2024-06-01 12:54:43 +05:30
sabaimran
5ec641837a
Allow automations to be shareable (#790)
* Updating the API / UI to support sharing of automations
* Allow people to see the automations even when not logged in, and add an overlay effect
* Handle unauthenticated users taking actions
* Support showing pre-filled automation details on the config automations page
* Redirect user to login if they try to add an automation while unauthenticated
2024-06-01 12:44:49 +05:30
Debanjum Singh Solanky
7d7d4cf5c3 Make new chat message text selectable in Obsidian side pane
Resolves #789
2024-06-01 11:01:39 +05:30
Debanjum Singh Solanky
7fb7f200b3 Fix rendering text in chat messages with bulleted lists
Improves #789
2024-06-01 10:51:22 +05:30
Debanjum Singh Solanky
7a93599fe8 Merge branch 'master' into upgrade-khoj-on-obsidian
- Conflicts:
  - src/khoj/interface/web/chat.html
    Use our changes with feedback button changes from master
2024-06-01 10:07:43 +05:30
Debanjum Singh Solanky
92bab9fa61 Get Conversation session action buttons out from under the three dot menu 2024-05-31 20:11:00 +05:30
Debanjum Singh Solanky
7fa42daf89 Render action buttons for new Khoj chat responses in Obsidian
- Dedupe the code to add action buttons to chat messages
- Update the renderIncrementalMessage function to also add the action
  buttons to newly generated chat messages by Khoj
2024-05-31 20:11:00 +05:30
Debanjum Singh Solanky
2d010db83f Toggle chat session view on clicking the Obsidian chat sessions button 2024-05-31 20:11:00 +05:30
Debanjum Singh Solanky
275d4877a6 Fix loading spinner visibility by using contrasting background color
Fix code formating of Khoj chat view in Obsidian
2024-05-31 20:09:24 +05:30
sabaimran
2667ef4544 Refresh the conversation from the db in the websocket flow 2024-05-31 16:15:56 +05:30
sabaimran
fd07abbfc8 Decrease the life of one connection 2024-05-31 15:39:15 +05:30
Debanjum
3090b84252
Disable Minutely Recurrence for Automations (#781)
* Disable automation recurrence at minute level frequency

* Set a max lifetime for django's connections to the db

* Disable any automation that has a non-numeric first digit (i.e., recuring on the minute level)

* Re-enable automations

---------

Co-authored-by: sabaimran <narmiabas@gmail.com>
2024-05-31 12:50:19 +05:30
sabaimran
5dca48d9fc Fix setting of conn_max_age variable 2024-05-31 11:07:13 +05:30
sabaimran
76f941f4e5 Revert email from from to sender again in resend API. keeps switching? 2024-05-31 10:30:18 +05:30
sabaimran
b27f59b12b Remove all unused code related to websockets 2024-05-30 11:39:04 +05:30
sabaimran
4b3d3fe7ea /s/sender/from in resend calls 2024-05-30 08:43:46 +05:30
sabaimran
2076543e32 Disable AP Scheduler while performing maintenance 2024-05-30 08:02:59 +05:30
Debanjum Singh Solanky
7823ef09dc Simplify conditional code. Improve logs to track conversion progress 2024-05-29 17:50:07 +05:30
Debanjum Singh Solanky
215db8cab3 Reduce log level of noisy process lock logs 2024-05-29 13:14:44 +05:30
Debanjum Singh Solanky
7b18919564 Tag external links to open in a separate window on the Desktop app
Previously clicking inline links would open the URL directly in the
Desktop app. This was strange and it didn't provide any way to go back
to Khoj desktop app UI from the opened link
2024-05-29 10:12:50 +05:30
Debanjum Singh Solanky
c957a6cb43 Delete unused base_processor_integration html file from web interface 2024-05-29 08:30:13 +05:30
sabaimran
cb33fb67fe Remove the automations-related dead code in the web config 2024-05-29 04:22:45 +05:30
Debanjum Singh Solanky
7594401461 Fix expand chat reference animation in web, desktop, obsidian clients 2024-05-28 20:56:26 +05:30
Debanjum Singh Solanky
1ea7675fc9 View, switch chat sessions from Obsidian chat pane 2024-05-28 20:33:39 +05:30
Debanjum Singh Solanky
e86899eec4 Click on referenced notes by Khoj chat to open it in Obsidian vault
Allow opening Khoj chat references in Obsidian vault if the reference
is a heading or file in the current Obsidian vault
2024-05-28 10:16:40 +05:30
Desmond
70fea6c6b6 fix: delete file request 2024-05-27 14:46:26 +08:00
sabaimran
607534021b Add a link to github in the settings menu, improve styling 2024-05-27 11:39:30 +05:30
Desmond
3f49b5a4ab fix: emacs tests 2024-05-27 10:42:09 +08:00
sabaimran
b97ca9d19d Skip using max_tokens as input to the extract questions step, as that's not used for max_output 2024-05-27 01:23:54 +05:30
sabaimran
9ebf3a4d80 Improve the admin experience, add more metadata to the list_display
- Don't propagate max_tokens to the openai chat completion method. the max for the newer models is fixed at 4096 max output. The token limit is just used for input
2024-05-27 00:49:20 +05:30
sabaimran
01cdc54ad0
Add support for Anthropic models (#760)
* Add support for chatting with Anthropic's suite of models

- Had to use a custom class because there was enough nuance with how the anthropic SDK works that it would be better to simply separate out the logic. The extract questions flow needed modification of the system prompt in order to work as intended with the haiku model
2024-05-26 22:50:34 +05:30
Debanjum Singh Solanky
0f796a79ec Extract function to get link to entry in Obsidian vault for reuse 2024-05-26 18:03:15 +05:30
Debanjum Singh Solanky
e24ca9ec28 Pass file path of each doc reference in references returned by API
- Pass file path of reference along with the compiled reference in
  list of references returned by chat API converts
- Update the structure of references from list of strings to list of
  dictionary (containing 'compiled' and 'file' keys)
- Pull out the compiled reference from the new references data struct
  wherever it was is being used
2024-05-26 18:02:11 +05:30
Debanjum Singh Solanky
ba330712f8 Fix to always pass online results in chat API response 2024-05-26 13:56:55 +05:30
Debanjum Singh Solanky
38d8d2bb56 Show online references used to generate response in Obsidian chat view 2024-05-26 13:55:22 +05:30
Debanjum Singh Solanky
f495d338eb Modularize render message with references func in web based clients
Simplify, reuse, standardize code to render messages with references
in the obsidian, web and desktop clients. Specifically:

- Reuse function to create reference section, dedupe code
- Create reusable function to generate image markdown
- Simplify logic to render message with references
2024-05-26 13:55:22 +05:30
Debanjum Singh Solanky
14a2006c76 Stream steps taken to generate response in Obsidian chat pane
- Setup websocket using Khoj web app as reference.
- Moved the geolocating code to chat view out from the general pane
  view
- Use loading spinner from web instead of the thinking emoji
2024-05-26 13:55:22 +05:30
Debanjum Singh Solanky
afcd22d30c Improve spacing, colors of chat message references and buttons
Works better with dark modes. References have more spacing and adhere
to background color of the chat message itself
2024-05-26 13:55:22 +05:30
Debanjum Singh Solanky
bd4931e70b Add ability to paste chat messages directly into current file
It'll replace any highlighted text with the chat message or if not
text is highlighted, it'll insert the chat message at the last cursor
position in the active file
2024-05-26 13:55:22 +05:30
Debanjum Singh Solanky
032ad3b521 Add ability to copy messages to clipboard from Obsidian Khoj chat 2024-05-26 13:55:22 +05:30
Debanjum Singh Solanky
57f1c53214 Create Nav bar for Obsidian pane. Use abstract View class for reuse
- Jump to chat, show similar actions from nav menu of Khoj side pane
  - Add chat, search icons from web, desktop app
  - Use lucide icon for find similar (for now)
  - Match proportions of find similar icon to khoj other icons via css, js

- Use KhojPaneView abstract class to allow reuse of common functionality like
  - Creating the nav bar header in side pane views
  - Loading geo-location data for chat context
  This should make creating new views easier
2024-05-26 13:55:22 +05:30
sabaimran
e23c803cee Release Khoj version 1.12.1 2024-05-24 21:42:03 +05:30
sabaimran
0308699849 Use links from assets.khoj.dev to render images in the automations page 2024-05-24 20:18:02 +05:30
sabaimran
3f9c20a399
Make it easier to manage server-level chat settings (#729)
* Add support for server-wide model settings fix web page reading results returning logic
2024-05-24 20:15:18 +05:30
sabaimran
cbbbe2da9a
Add a schedule picker and automations preview func (#747)
* Update suggested automations
* add a schedule picker when creating an automation
* Create a new conversation in flow of the automation scheduling in order to send a preview and deliver more consistent results
* Start adding in scaffolding to manually trigger a test job for an automation
* Add support for manually triggering automations for testing
* Schedule automation asynchronously
* Update styling of the preview button
* Improve admin lookup experience and prevent jobs from being scheduled to run every minute of everyday
* Ignore mypy issues on job info short description
2024-05-24 19:42:47 +05:30
sabaimran
4511c6ae7c Fix bug in chat feedback flow - user message not included during live chat 2024-05-21 14:55:39 -05:00
Desmond
a3c6045328 Merge remote-tracking branch 'origin/master' 2024-05-21 21:55:53 +08:00
Desmond
b0630c1a98 Simplify partition 2024-05-21 21:52:01 +08:00
Raghav Tirumale
d57772f9e7
Add Feedback Buttons on Chat (#721)
### Description and Rationale for Changes
This feature includes thumbs up and thumbs down buttons on Khoj's chat responses that provide automated feedback. When a thumbs up/down button is clicked, the code sends an email to team@khoj.dev with the following:
* user query
* khoj's response
* whether the sentiment of the user was good or bad. 

This is critical in improving Khoj's nondeterministic LLM model for a better user experience.
### List of Changes
* new endpoint in `api_chat.py` (/feedback) that can be used to trigger mail sending).
* thumbs up and thumbs down buttons implemented in `chat.html`
* new function in `routers/email.py` to handle feedback email sending via resend
* `feedback.html` template for a formatted email with the feedback.

---------

Co-authored-by: mythicalcow <mythicalcow@linux.myguest.virtualbox.org>
Co-authored-by: sabaimran <narmiabas@gmail.com>
2024-05-20 16:29:08 -05:00
sabaimran
7feaf34702 Fix capitalization, update suggeted prompt 2024-05-10 02:36:13 -07:00
sabaimran
b545aceb47 Use a simpler example for the sample automation and put schedule on top of instructions 2024-05-09 13:53:19 -07:00
sabaimran
7ae00832bd Rname from parameter to sender in resend call 2024-05-09 13:29:39 -07:00
sabaimran
fbd76f8ebe
Improve the UX of automations (#737)
* Improve the automations UX

- Add suggested jobs to elimiinate some of the cold start problem
- Make each of the tasks cards that are clickable/editable

* Hide suggested automations that have already been added

* Add a footer and reapply styling when a save action is taken on a card
2024-05-09 01:29:48 -07:00
sabaimran
70d0ee4310 Only remove the process lock from a process that created it 2024-05-08 10:14:52 -07:00
Desmond Deng
20303feb3a
Merge branch 'khoj-ai:master' into master 2024-05-08 13:46:34 +08:00
Desmond
150cd18bf3 Update batch-size 2024-05-08 13:44:22 +08:00
Desmond
192cd53003 Batch send of index files 2024-05-08 13:38:40 +08:00
sabaimran
a50deb2762 Add better handling for empty responses 2024-05-07 11:49:33 -07:00
sabaimran
4aed6bd274 Add an admin view for subscriptions 2024-05-07 11:48:52 -07:00
sabaimran
77626d28d1 Include stack trace when automation is not successfully craeted 2024-05-07 06:52:41 -07:00
sabaimran
0c8c565ab0 Don't include the whole stack trace for an integrity error 2024-05-07 06:48:18 -07:00
Debanjum Singh Solanky
0a1a6cd041 Get detailed user info in Obsidian from the new v1/user API
Previously we were just getting user email from the /health API
Instead store the retrieved user info in the user settings
2024-05-07 04:37:26 +08:00
Debanjum Singh Solanky
f8f9d066db Focus on input field, scroll to latest message on opening chat pane
Previously scroll and chat input focus weren't applied as view hadn't
been rendered yet
2024-05-07 04:37:26 +08:00
Debanjum Singh Solanky
9f65e8de98 Open Khoj Chat as a Pane instead of a Modal
- Allows having it open on the side as you traverse your Obsidian notes
- Allow faster time to response, having responses visible for context
- Enables ambient interactions
2024-05-07 04:37:26 +08:00
sabaimran
9ae828cf11 Use asssets.khoj.dev for loading math katex rendering 2024-05-07 01:43:46 +08:00
sabaimran
cf0b7628d0 Add the url scheme to the public share url 2024-05-06 21:37:49 +08:00
sabaimran
f6aaecb04f Fix construction method for public share conversation URL 2024-05-06 08:32:51 +05:30
sabaimran
14c9bea663
Make conversations optionally shareable (#712)
* Make conversations optionally shareable

- Shared conversations are viewable by anyone, without a login wall
- Can share a conversation from the three dot menu
- Add a new model for Public Conversation
- The rationale for a separate model is that public and private conversations have different assumptions. Separating them reduces some of the code specificity on our server-side code and allows us for easier interpretation and stricter security. Separating the data model makes it harder to accidentally view something that was meant to be private
- Add a new, read-only view for public conversations
2024-05-05 23:16:04 +05:30
Debanjum Singh Solanky
80cbaca935 Serve generated images from Khoj domain instead of directly from S3
Use CNAME to forward requests from the khoj subdomain to the
equivalent S3 bucket
2024-05-04 20:07:10 +05:30
Debanjum Singh Solanky
425496844b Rename assets URL from Khoj S3 bucket to assets.khoj.dev
Server khoj assets from khoj domain
2024-05-04 20:07:10 +05:30
sabaimran
88daa841fd Rename process lock migration and add a reverse migration step 2024-05-04 20:05:00 +05:30
sabaimran
509a8a412c Throw an error if trying to create a process lock that already exists. Names should be unique 2024-05-04 19:03:53 +05:30
sabaimran
7100614de5
Add support for rendering math equations in the web view (#733)
- Add parsing logic for LaTeX-format math equations in the web chat
- Add placeholder delimiters when converting the markdown to HTML in order to avoid removing the escaped characters
- Add the `<!DOCTYPE html>` specification to the page
2024-05-04 15:59:17 +05:30
Debanjum Singh Solanky
d9b3482b1a Show error when required fields to create automation are not set 2024-05-04 11:17:30 +05:30
Debanjum Singh Solanky
91a5643c5c Use Preview label for Automate feature. Prefix mailto: link to contact 2024-05-04 10:59:17 +05:30
Debanjum Singh Solanky
fd2328ab40 Do not hard code base url of path to automation icon in chat message 2024-05-04 10:59:07 +05:30
sabaimran
a38f3227e2 Revert domain in task task send emails 2024-05-03 15:27:27 +05:30
sabaimran
a1263951e9 Use mail to in email contact link 2024-05-03 12:16:56 +05:30
sabaimran
7c9847fe48 Increase jitter to 60 2024-05-03 11:38:22 +05:30
sabaimran
737ebfd521 Make improvements to online search prompts and use a custom domain for automations emails 2024-05-03 10:47:42 +05:30
sabaimran
42e9504ba8 Use a different function for getting last run time, avoid async/sync issues 2024-05-02 12:13:45 +05:30
sabaimran
9e8491b814 Add experimental disclaimers to the automations 2024-05-02 11:40:37 +05:30
sabaimran
c418449311 Add additional robustness in verifying job execution parameters at run time 2024-05-02 11:13:04 +05:30
sabaimran
690e9d8ed3 Collapse the reminders after they're successfully scheduled 2024-05-02 09:55:04 +05:30
sabaimran
6b648ee3ad Add experimental disclaimer in the automation page 2024-05-02 09:21:27 +05:30