Mercurial Hosting > lang
diff src/ai_ask.js.luan @ 5:a970b7a01a74
start ai
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 16 Jul 2025 15:08:14 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ai_ask.js.luan Wed Jul 16 15:08:14 2025 -0600 @@ -0,0 +1,30 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Parsers = require "luan:Parsers.luan" +local json_string = Parsers.json_string or error() +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local User = require "site:/lib/User.luan" +local current_user = User.current or error() +local Chat = require "site:/lib/Chat.luan" +local get_chat_by_id = Chat.get_by_id or error() + + +return function() + Io.stdout = Http.response.text_writer() + local parameters = Http.request.parameters + local chat = parameters.chat or error() + chat = get_chat_by_id(chat) or error() + chat.user_id == current_user().id or error() + local input = parameters.input or error() + if input == "" then +%> + hideWaitingAiIcon(); +<% + return + end + local html = chat.ask(input) +%> + updateAi(<%=json_string(html)%>); +<% +end