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