0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Io = require "luan:Io.luan"
|
|
4 local Http = require "luan:http/Http.luan"
|
|
5 local Shared = require "site:/lib/Shared.luan"
|
|
6 local head = Shared.head or error()
|
|
7 local header = Shared.header or error()
|
4
|
8 local started = Shared.started or error()
|
|
9 local User = require "site:/lib/User.luan"
|
|
10 local current_user = User.current or error()
|
|
11 local Chat = require "site:/lib/Chat.luan"
|
|
12 local get_chat_by_id = Chat.get_by_id or error()
|
0
|
13
|
|
14
|
|
15 return function()
|
4
|
16 local user = current_user()
|
|
17 if user == nil then
|
|
18 Http.response.send_redirect("/login.html")
|
|
19 return
|
|
20 end
|
18
|
21 local chat_id = Http.request.parameters.chat or error()
|
|
22 local chat = get_chat_by_id(chat_id) or error()
|
0
|
23 Io.stdout = Http.response.text_writer()
|
|
24 %>
|
|
25 <!doctype html>
|
|
26 <html lang="en">
|
|
27 <head>
|
|
28 <% head() %>
|
4
|
29 <style>
|
|
30 @import "/chat.css?s=<%=started%>";
|
|
31 </style>
|
|
32 <script>
|
6
|
33 let chatId = <%= chat.id %>;
|
4
|
34 </script>
|
|
35 <script src="/chat.js?s=<%=started%>"></script>
|
0
|
36 </head>
|
|
37 <body>
|
|
38 <% header() %>
|
4
|
39 <div content ai_container>
|
|
40 <div top>
|
|
41 <h3 name><%= chat.name_html() %></h3>
|
|
42 <span pulldown>
|
|
43 <img onclick="clickMenu(this)" src="/images/menu.svg">
|
|
44 <div>
|
|
45 <span onclick="renameChat()">Rename Chat</span>
|
|
46 <span onclick="deleteChat()">Delete Chat</span>
|
9
|
47 <span onclick="systemPrompt()">System Prompt</span>
|
1
|
48 </div>
|
4
|
49 </span>
|
|
50 </div>
|
7
|
51 <div messages>
|
|
52 <% chat.output_messages_html() %>
|
4
|
53 </div>
|
|
54 <div ask>
|
11
|
55 <textarea autofocus oninput="fixTextarea(event.target)" onkeydown="textareaKey(event)"></textarea>
|
14
|
56 <div buttons>
|
|
57 <button record onclick="toggleRecording()">Record</button>
|
|
58 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button>
|
|
59 </div>
|
1
|
60 </div>
|
0
|
61 </div>
|
6
|
62 <img waiting-ai-icon src="/images/spinner_green.gif">
|
4
|
63 <dialog rename>
|
|
64 <h2>Rename Chat</h2>
|
|
65 <form action="javascript:saveRenameChat()">
|
|
66 <p>
|
|
67 <label>Chat name</label><br>
|
|
68 <input name=name required><br>
|
|
69 <span error></span>
|
|
70 </p>
|
|
71 <div buttons>
|
|
72 <button type=button onclick="closeModal(this)">Cancel</button>
|
|
73 <button type=submit>Rename</button>
|
|
74 </div>
|
|
75 </form>
|
|
76 </dialog>
|
|
77 <dialog delete>
|
|
78 <h2>Delete Chat</h2>
|
|
79 <p>Are you sure that you want to delete this chat?</p>
|
|
80 <div buttons>
|
|
81 <button onclick="closeModal(this)">Cancel</button>
|
|
82 <button onclick="doDeleteChat(this)">Delete</button>
|
|
83 </div>
|
|
84 </dialog>
|
9
|
85 <dialog system_prompt>
|
|
86 <h2>System Prompt</h2>
|
|
87 <div system_prompt>
|
|
88 <% chat.output_system_prompt() %>
|
|
89 </div>
|
|
90 <div buttons>
|
|
91 <button onclick="closeModal(this)">Close</button>
|
|
92 </div>
|
|
93 </dialog>
|
6
|
94 <script>
|
|
95 handleMarkdown();
|
|
96 </script>
|
0
|
97 </body>
|
|
98 </html>
|
|
99 <%
|
|
100 end
|