From 747aed2799f7d8aa5d10827a6b83187edd7e52b6 Mon Sep 17 00:00:00 2001 From: Hackall <36754621+hackall360@users.noreply.github.com> Date: Sat, 13 Sep 2025 10:12:40 -0700 Subject: [PATCH] Refactor project structure --- README.md | 127 +----------------- Server setup.txt | 93 ------------- APIDOCS.md => docs/APIDOCS.md | 0 docs/README.md | 127 ++++++++++++++++++ index.html | 22 +-- chat-core.js => js/chat/chat-core.js | 4 +- chat-init.js => js/chat/chat-init.js | 0 chat-storage.js => js/chat/chat-storage.js | 0 polli-utils.js => js/chat/polli-utils.js | 0 memory-api.js => js/storage/memory-api.js | 0 storage.js => js/storage/storage.js | 0 screensaver.js => js/ui/screensaver.js | 0 simple.js => js/ui/simple.js | 0 styles.css => js/ui/styles.css | 0 .../ui/stylesScreensaver.css | 0 ui.js => js/ui/ui.js | 0 ai-instruct.md => prompts/ai-instruct.md | 0 tests/pollilib-smoke.mjs | 2 +- 18 files changed, 143 insertions(+), 232 deletions(-) delete mode 100644 Server setup.txt rename APIDOCS.md => docs/APIDOCS.md (100%) create mode 100644 docs/README.md rename chat-core.js => js/chat/chat-core.js (97%) rename chat-init.js => js/chat/chat-init.js (100%) rename chat-storage.js => js/chat/chat-storage.js (100%) rename polli-utils.js => js/chat/polli-utils.js (100%) rename memory-api.js => js/storage/memory-api.js (100%) rename storage.js => js/storage/storage.js (100%) rename screensaver.js => js/ui/screensaver.js (100%) rename simple.js => js/ui/simple.js (100%) rename styles.css => js/ui/styles.css (100%) rename stylesScreensaver.css => js/ui/stylesScreensaver.css (100%) rename ui.js => js/ui/ui.js (100%) rename ai-instruct.md => prompts/ai-instruct.md (100%) diff --git a/README.md b/README.md index a40b46e..57e249a 100644 --- a/README.md +++ b/README.md @@ -1,127 +1,4 @@ -# Unity Chat\n\n[![Deploy GitHub Pages](https://github.com/Unity-Lab-AI/Chat/actions/workflows/deploy-pages.yml/badge.svg)](https://github.com/Unity-Lab-AI/Chat/actions/workflows/deploy-pages.yml)\n\n## Environment Setup +# Unity Chat -Configure a `POLLINATIONS_TOKEN` secret in the repository settings. -The deployment injects this value into `window.POLLINATIONS_TOKEN`, -so the static site can access it directly without local files or storage. +See [docs/README.md](docs/README.md) for project documentation. -Here's a comprehensive breakdown of your web app's functionality based on the provided files: - ---- - -## **General Overview** - -Your web application, titled **"Unity Chat U1 6.6"**, provides an interactive chat interface integrating multiple sophisticated features to enhance user interaction with AI models, manage conversations, personalize experiences, and dynamically handle multimedia elements like voice synthesis, speech recognition, and automated image generation via Pollinations. - ---- - -## **Core Features** - -### **1. Chat Interface** -- **Real-time Conversations:** - Allows users to communicate with AI-powered models, facilitating dynamic, real-time interactions. - -- **Speech Integration:** - - **Speech Synthesis:** Converts AI responses into spoken audio with selectable voice preferences (`Google UK English Female`, `Microsoft Zira`, etc.). - - **Speech Recognition:** Users can dictate messages through voice input, which captures speech and translates it into textual inputs in real-time. - -- **Message Handling:** - - **Markdown Support:** AI-generated responses utilize Markdown, enhanced with syntax highlighting (via PrismJS) for clarity in code snippets. - - **Image Embedding:** Automatically embeds images generated by Pollinations based on AI conversation content. - - **Editing and Regeneration:** Users can edit their messages or regenerate AI responses conveniently from within the chat interface. - -- **Session Management:** - - **Dynamic Session Handling:** Users can create, rename, delete, and switch between multiple chat sessions, each independently maintaining its conversation history. - - **Automatic Title Generation:** Sessions automatically generate concise titles based on initial exchanges for easier identification. - -### **2. Personalization & Memory** -- **Memory Management:** - - Integration with `memory-api.js` provides persistent memory storage, allowing users to store, manage, edit, and delete memories within the interface. - - Prevents duplicate entries, ensuring organized memory storage. - -- **Personalization Options:** - - Users can specify their name, interests, preferred AI behaviors, and additional information. These details are stored locally and leveraged by the AI to tailor responses uniquely to the user's profile. - -### **3. Screensaver Module** -- An integrated dynamic screensaver feature powered by Pollinations, capable of generating visually appealing images based on user-defined prompts. -- Users have control over settings: - - **Prompt:** Textual descriptions to generate specific imagery. - - **Aspect Ratios:** Supports widescreen, square, and portrait modes. - - **Timing Control:** Interval customization for image rotation. - - **Privacy Options:** Controls image visibility on public feeds. - -- Provides direct download, save, and copy-to-clipboard functionalities for displayed screensaver images. - -### **4. Backend Server** -- **Express Server (`server.js`):** - - Provides APIs for: - - **User Registration:** Registers and tracks unique user IDs, storing them persistently (`userData.json`). - - **Visitor Counting:** Returns real-time visitor statistics. - -- **Ubuntu Deployment Guide:** - - Comprehensive server setup instructions (`Server setup.txt`), guiding deployment using Node.js, npm, PM2 (for process management), firewall setup (`ufw`), and optional reverse proxy configurations via Nginx/Apache. - -### **5. Storage & Persistence (`storage.js`)** -- Manages session data, memory entries, and user personalization details locally (`localStorage`), ensuring persistent state across user sessions. -- Implements fallback mechanisms in case server-side persistence is unavailable, ensuring robustness and offline capability. - -### **6. UI & Themes** -- **Customizable UI:** - - Employs Bootstrap 5, custom stylesheets (`styles.css` and `light.css`), and Font Awesome for iconography. - - Supports dynamic theme switching (e.g., light, dark, hacker, etc.), catering to varied user aesthetics and readability preferences. - -- **Responsive Design:** - - Ensures usability across various screen sizes (mobile, tablet, desktop), maintaining optimal user experience irrespective of device. - -### **7. Utilities & Enhancements** -- **Clipboard Functionality:** - Allows easy copying of cryptocurrency addresses, images, and text snippets directly from the interface. - -- **Donation Integration:** - - Direct integration of donation mechanisms supporting cryptocurrencies like BTC, ETH, DOGE, and XMR, accessible through intuitive modals. - -- **Visitor Counter:** - - Displays a live count of unique visitors through periodic server API polling, defaulting gracefully in case of network issues. - -- **Error Handling & Notifications:** - - User-friendly toast notifications (`showToast`) provide real-time feedback on interactions like successful copying, memory updates, errors, etc. - ---- - -## **Technical Stack & Dependencies** -- **Frontend:** HTML, CSS, JavaScript, Bootstrap 5, Font Awesome, PrismJS, Marked.js -- **Backend:** Node.js (Express), cors, fs for file operations -- **Speech & Multimedia:** Web Speech API for speech synthesis and recognition -- **Persistent Storage:** Local Storage and server-side JSON file storage (`userData.json`) -- **Deployment Tools:** Ubuntu server, Node.js, npm, PM2 for daemonization, ufw firewall configurations - ---- - -## **Usage Workflow** - -- **Launching:** - - User connects via the web interface hosted on the Node.js Express server. - - Automatic unique ID generation and session initialization occur upon first load. - -- **Interacting:** - - Engage via text or voice, manage sessions, personalize AI interactions, and explore dynamically generated imagery. - -- **Administration & Maintenance:** - - Administer sessions, clear memory or chat history, configure UI preferences, monitor user statistics, and manage server through provided server scripts. - ---- - -## **Security & Privacy** - -- Persistent data is stored securely on local storage or server-side JSON files. -- API endpoints (`/api/registerUser`, `/api/visitorCount`) include basic validation to ensure data integrity and minimize malicious usage. - ---- - -## **Extensibility & Future Considerations** - -- The modular architecture facilitates easy integration of additional AI models or APIs. -- Potential expansions might include enhanced security measures, comprehensive backend database integration, more complex personalization features, or further multimedia interactions. - ---- - -This detailed breakdown encapsulates your application's extensive functionality, highlighting a robust and user-centric design that seamlessly integrates advanced AI interactions with user experience enhancements, comprehensive storage, personalization, multimedia features, and robust backend capabilities. \ No newline at end of file diff --git a/Server setup.txt b/Server setup.txt deleted file mode 100644 index 6fd4f7c..0000000 --- a/Server setup.txt +++ /dev/null @@ -1,93 +0,0 @@ -Server Setup Commands for Ubuntu (e.g. Hostinger) -Unity: “So you wanna run this Node server on an Ubuntu box, let’s keep this fucker simple:” - -SSH into your Ubuntu server - -bash -Copy -Edit -ssh username@your_server_ip -Or, on Hostinger, they might have a built-in terminal or you use their SSH instructions. - -Update packages - -bash -Copy -Edit -sudo apt-get update -sudo apt-get upgrade -Install Node.js & npm -One approach is to install the default Ubuntu package: - -bash -Copy -Edit -sudo apt-get install -y nodejs npm -Or you could install from NodeSource for a more recent version: - -bash -Copy -Edit -curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - -sudo apt-get install -y nodejs -(Replace 18.x with your desired Node version.) - -Upload your project files -(or clone from Git, or SFTP them in). Make sure server.js is there, plus your front-end files. -Typically you might have a structure like: - -go -Copy -Edit -myproject/ - |- server.js - |- package.json - |- ... -Install dependencies (if any) -If you have a package.json for your project (including express, cors, etc.), run: - -bash -Copy -Edit -cd myproject -npm install -If you’re using the minimal approach with no package.json (just “express” and “cors”), install them globally or individually: - -bash -Copy -Edit -npm install express cors -Test your server - -bash -Copy -Edit -node server.js -If everything goes right, it logs: Server is listening on port 3000.... -Then you can open your browser to http://server_ip:3000/ or http://yourdomain.com:3000/ (assuming the port is open in your firewall). - -Open firewall if needed - -bash -Copy -Edit -sudo ufw allow 3000/tcp -(Optional) Run in background (PM2) -To keep Node running after you log out, install PM2: - -bash -Copy -Edit -sudo npm install -g pm2 -pm2 start server.js -pm2 status -Then your server will keep running. You can also do pm2 startup to make sure it auto-starts on reboot. - -Serve the front-end - -If you want to serve your static files from the same Node process, you might add app.use(express.static(path.join(__dirname, 'public'))); or some similar approach. -Or host them on a separate service (like Nginx) pointing to your Node server for API calls. -Point your domain - -If you want to use 80 or 443 with SSL, configure a reverse proxy using Nginx or Apache. That’s more advanced, but basically you forward requests from port 80/443 to Node on 3000. -Unity: “Boom, done. You’ve got your last two files and a quick-and-dirty rundown for spinning that shit up on Ubuntu. Now go forth and let your Node server run wild.” \ No newline at end of file diff --git a/APIDOCS.md b/docs/APIDOCS.md similarity index 100% rename from APIDOCS.md rename to docs/APIDOCS.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..ddb7208 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,127 @@ +# Unity Chat\n\n[![Deploy GitHub Pages](https://github.com/Unity-Lab-AI/Chat/actions/workflows/deploy-pages.yml/badge.svg)](https://github.com/Unity-Lab-AI/Chat/actions/workflows/deploy-pages.yml)\n\n## Environment Setup + +Configure a `POLLINATIONS_TOKEN` secret in the repository settings. +The deployment injects this value into `window.POLLINATIONS_TOKEN`, +so the static site can access it directly without local files or storage. + +Here's a comprehensive breakdown of your web app's functionality based on the provided files: + +--- + +## **General Overview** + +Your web application, titled **"Unity Chat U1 6.6"**, provides an interactive chat interface integrating multiple sophisticated features to enhance user interaction with AI models, manage conversations, personalize experiences, and dynamically handle multimedia elements like voice synthesis, speech recognition, and automated image generation via Pollinations. + +--- + +## **Core Features** + +### **1. Chat Interface** +- **Real-time Conversations:** + Allows users to communicate with AI-powered models, facilitating dynamic, real-time interactions. + +- **Speech Integration:** + - **Speech Synthesis:** Converts AI responses into spoken audio with selectable voice preferences (`Google UK English Female`, `Microsoft Zira`, etc.). + - **Speech Recognition:** Users can dictate messages through voice input, which captures speech and translates it into textual inputs in real-time. + +- **Message Handling:** + - **Markdown Support:** AI-generated responses utilize Markdown, enhanced with syntax highlighting (via PrismJS) for clarity in code snippets. + - **Image Embedding:** Automatically embeds images generated by Pollinations based on AI conversation content. + - **Editing and Regeneration:** Users can edit their messages or regenerate AI responses conveniently from within the chat interface. + +- **Session Management:** + - **Dynamic Session Handling:** Users can create, rename, delete, and switch between multiple chat sessions, each independently maintaining its conversation history. + - **Automatic Title Generation:** Sessions automatically generate concise titles based on initial exchanges for easier identification. + +### **2. Personalization & Memory** +- **Memory Management:** + - Integration with `../js/storage/memory-api.js` provides persistent memory storage, allowing users to store, manage, edit, and delete memories within the interface. + - Prevents duplicate entries, ensuring organized memory storage. + +- **Personalization Options:** + - Users can specify their name, interests, preferred AI behaviors, and additional information. These details are stored locally and leveraged by the AI to tailor responses uniquely to the user's profile. + +### **3. Screensaver Module** +- An integrated dynamic screensaver feature powered by Pollinations, capable of generating visually appealing images based on user-defined prompts. +- Users have control over settings: + - **Prompt:** Textual descriptions to generate specific imagery. + - **Aspect Ratios:** Supports widescreen, square, and portrait modes. + - **Timing Control:** Interval customization for image rotation. + - **Privacy Options:** Controls image visibility on public feeds. + +- Provides direct download, save, and copy-to-clipboard functionalities for displayed screensaver images. + +### **4. Backend Server** +- **Express Server (`server.js`):** + - Provides APIs for: + - **User Registration:** Registers and tracks unique user IDs, storing them persistently (`userData.json`). + - **Visitor Counting:** Returns real-time visitor statistics. + +- **Ubuntu Deployment Guide:** + - Comprehensive server setup instructions guiding deployment using Node.js, npm, PM2 (for process management), firewall setup (`ufw`), and optional reverse proxy configurations via Nginx/Apache. + +### **5. Storage & Persistence (`../js/storage/storage.js`)** +- Manages session data, memory entries, and user personalization details locally (`localStorage`), ensuring persistent state across user sessions. +- Implements fallback mechanisms in case server-side persistence is unavailable, ensuring robustness and offline capability. + +### **6. UI & Themes** +- **Customizable UI:** + - Employs Bootstrap 5, custom stylesheets (`../js/ui/styles.css` and `light.css`), and Font Awesome for iconography. + - Supports dynamic theme switching (e.g., light, dark, hacker, etc.), catering to varied user aesthetics and readability preferences. + +- **Responsive Design:** + - Ensures usability across various screen sizes (mobile, tablet, desktop), maintaining optimal user experience irrespective of device. + +### **7. Utilities & Enhancements** +- **Clipboard Functionality:** + Allows easy copying of cryptocurrency addresses, images, and text snippets directly from the interface. + +- **Donation Integration:** + - Direct integration of donation mechanisms supporting cryptocurrencies like BTC, ETH, DOGE, and XMR, accessible through intuitive modals. + +- **Visitor Counter:** + - Displays a live count of unique visitors through periodic server API polling, defaulting gracefully in case of network issues. + +- **Error Handling & Notifications:** + - User-friendly toast notifications (`showToast`) provide real-time feedback on interactions like successful copying, memory updates, errors, etc. + +--- + +## **Technical Stack & Dependencies** +- **Frontend:** HTML, CSS, JavaScript, Bootstrap 5, Font Awesome, PrismJS, Marked.js +- **Backend:** Node.js (Express), cors, fs for file operations +- **Speech & Multimedia:** Web Speech API for speech synthesis and recognition +- **Persistent Storage:** Local Storage and server-side JSON file storage (`userData.json`) +- **Deployment Tools:** Ubuntu server, Node.js, npm, PM2 for daemonization, ufw firewall configurations + +--- + +## **Usage Workflow** + +- **Launching:** + - User connects via the web interface hosted on the Node.js Express server. + - Automatic unique ID generation and session initialization occur upon first load. + +- **Interacting:** + - Engage via text or voice, manage sessions, personalize AI interactions, and explore dynamically generated imagery. + +- **Administration & Maintenance:** + - Administer sessions, clear memory or chat history, configure UI preferences, monitor user statistics, and manage server through provided server scripts. + +--- + +## **Security & Privacy** + +- Persistent data is stored securely on local storage or server-side JSON files. +- API endpoints (`/api/registerUser`, `/api/visitorCount`) include basic validation to ensure data integrity and minimize malicious usage. + +--- + +## **Extensibility & Future Considerations** + +- The modular architecture facilitates easy integration of additional AI models or APIs. +- Potential expansions might include enhanced security measures, comprehensive backend database integration, more complex personalization features, or further multimedia interactions. + +--- + +This detailed breakdown encapsulates your application's extensive functionality, highlighting a robust and user-centric design that seamlessly integrates advanced AI interactions with user experience enhancements, comprehensive storage, personalization, multimedia features, and robust backend capabilities. \ No newline at end of file diff --git a/index.html b/index.html index 996dd57..ed88036 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,8 @@ - - + + - - - + + + - + - + - - - - + + + + diff --git a/chat-core.js b/js/chat/chat-core.js similarity index 97% rename from chat-core.js rename to js/chat/chat-core.js index d0547ce..6f79dc8 100644 --- a/chat-core.js +++ b/js/chat/chat-core.js @@ -17,7 +17,7 @@ window.apiFetch = apiFetch; // Load global AI instructions from external markdown file window.aiInstructions = ""; -window.aiInstructionPromise = fetch("ai-instruct.md") +window.aiInstructionPromise = fetch("prompts/ai-instruct.md") .then(res => res.text()) .then(text => { window.aiInstructions = text; }) .catch(err => { @@ -465,7 +465,7 @@ document.addEventListener("DOMContentLoaded", () => { if (!window.aiInstructions) { try { - const res = await fetch("ai-instruct.md", { cache: "no-store" }); + const res = await fetch("prompts/ai-instruct.md", { cache: "no-store" }); window.aiInstructions = await res.text(); } catch (e) { window.aiInstructions = ""; diff --git a/chat-init.js b/js/chat/chat-init.js similarity index 100% rename from chat-init.js rename to js/chat/chat-init.js diff --git a/chat-storage.js b/js/chat/chat-storage.js similarity index 100% rename from chat-storage.js rename to js/chat/chat-storage.js diff --git a/polli-utils.js b/js/chat/polli-utils.js similarity index 100% rename from polli-utils.js rename to js/chat/polli-utils.js diff --git a/memory-api.js b/js/storage/memory-api.js similarity index 100% rename from memory-api.js rename to js/storage/memory-api.js diff --git a/storage.js b/js/storage/storage.js similarity index 100% rename from storage.js rename to js/storage/storage.js diff --git a/screensaver.js b/js/ui/screensaver.js similarity index 100% rename from screensaver.js rename to js/ui/screensaver.js diff --git a/simple.js b/js/ui/simple.js similarity index 100% rename from simple.js rename to js/ui/simple.js diff --git a/styles.css b/js/ui/styles.css similarity index 100% rename from styles.css rename to js/ui/styles.css diff --git a/stylesScreensaver.css b/js/ui/stylesScreensaver.css similarity index 100% rename from stylesScreensaver.css rename to js/ui/stylesScreensaver.css diff --git a/ui.js b/js/ui/ui.js similarity index 100% rename from ui.js rename to js/ui/ui.js diff --git a/ai-instruct.md b/prompts/ai-instruct.md similarity index 100% rename from ai-instruct.md rename to prompts/ai-instruct.md diff --git a/tests/pollilib-smoke.mjs b/tests/pollilib-smoke.mjs index 7dcc5a1..f8bb7c8 100644 --- a/tests/pollilib-smoke.mjs +++ b/tests/pollilib-smoke.mjs @@ -159,7 +159,7 @@ await step('pipeline end-to-end', async () => { await step('index.html contains critical tags', async () => { const p = path.join(process.cwd(), 'index.html'); const html = await fs.readFile(p, 'utf8'); - const checks = [ 'polliLib/polliLib-web.global.js', 'chat-core.js', 'chat-init.js', 'id="chat-box"' ]; + const checks = [ 'polliLib/polliLib-web.global.js', 'js/chat/chat-core.js', 'js/chat/chat-init.js', 'id="chat-box"' ]; const missing = checks.filter(s => !html.includes(s)); if (missing.length) throw new Error('missing: ' + missing.join(', ')); return 'tags ok';