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 %>;
|
4
|
32 </script>
|
|
33 <script src="/chat.js?s=<%=started%>"></script>
|
0
|
34 </head>
|
|
35 <body>
|
|
36 <% header() %>
|
4
|
37 <div content ai_container>
|
|
38 <div top>
|
|
39 <h3 name><%= chat.name_html() %></h3>
|
|
40 <span pulldown>
|
|
41 <img onclick="clickMenu(this)" src="/images/menu.svg">
|
|
42 <div>
|
|
43 <span onclick="renameChat()">Rename Chat</span>
|
|
44 <span onclick="deleteChat()">Delete Chat</span>
|
9
|
45 <span onclick="systemPrompt()">System Prompt</span>
|
1
|
46 </div>
|
4
|
47 </span>
|
|
48 </div>
|
7
|
49 <div messages>
|
|
50 <% chat.output_messages_html() %>
|
4
|
51 </div>
|
|
52 <div ask>
|
11
|
53 <textarea autofocus oninput="fixTextarea(event.target)" onkeydown="textareaKey(event)"></textarea>
|
14
|
54 <div buttons>
|
|
55 <button record onclick="toggleRecording()">Record</button>
|
|
56 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button>
|
|
57 </div>
|
1
|
58 </div>
|
0
|
59 </div>
|
6
|
60 <img waiting-ai-icon src="/images/spinner_green.gif">
|
4
|
61 <dialog rename>
|
|
62 <h2>Rename Chat</h2>
|
|
63 <form action="javascript:saveRenameChat()">
|
|
64 <p>
|
|
65 <label>Chat name</label><br>
|
|
66 <input name=name required><br>
|
|
67 <span error></span>
|
|
68 </p>
|
|
69 <div buttons>
|
|
70 <button type=button onclick="closeModal(this)">Cancel</button>
|
|
71 <button type=submit>Rename</button>
|
|
72 </div>
|
|
73 </form>
|
|
74 </dialog>
|
|
75 <dialog delete>
|
|
76 <h2>Delete Chat</h2>
|
|
77 <p>Are you sure that you want to delete this chat?</p>
|
|
78 <div buttons>
|
|
79 <button onclick="closeModal(this)">Cancel</button>
|
|
80 <button onclick="doDeleteChat(this)">Delete</button>
|
|
81 </div>
|
|
82 </dialog>
|
9
|
83 <dialog system_prompt>
|
|
84 <h2>System Prompt</h2>
|
27
|
85 <pre>
|
9
|
86 <% chat.output_system_prompt() %>
|
27
|
87 </pre>
|
|
88 <p><a href="view_course.html?course=<%=chat.course_id%>">View course</a></p>
|
9
|
89 <div buttons>
|
|
90 <button onclick="closeModal(this)">Close</button>
|
|
91 </div>
|
|
92 </dialog>
|
27
|
93 <input name=initialized style="display:none">
|
6
|
94 <script>
|
|
95 handleMarkdown();
|
27
|
96 setTimeout(function(){
|
|
97 let initialized = document.querySelector('[name=initialized]');
|
|
98 if( !initialized.value ) {
|
|
99 initialized.value = 'yes';
|
|
100 //alert('init');
|
|
101 scrollToEnd();
|
25
|
102 <% if added_message then %>
|
27
|
103 playLastMessage();
|
25
|
104 <% end %>
|
27
|
105 }
|
|
106 },10);
|
6
|
107 </script>
|
0
|
108 </body>
|
|
109 </html>
|
|
110 <%
|
|
111 end
|