Mercurial Hosting > lang
annotate src/chat.html.luan @ 50:85c5f62070d8
misc
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 15 Aug 2025 09:33:29 +0900 |
| parents | 97b0d206cacd |
| children | 4581a20b8124 |
| rev | line source |
|---|---|
| 0 | 1 local Luan = require "luan:Luan.luan" |
| 2 local error = Luan.error | |
| 31 | 3 local ipairs = Luan.ipairs or error() |
| 29 | 4 local Parsers = require "luan:Parsers.luan" |
| 5 local json_string = Parsers.json_string or error() | |
|
35
3117876debca
ai_first_message in textarea
Franklin Schmidt <fschmidt@gmail.com>
parents:
34
diff
changeset
|
6 local Html = require "luan:Html.luan" |
|
3117876debca
ai_first_message in textarea
Franklin Schmidt <fschmidt@gmail.com>
parents:
34
diff
changeset
|
7 local html_encode = Html.encode or error() |
| 0 | 8 local Io = require "luan:Io.luan" |
| 9 local Http = require "luan:http/Http.luan" | |
| 10 local Shared = require "site:/lib/Shared.luan" | |
| 11 local head = Shared.head or error() | |
| 12 local header = Shared.header or error() | |
| 4 | 13 local started = Shared.started or error() |
| 31 | 14 local voices = Shared.voices or error() |
| 4 | 15 local User = require "site:/lib/User.luan" |
| 41 | 16 local current_user = User.current or error() |
| 4 | 17 local Chat = require "site:/lib/Chat.luan" |
| 18 local get_chat_by_id = Chat.get_by_id or error() | |
| 46 | 19 local Utils = require "site:/lib/Utils.luan" |
| 20 local capitalize = Utils.capitalize or error() | |
| 0 | 21 |
| 22 | |
| 23 return function() | |
| 18 | 24 local chat_id = Http.request.parameters.chat or error() |
| 25 local chat = get_chat_by_id(chat_id) or error() | |
| 41 | 26 local user = current_user() |
| 27 local is_owner = user ~= nil and user.id == chat.user_id | |
| 28 is_owner or not chat.is_private or error "private" | |
|
35
3117876debca
ai_first_message in textarea
Franklin Schmidt <fschmidt@gmail.com>
parents:
34
diff
changeset
|
29 local init_text = chat.init_text() |
| 0 | 30 Io.stdout = Http.response.text_writer() |
| 31 %> | |
| 32 <!doctype html> | |
| 33 <html lang="en"> | |
| 34 <head> | |
| 35 <% head() %> | |
| 4 | 36 <style> |
| 37 @import "/chat.css?s=<%=started%>"; | |
| 38 </style> | |
| 39 <script src="/chat.js?s=<%=started%>"></script> | |
| 0 | 40 </head> |
| 41 <body> | |
| 42 <% header() %> | |
| 4 | 43 <div content ai_container> |
| 44 <div top> | |
| 29 | 45 <h3 name></h3> |
| 4 | 46 <span pulldown> |
| 47 <img onclick="clickMenu(this)" src="/images/menu.svg"> | |
| 48 <div> | |
| 41 | 49 <% if is_owner then %> |
| 29 | 50 <span onclick="editChat()">Edit Chat</span> |
| 4 | 51 <span onclick="deleteChat()">Delete Chat</span> |
| 41 | 52 <% end %> |
| 9 | 53 <span onclick="systemPrompt()">System Prompt</span> |
| 50 | 54 <a href="chat.json?chat=<%=chat_id%>">Chat JSON</a> |
| 1 | 55 </div> |
| 4 | 56 </span> |
| 57 </div> | |
| 7 | 58 <div messages> |
| 59 <% chat.output_messages_html() %> | |
| 4 | 60 </div> |
| 41 | 61 <% if is_owner then %> |
| 4 | 62 <div ask> |
| 50 | 63 <textarea oninput="fixChatTextarea(event.target)" onkeydown="textareaKey(event)"><%= html_encode(init_text) %></textarea> |
| 14 | 64 <div buttons> |
| 28 | 65 <audio controls preload=none></audio> |
| 14 | 66 <button record onclick="toggleRecording()">Record</button> |
| 67 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button> | |
| 68 </div> | |
| 1 | 69 </div> |
| 41 | 70 <% end %> |
| 0 | 71 </div> |
| 6 | 72 <img waiting-ai-icon src="/images/spinner_green.gif"> |
| 29 | 73 <dialog edit> |
| 74 <h2>Edit Chat</h2> | |
| 75 <form onsubmit="saveChat(this)" action="javascript:"> | |
| 76 <input type=hidden name=chat value="<%=chat.id%>"> | |
| 4 | 77 <p> |
| 78 <label>Chat name</label><br> | |
| 34 | 79 <input type=text name=name required><br> |
| 4 | 80 <span error></span> |
| 81 </p> | |
| 32 | 82 <p><%= chat.language_name() %></p> |
| 83 <p> | |
| 31 | 84 <label>Voice</label><br> |
| 85 <select name=voice> | |
| 86 <% for _, voice in ipairs(voices) do %> | |
| 46 | 87 <option value="<%=voice%>"><%=capitalize(voice)%></option> |
| 31 | 88 <% end %> |
| 89 <select> | |
| 90 </p> | |
| 34 | 91 <p> |
| 36 | 92 <label clickable><input type=checkbox name=autoplay>Autoplay</label> |
| 93 </p> | |
| 94 <p> | |
| 34 | 95 <label clickable><input type=checkbox name=show_text>Show text</label> |
| 96 </p> | |
| 41 | 97 <p> |
| 98 <label clickable><input type=checkbox name=is_private>Private chat</label> | |
| 99 </p> | |
| 4 | 100 <div buttons> |
| 101 <button type=button onclick="closeModal(this)">Cancel</button> | |
| 29 | 102 <button type=submit>Save</button> |
| 4 | 103 </div> |
| 104 </form> | |
| 105 </dialog> | |
| 106 <dialog delete> | |
| 107 <h2>Delete Chat</h2> | |
| 108 <p>Are you sure that you want to delete this chat?</p> | |
| 109 <div buttons> | |
| 110 <button onclick="closeModal(this)">Cancel</button> | |
| 111 <button onclick="doDeleteChat(this)">Delete</button> | |
| 112 </div> | |
| 113 </dialog> | |
| 9 | 114 <dialog system_prompt> |
| 115 <h2>System Prompt</h2> | |
| 27 | 116 <pre> |
| 9 | 117 <% chat.output_system_prompt() %> |
| 27 | 118 </pre> |
| 50 | 119 <h3>Text to speech instructions</h3> |
| 120 <pre> | |
| 121 <%= chat.tts_instructions %> | |
| 122 </pre> | |
| 27 | 123 <p><a href="view_course.html?course=<%=chat.course_id%>">View course</a></p> |
| 9 | 124 <div buttons> |
| 125 <button onclick="closeModal(this)">Close</button> | |
| 126 </div> | |
| 127 </dialog> | |
| 27 | 128 <input name=initialized style="display:none"> |
| 6 | 129 <script> |
| 41 | 130 'use strict'; |
| 29 | 131 setChat(<%= json_string(chat.info()) %>); |
| 132 handleChatMarkdown(); | |
| 27 | 133 setTimeout(function(){ |
| 134 let initialized = document.querySelector('[name=initialized]'); | |
| 135 if( !initialized.value ) { | |
| 136 initialized.value = 'yes'; | |
| 137 //alert('init'); | |
| 50 | 138 document.querySelector('textarea').focus(); |
| 27 | 139 scrollToEnd(); |
| 140 } | |
| 50 | 141 },100); |
| 6 | 142 </script> |
| 0 | 143 </body> |
| 144 </html> | |
| 145 <% | |
| 146 end |
