1 var chat = document.getElementById('chat');
2 var chatTypeDiv = document.getElementById('chatTypeDiv');
3 var docTitle = document.getElementById('docTitle');
4 var restart_button = document.getElementById('restart');
5 var input_text = document.getElementById('input');
6 var send_button = document.getElementById('send');
7 let restartNewChat = document.getElementById('restartNewChat');
8 var thisChatType = chatTypes.balance;
13 var isSpeaking = false;
15 reSetStartChatMessage();
18 function addMyChat(message) {
19 let bobo = document.createElement('div');
20 bobo.style.whiteSpace = 'pre-wrap';
21 bobo.innerText = message;
22 bobo.classList.add('bobo');
23 bobo.classList.add('markdown-body');
24 let go = document.createElement('div');
25 go.classList.add('my');
31 function addError(message) {
32 let go = document.createElement('div');
33 go.classList.add('error');
34 go.innerHTML = message;
38 let onMessageIsOKClose = false;
40 function onMessage(json, returnMessage) {
41 if (json.type == "close") {
43 if (!onMessageIsOKClose) {
44 addError("聊天异常中断了!可能是网络问题。");
48 if (json.type == 'error') {
49 addError("连接发生错误:" + json.mess);
52 onMessageIsOKClose = false
54 onMessageIsOKClose = true;
55 returnMessage.getCatWebSocket().close(1000, 'ok');
57 localStorage.removeItem('LastChatJson');
59 porserArguments(json.arguments);
60 } else if (json.type == 2) {
61 porserType2Item(json.item);
63 console.log(JSON.stringify(json));
73 input_text.addEventListener('keydown', (event) => {
74 if (event.key === 'Enter' && !event.altKey) {
75 event.preventDefault();
77 send_button.onclick();
78 } else if (event.key === 'Enter' && event.altKey) {
79 event.preventDefault();
81 input_text.value += "\n";
86 function reSetStartChatMessage(type) {
87 createChat(thisChatType).then((r) => {
88 if(r.ok) talk = r.obj;
90 getChatHubWithMagic().then(async a => {
93 t = await getLastChatInvocationId();
97 <div class="adaptiveCardsFatherDIV">
98 <div class="textBlock markdown-body">
100 <div class="throttling">
110 function isAskingToMagic() {
112 send_button.value = '施法中.';
116 function isSpeakingStart(chatWithMagic, sendText) {
120 docTitle.innerText = sendText;
122 send_button.value = '响应中.';
126 function isSpeakingFinish() {
128 send_button.value = 'submit';
131 function send(text) {
135 chatTypeDiv.style.opacity = 0;
139 createChat(thisChatType).then((r) => {
147 r = talk.sendMessage(text, onMessage);
153 returnMessage = r.obj;
154 isSpeakingStart(r.chatWithMagic, text);
159 let r = talk.sendMessage(text, onMessage)
165 returnMessage = r.obj;
166 isSpeakingStart(r.chatWithMagic, text);
170 send_button.onclick = () => {
174 let text = input_text.value;
175 input_text.value = '';
176 input_update_input_text_sstyle_show_update({ target: input_text });
184 restart_button.onclick = () => {
185 onMessageIsOKClose = true;
187 returnMessage.getCatWebSocket().close(1000, 'ok');
188 returnMessage = undefined;
192 reSetStartChatMessage();
193 chatTypeDiv.style.opacity = 1;
201 function handleScroll() {
203 var docHeight = document.body.scrollHeight;
204 var scrollPos = window.pageYOffset;
205 // 如果滚动到底部,显示元素,否则隐藏元素
208 window.addEventListener("scroll", handleScroll);
214 let backgroundDIV = document.getElementById('background');
215 let chatTypeChoseCreate = document.getElementById('chatTypeChoseCreate');
216 let chatTypeChoseBalance = document.getElementById('chatTypeChoseBalance');
217 let chatTypeChoseAccurate = document.getElementById('chatTypeChoseAccurate');
219 thisChatType = chatTypes.balance;
220 chatTypeChoseCreate.onclick = () => {
221 if (chatTypeDiv.style.opacity == 0) {
224 chatTypeChoseCreate.classList.add('Chose');
225 chatTypeChoseBalance.classList.remove('Chose');
226 chatTypeChoseAccurate.classList.remove('Chose');
227 thisChatType = chatTypes.create;
228 backgroundDIV.className = 'a';
229 reSetStartChatMessage('create');
231 chatTypeChoseBalance.onclick = () => {
232 if (chatTypeDiv.style.opacity == 0) {
235 chatTypeChoseCreate.classList.remove('Chose');
236 chatTypeChoseBalance.classList.add('Chose');
237 chatTypeChoseAccurate.classList.remove('Chose');
238 thisChatType = chatTypes.balance;
239 backgroundDIV.className = 'b';
240 reSetStartChatMessage('balance');
242 chatTypeChoseAccurate.onclick = () => {
243 if (chatTypeDiv.style.opacity == 0) {
246 chatTypeChoseCreate.classList.remove('Chose');
247 chatTypeChoseBalance.classList.remove('Chose');
248 chatTypeChoseAccurate.classList.add('Chose');
249 thisChatType = chatTypes.accurate;
250 backgroundDIV.className = 'c';
251 reSetStartChatMessage('accurate');
255 // "resourceTypes": [
275 function input_update_input_text_sstyle_show_update(v) {
276 if (v.target.value) {
277 send_button.style.opacity = 1;
279 send_button.style.opacity = 0;
282 input_text.addEventListener("input", input_update_input_text_sstyle_show_update);
283 input_update_input_text_sstyle_show_update({ target: input_text });
287 restartNewChat.onclick = async () => {
288 localStorage.removeItem('LastChatJson');
289 await setLastInvocationId(1);
290 restart_button.onclick();