Mercurial Hosting > lang
comparison src/ai_ask.js.luan @ 71:44bec62c49e2 default tip
split ask
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 24 Aug 2025 08:32:08 -0600 |
parents | 4a73af8f2203 |
children |
comparison
equal
deleted
inserted
replaced
70:4a73af8f2203 | 71:44bec62c49e2 |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local Parsers = require "luan:Parsers.luan" | |
4 local json_string = Parsers.json_string or error() | |
5 local Io = require "luan:Io.luan" | |
6 local Http = require "luan:http/Http.luan" | |
7 local User = require "site:/lib/User.luan" | |
8 local current_user = User.current or error() | |
9 local Chat = require "site:/lib/Chat.luan" | |
10 local get_chat_by_id = Chat.get_by_id or error() | |
11 | |
12 | |
13 return function() | |
14 Io.stdout = Http.response.text_writer() | |
15 local parameters = Http.request.parameters | |
16 local chat = parameters.chat or error() | |
17 chat = get_chat_by_id(chat) or error() | |
18 chat.user_id == current_user().id or error() | |
19 local input = parameters.input or error() | |
20 if input == "" then | |
21 %> | |
22 hideWaitingAiIcon(); | |
23 <% | |
24 return | |
25 end | |
26 local html = chat.ask(input) | |
27 %> | |
28 updateAi(<%=json_string(html)%>); | |
29 <% | |
30 end |