Mercurial Hosting > lang
annotate src/chat.html.luan @ 66:2ff1f78bb13e
minor
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 22 Aug 2025 07:25:35 -0600 |
| parents | bd3f16f7b8b7 |
| children | 44bec62c49e2 |
| 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> | |
| 51 | 45 <h2 name></h2> |
| 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> |
| 1 | 54 </div> |
| 4 | 55 </span> |
| 56 </div> | |
| 7 | 57 <div messages> |
| 58 <% chat.output_messages_html() %> | |
| 4 | 59 </div> |
| 41 | 60 <% if is_owner then %> |
| 4 | 61 <div ask> |
| 50 | 62 <textarea oninput="fixChatTextarea(event.target)" onkeydown="textareaKey(event)"><%= html_encode(init_text) %></textarea> |
| 14 | 63 <div buttons> |
| 28 | 64 <audio controls preload=none></audio> |
| 14 | 65 <button record onclick="toggleRecording()">Record</button> |
| 66 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button> | |
| 67 </div> | |
| 1 | 68 </div> |
| 41 | 69 <% end %> |
| 0 | 70 </div> |
| 6 | 71 <img waiting-ai-icon src="/images/spinner_green.gif"> |
| 29 | 72 <dialog edit> |
| 73 <h2>Edit Chat</h2> | |
| 74 <form onsubmit="saveChat(this)" action="javascript:"> | |
| 75 <input type=hidden name=chat value="<%=chat.id%>"> | |
| 4 | 76 <p> |
| 77 <label>Chat name</label><br> | |
| 34 | 78 <input type=text name=name required><br> |
| 4 | 79 <span error></span> |
| 80 </p> | |
| 32 | 81 <p><%= chat.language_name() %></p> |
| 82 <p> | |
| 31 | 83 <label>Voice</label><br> |
| 84 <select name=voice> | |
| 85 <% for _, voice in ipairs(voices) do %> | |
| 46 | 86 <option value="<%=voice%>"><%=capitalize(voice)%></option> |
| 31 | 87 <% end %> |
| 88 <select> | |
| 89 </p> | |
| 34 | 90 <p> |
| 36 | 91 <label clickable><input type=checkbox name=autoplay>Autoplay</label> |
| 92 </p> | |
| 93 <p> | |
| 52 | 94 <select name=show_text> |
| 95 <option value=show_text>Show text</option> | |
| 96 <% if chat.has_ruby then %> | |
| 97 <option value=hide_ruby>Hide pronunciation</option> | |
| 98 <% end %> | |
| 99 <option value=hide_text>Hide text</option> | |
| 100 </select> | |
| 34 | 101 </p> |
| 41 | 102 <p> |
| 103 <label clickable><input type=checkbox name=is_private>Private chat</label> | |
| 104 </p> | |
| 4 | 105 <div buttons> |
| 106 <button type=button onclick="closeModal(this)">Cancel</button> | |
| 29 | 107 <button type=submit>Save</button> |
| 4 | 108 </div> |
| 109 </form> | |
| 110 </dialog> | |
| 111 <dialog delete> | |
| 112 <h2>Delete Chat</h2> | |
| 113 <p>Are you sure that you want to delete this chat?</p> | |
| 114 <div buttons> | |
| 115 <button onclick="closeModal(this)">Cancel</button> | |
| 116 <button onclick="doDeleteChat(this)">Delete</button> | |
| 117 </div> | |
| 118 </dialog> | |
| 9 | 119 <dialog system_prompt> |
| 120 <h2>System Prompt</h2> | |
| 27 | 121 <pre> |
| 9 | 122 <% chat.output_system_prompt() %> |
| 27 | 123 </pre> |
| 50 | 124 <h3>Text to speech instructions</h3> |
| 125 <pre> | |
| 126 <%= chat.tts_instructions %> | |
| 127 </pre> | |
| 27 | 128 <p><a href="view_course.html?course=<%=chat.course_id%>">View course</a></p> |
| 9 | 129 <div buttons> |
| 130 <button onclick="closeModal(this)">Close</button> | |
| 131 </div> | |
| 132 </dialog> | |
| 27 | 133 <input name=initialized style="display:none"> |
| 6 | 134 <script> |
| 41 | 135 'use strict'; |
| 29 | 136 setChat(<%= json_string(chat.info()) %>); |
| 137 handleChatMarkdown(); | |
| 27 | 138 setTimeout(function(){ |
| 139 let initialized = document.querySelector('[name=initialized]'); | |
| 140 if( !initialized.value ) { | |
| 141 initialized.value = 'yes'; | |
| 142 //alert('init'); | |
| 62 | 143 <% if is_owner then %> |
| 50 | 144 document.querySelector('textarea').focus(); |
| 27 | 145 scrollToEnd(); |
| 62 | 146 <% end %> |
| 27 | 147 } |
| 50 | 148 },100); |
| 6 | 149 </script> |
| 0 | 150 </body> |
| 151 </html> | |
| 152 <% | |
| 153 end |
