From 5bbd602a99f86afb97a787de0da9127cf5f58e39 Mon Sep 17 00:00:00 2001 From: NikkeDoy Date: Mon, 18 May 2026 21:44:35 +0300 Subject: [PATCH] =?UTF-8?q?:=F0=9F=92=A9:=20|=20GPT=20->=20gpt-unslother?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 139 +-- README.md | 12 +- docs/NGINX-STATIC-HOSTING.md | 211 ++++ lune.config.js | 17 + package.json | 8 + plugins/gpt-unslothed/index.jsx | 253 +++++ plugins/gpt-unslothed/plugin.json | 5 + plugins/gpt-unslothed/settings.jsx | 27 + pnpm-lock.yaml | 1518 ++++++++++++++++++++++++++++ pnpm-workspace.yaml | 2 + previews/gpt.png | Bin 0 -> 15218 bytes 11 files changed, 2054 insertions(+), 138 deletions(-) create mode 100644 docs/NGINX-STATIC-HOSTING.md create mode 100644 lune.config.js create mode 100644 package.json create mode 100644 plugins/gpt-unslothed/index.jsx create mode 100644 plugins/gpt-unslothed/plugin.json create mode 100644 plugins/gpt-unslothed/settings.jsx create mode 100644 pnpm-lock.yaml create mode 100644 pnpm-workspace.yaml create mode 100644 previews/gpt.png diff --git a/.gitignore b/.gitignore index 2309cc8..5a670e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,138 +1,3 @@ -# ---> Node -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp -.cache - -# vitepress build output -**/.vitepress/dist - -# vitepress cache directory -**/.vitepress/cache - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - +.DS_Store +dist/ diff --git a/README.md b/README.md index b95e7e0..8e23b62 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # shelter-plugins -ORIGINAL: https://github.com/edde746/shelter-plugins \ No newline at end of file +> **Note:** This repository is a fork of [edde746/shelter-plugins](https://github.com/edde746/shelter-plugins). + +## Self-Hosting + +These plugins can be hosted on your own server using NGINX. See the [NGINX Static Hosting Guide](docs/NGINX-STATIC-HOSTING.md) for setup instructions. + +## gpt-unslothed + +Use local language models via Unsloth Studio API to generate responses based on recent messages in the channel and a prompt. + +![GPT Unslothed Plugin Showcase](/previews/gpt.png) diff --git a/docs/NGINX-STATIC-HOSTING.md b/docs/NGINX-STATIC-HOSTING.md new file mode 100644 index 0000000..9051409 --- /dev/null +++ b/docs/NGINX-STATIC-HOSTING.md @@ -0,0 +1,211 @@ +# Hosting Shelter Plugins with NGINX + +This guide walks you through hosting the built plugin files using NGINX on your own server. + +## Prerequisites + +- A server running NGINX +- Access to the server via SSH +- Basic familiarity with Linux command line + +## Step 1: Prepare the Plugin Files + +First, build the plugins locally using Lune: + +```bash +# Install pnpm if you haven't already +npm install -g pnpm + +# Install dependencies +pnpm install + +# Build the plugins +pnpm lune ci +``` + +This creates the built plugin files in the `dist/` directory (e.g., `dist/gpt/plugin.js`, `dist/gpt/plugin.json`). + +## Step 2: Set Up the Web Directory + +Create a directory for the static files: + +```bash +# Create the directory (you can change the path as needed) +sudo mkdir -p /var/www/shelter-plugins + +# Copy the built files +sudo cp -r dist/* /var/www/shelter-plugins/ +``` + +## Step 3: Configure NGINX + +Create a new NGINX configuration file: + +```bash +sudo nano /etc/nginx/sites-available/shelter-plugins +``` + +Add the following configuration: + +```nginx +server { + listen 80; + server_name plugins.your-domain.com; # Change to your domain + + root /var/www/shelter-plugins; + index index.html; + + # Serve plugin files + location /gpt-unslothed { + default_type application/json; + try_files $uri $uri/ =404; + } + + # Serve preview images + location /previews { + default_type image/png; + try_files $uri $uri/ =404; + } + + # Serve README + location /README.md { + default_type text/markdown; + try_files $uri =404; + } + + # Catch-all for 404 + location = /404.html { + internal; + } + + # Redirect all other requests to 404 + location / { + return 404; + } +} +``` + +### Configuration Notes + +- Change `plugins.your-domain.com` to your actual domain or IP address +- The `default_type application/json` ensures browsers don't try to execute the plugin files +- The configuration serves plugins from paths like `http://plugins.your-domain.com/gpt-unslothed/` + +## Step 4: Enable the Site + +```bash +# Enable the site +sudo ln -s /etc/nginx/sites-available/shelter-plugins /etc/nginx/sites-enabled/ + +# Test the configuration +sudo nginx -t + +# Reload NGINX +sudo systemctl reload nginx +``` + +## Step 5: Use in Shelter + +In Shelter, add the plugin using the URL: + +``` +http://plugins.your-domain.com/gpt-unslothed/plugin.json +``` + +Or if using HTTPS (recommended): + +``` +https://plugins.your-domain.com/gpt-unslothed/plugin.json +``` + +## Optional: Set Up HTTPS with Let's Encrypt + +Install Certbot and get an SSL certificate: + +```bash +# Install Certbot (Ubuntu/Debian) +sudo apt update +sudo apt install certbot python3-certbot-nginx + +# Get the certificate +sudo certbot --nginx -d plugins.your-domain.com +``` + +Certbot will automatically update your NGINX configuration to use HTTPS. + +## Automation: Deploying Updates + +To make updates easier, you can create a simple deployment script: + +```bash +#!/bin/bash +# deploy.sh + +set -e + +# Build plugins +echo "Building plugins..." +pnpm lune ci + +# Copy files +echo "Copying files to web directory..." +sudo rsync -av --delete dist/ /var/www/shelter-plugins/ + +# Reload NGINX (optional) +# sudo systemctl reload nginx + +echo "Deployment complete!" +``` + +Make it executable and run it when you want to deploy: + +```bash +chmod +x deploy.sh +./deploy.sh +``` + +## File Structure + +After deployment, your server should look like this: + +``` +/var/www/shelter-plugins/ +├── gpt-unslothed/ +│ ├── plugin.json +│ ├── index.jsx +│ └── settings.jsx +└── previews/ + └── gpt.png +``` + +## Troubleshooting + +### 404 Not Found + +- Ensure the `dist/` directory contents were copied correctly +- Check that your NGINX site is enabled: `ls /etc/nginx/sites-enabled/` +- Check NGINX error logs: `sudo tail -f /var/log/nginx/error.log` + +### Plugin not loading in Shelter + +- Make sure the URL points to `plugin.json`, not the directory +- Check browser console for CORS errors (may need to add CORS headers) + +### Adding CORS headers + +If Shelter is experiencing CORS issues, add these headers to your NGINX config: + +```nginx +location / { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Content-Type'; + + if ($request_method = 'OPTIONS') { + return 204; + } + + default_type application/json; + try_files $uri $uri/ =404; +} +``` diff --git a/lune.config.js b/lune.config.js new file mode 100644 index 0000000..210a301 --- /dev/null +++ b/lune.config.js @@ -0,0 +1,17 @@ +// Welcome to your Lune config file! +// You can view documentation on Lune here: +// https://github.com/uwu/shelter/tree/main/packages/lune +// uncomment lines below to enable options, and feel free to delete this header. +import { defineConfig } from "@uwu/lune"; + +export default defineConfig({ + // this is the directory that your plugins live in. + // repoSubDir: "plugins-live-in-here", + + // this enables CSS Module support - see docs for info + // cssModules: true, + + // these add extra esbuild plugins into the pipeline. + // prePlugins: [], + // postPlugins: [], +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..0b5136c --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "devDependencies": { + "@uwu/lune": "^1.2.1", + "@uwu/shelter-defs": "^1.1.0" + }, + "type": "module", + "workspaces": ["plugins/*"] +} diff --git a/plugins/gpt-unslothed/index.jsx b/plugins/gpt-unslothed/index.jsx new file mode 100644 index 0000000..d177bcf --- /dev/null +++ b/plugins/gpt-unslothed/index.jsx @@ -0,0 +1,253 @@ +const { + observeDom, + ui: { + injectCss, + Button, + openModal, + ModalRoot, + ModalHeader, + ModalBody, + ModalFooter, + ModalSizes, + Text, + TextBox, + ReactiveRoot, + TextArea, + ButtonLooks, + }, + plugin: { store }, + util: { getFiber }, +} = shelter; + +let popupButton = null; +let unobserve = null; + +const getMessageHistory = () => { + const messageElements = document.querySelectorAll('div[class^="message-"]'); + + const messages = [...messageElements].map((message) => ({ + username: message.querySelector("h3 > span > span")?.textContent, + message: message.querySelector("div > div > div").textContent, + })); + + return messages.reduce((acc, message) => { + if (message.username) { + acc.push(message); + } else { + acc[acc.length - 1].message += `\n${message.message}`; + } + return acc; + }, []); +}; + +const loadingIndicator = () => ( + + + + + + +); + +// Credits to yellowsink for this messagebar stuff +// https://github.com/yellowsink +const appendTextToMessagebar = (text) => { + const elem = document.querySelector('[class*="slateContainer"]'); + const fiber = getFiber(elem); + const editor = fiber.child.pendingProps.editor; + + editor.insertText(text); +}; + +export function onLoad() { + injectCss(` + .label-spacing { + margin-bottom: .125rem; + } + .mb-2 { + margin-bottom: .5rem; + } + + .pr-2 { + padding-right: .5rem; + }`); + + let closeModal = null; + const openGenerationModal = async () => { + let savedModel = store.model || ""; + + let model = savedModel; + let prompt = ""; + closeModal = openModal((p) => ( + + closeModal()}>Generate Response + +
+
+
+ Model +
+ { + model = e; + }} + /> +
+
+ Prompt +
+