From d172d8034a96c7df3dc4fa7a54e5dcf6ed1241cf Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Fri, 18 Aug 2023 03:30:41 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 + README.md | 7 + lune.config.js | 17 + package.json | 8 + plugins/gpt/index.jsx | 210 ++++++++++ plugins/gpt/plugin.json | 5 + pnpm-lock.yaml | 820 ++++++++++++++++++++++++++++++++++++++++ pnpm-workspace.yaml | 2 + 8 files changed, 1071 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 lune.config.js create mode 100644 package.json create mode 100644 plugins/gpt/index.jsx create mode 100644 plugins/gpt/plugin.json create mode 100644 pnpm-lock.yaml create mode 100644 pnpm-workspace.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2752eb9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..351d553 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# gpt-shelter-plugin + +A shelter plugin for [shelter](https://github.com/uwu/shelter). The code is terrible, but I believe there is no better way to achieve this. + +## Usage + +TODO 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/index.jsx b/plugins/gpt/index.jsx new file mode 100644 index 0000000..9af2fa9 --- /dev/null +++ b/plugins/gpt/index.jsx @@ -0,0 +1,210 @@ +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; + }, []); +}; + +// 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 hasValidKey = store.openaiKey?.startsWith("sk-"); + let savedModel = store.model || "gpt-3.5-turbo"; + + let model = savedModel; + let prompt = ""; + closeModal = openModal((p) => ( + + closeModal()}>Generate Response + +
+
+
+ Model +
+ { + model = e; + }} + /> +
+
+ Prompt +
+