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