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()
|
25
|
20 local added_message = chat.init_ai()
|
0
|
21 Io.stdout = Http.response.text_writer()
|
|
22 %>
|
|
23 <!doctype html>
|
|
24 <html lang="en">
|
|
25 <head>
|
|
26 <% head() %>
|
4
|
27 <style>
|
|
28 @import "/chat.css?s=<%=started%>";
|
|
29 </style>
|
|
30 <script>
|
6
|
31 let chatId = <%= chat.id %>;
|
28
|
32 let lang = '<%= chat.language_region %>';
|
4
|
33 </script>
|
|
34 <script src="/chat.js?s=<%=started%>"></script>
|
0
|
35 </head>
|
|
36 <body>
|
|
37 <% header() %>
|
4
|
38 <div content ai_container>
|
|
39 <div top>
|
|
40 <h3 name><%= chat.name_html() %></h3>
|
|
41 <span pulldown>
|
|
42 <img onclick="clickMenu(this)" src="/images/menu.svg">
|
|
43 <div>
|
|
44 <span onclick="renameChat()">Rename Chat</span>
|
|
45 <span onclick="deleteChat()">Delete Chat</span>
|
9
|
46 <span onclick="systemPrompt()">System Prompt</span>
|
1
|
47 </div>
|
4
|
48 </span>
|
|
49 </div>
|
7
|
50 <div messages>
|
|
51 <% chat.output_messages_html() %>
|
4
|
52 </div>
|
|
53 <div ask>
|
11
|
54 <textarea autofocus oninput="fixTextarea(event.target)" onkeydown="textareaKey(event)"></textarea>
|
14
|
55 <div buttons>
|
28
|
56 <audio controls preload=none></audio>
|
14
|
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>
|
27
|
87 <pre>
|
9
|
88 <% chat.output_system_prompt() %>
|
27
|
89 </pre>
|
|
90 <p><a href="view_course.html?course=<%=chat.course_id%>">View course</a></p>
|
9
|
91 <div buttons>
|
|
92 <button onclick="closeModal(this)">Close</button>
|
|
93 </div>
|
|
94 </dialog>
|
27
|
95 <input name=initialized style="display:none">
|
6
|
96 <script>
|
|
97 handleMarkdown();
|
27
|
98 setTimeout(function(){
|
|
99 let initialized = document.querySelector('[name=initialized]');
|
|
100 if( !initialized.value ) {
|
|
101 initialized.value = 'yes';
|
|
102 //alert('init');
|
|
103 scrollToEnd();
|
25
|
104 <% if added_message then %>
|
27
|
105 playLastMessage();
|
25
|
106 <% end %>
|
27
|
107 }
|
|
108 },10);
|
6
|
109 </script>
|
0
|
110 </body>
|
|
111 </html>
|
|
112 <%
|
|
113 end
|