From ee5ce669d5a8693a249de4aba4d74aa04c596ba2 Mon Sep 17 00:00:00 2001 From: losfair Date: Wed, 14 Feb 2024 15:59:27 +0800 Subject: [PATCH] squash --- .github/workflows/ci.yml | 33 ++ .gitignore | 11 + .vscode/extensions.json | 6 + .vscode/settings.json | 20 + .vscode/tailwind.json | 60 +++ README.md | 4 +- components/Button.tsx | 12 + deno.json | 40 ++ dev.ts | 8 + fresh.config.ts | 6 + fresh.gen.ts | 42 ++ islands/ChatContent.tsx | 361 ++++++++++++++++++ islands/ChatUI.tsx | 60 +++ islands/Counter.tsx | 16 + islands/Sidebar.tsx | 104 +++++ lib/fetch.ts | 24 ++ lib/kv.ts | 1 + lib/markdown.ts | 9 + lib/oai.ts | 96 +++++ lib/workspace.ts | 75 ++++ main.ts | 14 + routes/_404.tsx | 27 ++ routes/_app.tsx | 17 + routes/api/workspace/[workspaceId]/chat.ts | 25 ++ .../workspace/[workspaceId]/chats/[chatId].ts | 266 +++++++++++++ .../[workspaceId]/messages/[messageId].ts | 43 +++ routes/index.tsx | 25 ++ routes/workspace/[workspaceId].tsx | 42 ++ routes/workspace/index.tsx | 44 +++ static/favicon.ico | Bin 0 -> 22382 bytes static/logo.svg | 6 + static/styles.css | 3 + tailwind.config.ts | 11 + 33 files changed, 1510 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tailwind.json create mode 100644 components/Button.tsx create mode 100644 deno.json create mode 100755 dev.ts create mode 100644 fresh.config.ts create mode 100644 fresh.gen.ts create mode 100644 islands/ChatContent.tsx create mode 100644 islands/ChatUI.tsx create mode 100644 islands/Counter.tsx create mode 100644 islands/Sidebar.tsx create mode 100644 lib/fetch.ts create mode 100644 lib/kv.ts create mode 100644 lib/markdown.ts create mode 100644 lib/oai.ts create mode 100644 lib/workspace.ts create mode 100644 main.ts create mode 100644 routes/_404.tsx create mode 100644 routes/_app.tsx create mode 100644 routes/api/workspace/[workspaceId]/chat.ts create mode 100644 routes/api/workspace/[workspaceId]/chats/[chatId].ts create mode 100644 routes/api/workspace/[workspaceId]/messages/[messageId].ts create mode 100644 routes/index.tsx create mode 100644 routes/workspace/[workspaceId].tsx create mode 100644 routes/workspace/index.tsx create mode 100644 static/favicon.ico create mode 100644 static/logo.svg create mode 100644 static/styles.css create mode 100644 tailwind.config.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..afd4c0d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: Deploy +on: + push: + branches: [main] + pull_request: + branches: main + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + permissions: + id-token: write + contents: read + + steps: + - name: Clone repository + uses: actions/checkout@v3 + + - name: Install Deno + uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + + - name: Build step + run: "OPENAI_API_KEY=dummy deno task build" + + - name: Upload to Deno Deploy + uses: denoland/deployctl@v1 + with: + project: "chatspace" + entrypoint: "./main.ts" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b4bdef --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# Fresh build directory +_fresh/ +# npm dependencies +node_modules/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..455f9fc --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "denoland.vscode-deno", + "bradlc.vscode-tailwindcss" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bedf1ce --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,20 @@ +{ + "deno.enable": true, + "deno.lint": true, + "editor.defaultFormatter": "denoland.vscode-deno", + "[typescriptreact]": { + "editor.defaultFormatter": "denoland.vscode-deno" + }, + "[typescript]": { + "editor.defaultFormatter": "denoland.vscode-deno" + }, + "[javascriptreact]": { + "editor.defaultFormatter": "denoland.vscode-deno" + }, + "[javascript]": { + "editor.defaultFormatter": "denoland.vscode-deno" + }, + "css.customData": [ + ".vscode/tailwind.json" + ] +} diff --git a/.vscode/tailwind.json b/.vscode/tailwind.json new file mode 100644 index 0000000..af7991c --- /dev/null +++ b/.vscode/tailwind.json @@ -0,0 +1,60 @@ +{ + "version": 1.1, + "atDirectives": [ + { + "name": "@tailwind", + "description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#tailwind" + } + ] + }, + { + "name": "@apply", + "description": "Use the `@apply` directive to inline any existing utility classes into your own custom CSS. This is useful when you find a common utility pattern in your HTML that you’d like to extract to a new component.", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#apply" + } + ] + }, + { + "name": "@responsive", + "description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css +@responsive {\n .alert { + background-color: #E53E3E;\n }\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#responsive" + } + ] + }, + { + "name": "@screen", + "description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css +@screen sm {\n /* ... */\n}\n```\n…gets transformed into this:\n```css +@media (min-width: 640px) {\n /* ... */\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#screen" + } + ] + }, + { + "name": "@variants", + "description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css +@variants hover, focus {\n .btn-brand {\n background-color: #3182CE;\n }\n}\n```\n", + "references": [ + { + "name": "Tailwind Documentation", + "url": "https://tailwindcss.com/docs/functions-and-directives#variants" + } + ] + } + ] +} diff --git a/README.md b/README.md index 9f83154..b4ad959 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# chatspace \ No newline at end of file +# Chatspace + +Real-time, collaborative GPT frontend built with Deno KV. diff --git a/components/Button.tsx b/components/Button.tsx new file mode 100644 index 0000000..f1b80a0 --- /dev/null +++ b/components/Button.tsx @@ -0,0 +1,12 @@ +import { JSX } from "preact"; +import { IS_BROWSER } from "$fresh/runtime.ts"; + +export function Button(props: JSX.HTMLAttributes) { + return ( +