From 8012b35dfe9eb3776a435f7242541fcf8eda167f Mon Sep 17 00:00:00 2001 From: G-Fourteen Date: Sat, 13 Sep 2025 00:33:14 -0600 Subject: [PATCH] Add files via upload --- chat-core.js | 44 ++++------ chat-init.js | 31 +++---- chat-storage.js | 84 +++++++------------ index.html | 77 ++++++----------- memory-api.js | 61 ++++---------- screensaver.js | 178 +++++++++++++++++++--------------------- simple.js | 66 +++++++-------- storage.js | 7 +- styles.css | 187 +++++++++++++++++------------------------- stylesScreensaver.css | 41 ++------- ui.js | 35 ++++---- 11 files changed, 314 insertions(+), 497 deletions(-) diff --git a/chat-core.js b/chat-core.js index cb7cbfb..7155830 100644 --- a/chat-core.js +++ b/chat-core.js @@ -3,10 +3,7 @@ async function pollinationsFetch(url, options = {}, { timeoutMs = 45000 } = {}) const controller = new AbortController(); const timer = setTimeout(() => controller.abort(new DOMException('timeout', 'AbortError')), timeoutMs); try { - const res = await fetch( - url, - { ...options, signal: controller.signal, cache: 'no-store' } - ); + const res = await fetch(url, { ...options, signal: controller.signal, cache: 'no-store' }); if (!res.ok) throw new Error(`HTTP ${res.status}`); return res; } finally { @@ -472,50 +469,39 @@ document.addEventListener("DOMContentLoaded", () => { } } - const messages = []; - if (window.aiInstructions) { - messages.push({ role: "system", content: window.aiInstructions }); - } + let prompt = window.aiInstructions; const memories = Memory.getMemories(); if (memories?.length) { - messages.push({ role: "system", content: `Relevant memory:\n${memories.join("\n")}\nUse it in your response.` }); + prompt += `\nRelevant memory:\n${memories.join("\n")}\nUse it in your response.`; } const HISTORY = 10; const end = currentSession.messages.length - 1; const start = Math.max(0, end - HISTORY); for (let i = start; i < end; i++) { - messages.push(currentSession.messages[i]); + const m = currentSession.messages[i]; + prompt += `\n${m.role === "ai" ? "AI" : "User"}: ${m.content}`; } const lastUser = overrideContent || currentSession.messages[end]?.content; if (lastUser) { - messages.push({ role: "user", content: lastUser }); + prompt += `\nUser: ${lastUser}`; } const modelSelectEl = document.getElementById("model-select"); - const model = modelSelectEl?.value || currentSession.model || Storage.getDefaultModel(); - if (!model) { - loadingDiv.textContent = "Error: No model selected."; - setTimeout(() => loadingDiv.remove(), 3000); - const btn = window._chatInternals?.sendButton || document.getElementById("send-button"); - const input = window._chatInternals?.chatInput || document.getElementById("chat-input"); - if (btn) btn.disabled = false; - if (input) input.disabled = false; - showToast("Please select a model before sending a message."); - if (callback) callback(); - return; - } + const model = modelSelectEl?.value || currentSession.model; + if (!model) throw new Error("No model selected"); + const apiUrl = `https://text.pollinations.ai/${encodeURIComponent(prompt)}?model=${encodeURIComponent(model)}`; try { - const res = await window.pollinationsFetch("https://text.pollinations.ai/openai", { - method: "POST", - headers: { "Content-Type": "application/json", Accept: "application/json" }, - body: JSON.stringify({ model, messages }) + const res = await window.pollinationsFetch(apiUrl, { + method: "GET", + headers: { "Accept": "text/plain" } }, { timeoutMs: 45000 }); - const data = await res.json(); + const aiContentRaw = await res.text(); + loadingDiv.remove(); - const aiContentRaw = data?.choices?.[0]?.message?.content || ""; + let aiContent = aiContentRaw; const memRegex = /\[memory\]([\s\S]*?)\[\/memory\]/gi; diff --git a/chat-init.js b/chat-init.js index 17a429a..928b3a1 100644 --- a/chat-init.js +++ b/chat-init.js @@ -565,24 +565,19 @@ document.addEventListener("DOMContentLoaded", () => { chatInput.disabled = true; }; window._chatInternals.handleSendMessage = handleSendMessage; - chatInput.addEventListener("input", () => { - sendButton.disabled = chatInput.value.trim() === ""; - chatInput.style.height = "auto"; - chatInput.style.height = chatInput.scrollHeight + "px"; - }); - sendButton.addEventListener("click", handleSendMessage); - - // Send on Enter, allow newline with Shift+Enter - chatInput.addEventListener('keydown', (e) => { - if (e.key === 'Enter') { - if (e.shiftKey) return; // allow newline - e.preventDefault(); - // Directly invoke the send handler so the message is processed - // even if the button state would block programmatic clicks. - handleSendMessage(); - } - }); - sendButton.disabled = chatInput.value.trim() === ""; + chatInput.addEventListener("input", () => { + sendButton.disabled = chatInput.value.trim() === ""; + chatInput.style.height = "auto"; + chatInput.style.height = chatInput.scrollHeight + "px"; + }); + chatInput.addEventListener("keydown", e => { + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + handleSendMessage(); + } + }); + sendButton.addEventListener("click", handleSendMessage); + sendButton.disabled = chatInput.value.trim() === ""; chatInput.dispatchEvent(new Event("input")); const initialSession = Storage.getCurrentSession(); if (initialSession.messages?.length > 0) renderStoredMessages(initialSession.messages); diff --git a/chat-storage.js b/chat-storage.js index 0f56252..77d43b2 100644 --- a/chat-storage.js +++ b/chat-storage.js @@ -1,36 +1,7 @@ document.addEventListener("DOMContentLoaded", () => { const { chatBox, chatInput, clearChatBtn, voiceToggleBtn, modelSelect, synth, autoSpeakEnabled, speakMessage, stopSpeaking, showToast, toggleSpeechRecognition, initSpeechRecognition, handleVoiceCommand, speakSentences } = window._chatInternals; const imagePatterns = window.imagePatterns; - - function openImageModal(imageUrl) { - window.open(imageUrl, "_blank"); - } - - function addImageToGallery(imageUrl) { - const gallery = document.getElementById('past-image-gallery'); - if (!gallery) return; - if ([...gallery.querySelectorAll('img.thumbnail')].some(img => img.src === imageUrl)) return; - const wrapper = gallery.parentElement; - const img = document.createElement('img'); - img.src = imageUrl; - img.className = 'thumbnail'; - img.addEventListener('click', () => { - openImageModal(imageUrl); - }); - gallery.appendChild(img); - if (wrapper && wrapper.classList.contains('hidden')) { - wrapper.classList.remove('hidden'); - } - if (window.Memory && typeof window.Memory.saveImage === 'function') { - window.Memory.saveImage(imageUrl); - } - } - - if (window.Memory && typeof window.Memory.loadPastImages === 'function') { - window.Memory.loadPastImages(addImageToGallery); - } - - function generateSessionTitle(messages) { + function generateSessionTitle(messages) { let title = ""; for (let i = 0; i < messages.length; i++) { if (messages[i].role === "ai") { @@ -234,20 +205,19 @@ document.addEventListener("DOMContentLoaded", () => { img.style.display = "block"; attachImageButtons(img, imageId); }; - img.onerror = () => { - loadingDiv.innerHTML = "⚠️ Failed to load image"; - loadingDiv.style.display = "flex"; - loadingDiv.style.justifyContent = "center"; - loadingDiv.style.alignItems = "center"; - }; - imageContainer.appendChild(img); - addImageToGallery(url); - const imgButtonContainer = document.createElement("div"); - imgButtonContainer.className = "image-button-container"; - imgButtonContainer.dataset.imageId = imageId; - imageContainer.appendChild(imgButtonContainer); - return imageContainer; - } + img.onerror = () => { + loadingDiv.innerHTML = "⚠️ Failed to load image"; + loadingDiv.style.display = "flex"; + loadingDiv.style.justifyContent = "center"; + loadingDiv.style.alignItems = "center"; + }; + imageContainer.appendChild(img); + const imgButtonContainer = document.createElement("div"); + imgButtonContainer.className = "image-button-container"; + imgButtonContainer.dataset.imageId = imageId; + imageContainer.appendChild(imgButtonContainer); + return imageContainer; + } function attachImageButtons(img, imageId) { const imgButtonContainer = document.querySelector(`.image-button-container[data-image-id="${imageId}"]`); if (!imgButtonContainer) { @@ -621,16 +591,22 @@ document.addEventListener("DOMContentLoaded", () => { sendButton.disabled = true; chatInput.disabled = true; } - chatInput.addEventListener("input", () => { - sendButton.disabled = chatInput.value.trim() === ""; - chatInput.style.height = "auto"; - chatInput.style.height = chatInput.scrollHeight + "px"; - }); - sendButton.addEventListener("click", () => { - handleSendMessage(); - }); - sendButton.disabled = chatInput.value.trim() === ""; - const initialSession = Storage.getCurrentSession(); + chatInput.addEventListener("input", () => { + sendButton.disabled = chatInput.value.trim() === ""; + chatInput.style.height = "auto"; + chatInput.style.height = chatInput.scrollHeight + "px"; + }); + chatInput.addEventListener("keydown", (e) => { + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + handleSendMessage(); + } + }); + sendButton.addEventListener("click", () => { + handleSendMessage(); + }); + sendButton.disabled = chatInput.value.trim() === ""; + const initialSession = Storage.getCurrentSession(); if (initialSession.messages && initialSession.messages.length > 0) { renderStoredMessages(initialSession.messages); } else { diff --git a/index.html b/index.html index de1bee1..2988997 100644 --- a/index.html +++ b/index.html @@ -2,36 +2,20 @@ - Unity AI Lab Chat + Unity Chat UI 0.14.7 - + @@ -370,18 +349,18 @@ 1.0x -
- - - 1.0x -
- - +
+ + + 1.0x +
+ +