view src/chat.html.luan @ 24:87fe70201aa8

courses work
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Jul 2025 22:30:26 -0600
parents 820136c5ee33
children 3a80ddafe5a4
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local head = Shared.head or error()
local header = Shared.header or error()
local started = Shared.started or error()
local User = require "site:/lib/User.luan"
local current_user = User.current_required or error()
local Chat = require "site:/lib/Chat.luan"
local get_chat_by_id = Chat.get_by_id or error()


return function()
	local user = current_user()
	if user == nil then return end
	local chat_id = Http.request.parameters.chat or error()
	local chat = get_chat_by_id(chat_id) or error()
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html lang="en">
	<head>
<%		head() %>
		<style>
			@import "/chat.css?s=<%=started%>";
		</style>
		<script>
			let chatId = <%= chat.id %>;
		</script>
		<script src="/chat.js?s=<%=started%>"></script>
	</head>
	<body>
<%		header() %>
		<div content ai_container>
			<div top>
				<h3 name><%= chat.name_html() %></h3>
				<span pulldown>
					<img onclick="clickMenu(this)" src="/images/menu.svg">
					<div>
						<span onclick="renameChat()">Rename Chat</span>
						<span onclick="deleteChat()">Delete Chat</span>
						<span onclick="systemPrompt()">System Prompt</span>
					</div>
				</span>
			</div>
			<div messages>
<%				chat.output_messages_html() %>
			</div>
			<div ask>
				<textarea autofocus oninput="fixTextarea(event.target)" onkeydown="textareaKey(event)"></textarea>
				<div buttons>
					<button record onclick="toggleRecording()">Record</button>
					<button onclick="askAi()" title="Send"><img src="/images/send.svg"></button>
				</div>
			</div>
		</div>
		<img waiting-ai-icon src="/images/spinner_green.gif">
		<dialog rename>
			<h2>Rename Chat</h2>
			<form action="javascript:saveRenameChat()">
				<p>
					<label>Chat name</label><br> 
					<input name=name required><br>
					<span error></span>
				</p>
				<div buttons>
					<button type=button onclick="closeModal(this)">Cancel</button>
					<button type=submit>Rename</button>
				</div>
			</form>
		</dialog>
		<dialog delete>
			<h2>Delete Chat</h2>
			<p>Are you sure that you want to delete this chat?</p>
			<div buttons>
				<button onclick="closeModal(this)">Cancel</button>
				<button onclick="doDeleteChat(this)">Delete</button>
			</div>
		</dialog>
		<dialog system_prompt>
			<h2>System Prompt</h2>
			<div system_prompt>
<%				chat.output_system_prompt() %>
			</div>
			<div buttons>
				<button onclick="closeModal(this)">Close</button>
			</div>
		</dialog>
		<script>
			handleMarkdown();
		</script>
	</body>
</html>
<%
end