From 8c9ac9209904b8df8bb96924c38c7359355325e0 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Tue, 3 Dec 2024 21:32:41 +0800 Subject: [PATCH] fix: errors and missing components, use wildcard for CORS headers --- package.json | 2 +- packages/elevenlabs/package.json | 2 +- packages/llm-proxy/src/index.ts | 15 +- packages/stage/package.json | 4 + packages/stage/src/App.vue | 36 +-- packages/stage/src/auto-imports.d.ts | 2 + packages/stage/src/components/MainStage.vue | 37 +-- packages/stage/src/components/Settings.vue | 31 +++ packages/stage/src/pages/audio.vue | 18 +- packages/stage/src/pages/index.vue | 4 +- packages/stage/src/pages/queue.vue | 4 +- .../stage/src/pages/test/filter-message.vue | 40 ++-- .../stage/src/pages/test/queues/delays.vue | 58 +++-- .../stage/src/pages/test/queues/emotions.vue | 58 +++-- .../stage/src/pages/test/queues/messages.vue | 44 ++-- packages/stage/src/stores/audio.ts | 9 +- packages/stage/src/stores/llm.ts | 28 ++- packages/stage/src/stores/settings.ts | 14 ++ pnpm-lock.yaml | 223 ++++++++++++++++++ 19 files changed, 425 insertions(+), 204 deletions(-) create mode 100644 packages/stage/src/components/Settings.vue create mode 100644 packages/stage/src/stores/settings.ts diff --git a/package.json b/package.json index caa5fb6..9023444 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "typecheck": "pnpm -r --filter=./packages/* run build", "dev": "pnpm packages:dev", "build": "pnpm packages:build", - "packages:dev": "pnpm -r --filter=./packages/* run dev", + "packages:dev": "pnpm -r --filter=./packages/* --parallel run dev", "packages:stub": "pnpm -r --filter=./packages/* run stub", "packages:build": "pnpm -r --filter=./packages/* run build", "test": "vitest --coverage", diff --git a/packages/elevenlabs/package.json b/packages/elevenlabs/package.json index ea1595a..6365bf0 100644 --- a/packages/elevenlabs/package.json +++ b/packages/elevenlabs/package.json @@ -27,7 +27,7 @@ "package.json" ], "scripts": { - "dev": "concurrently \"pnpm run stub\"", + "dev": "pnpm run stub", "stub": "unbuild --stub", "build": "unbuild" }, diff --git a/packages/llm-proxy/src/index.ts b/packages/llm-proxy/src/index.ts index ad0b70e..8c36168 100644 --- a/packages/llm-proxy/src/index.ts +++ b/packages/llm-proxy/src/index.ts @@ -1,5 +1,6 @@ import { ElevenLabsClient } from 'elevenlabs' import { Hono } from 'hono' +import { env } from 'hono/adapter' import { cors } from 'hono/cors' import { stream } from 'hono/streaming' @@ -7,7 +8,7 @@ const app = new Hono() app.use(cors({ origin: '*', - allowHeaders: ['Referer', 'Origin', 'Content-Type', 'Accept', 'Authorization', 'X-Requested-With', 'X-HTTP-Method-Override', 'X-Forwarded-For', 'X-Real-IP'], + allowHeaders: ['*'], allowMethods: ['POST', 'HEAD'], exposeHeaders: ['Content-Type', 'Transfer-Encoding', 'Content-Length', 'Date', 'Server', 'Connection', 'X-Powered-By', 'X-Request-ID'], maxAge: 60 * 60 * 24 * 30, // 30 days @@ -16,11 +17,15 @@ app.use(cors({ app.post('/api/v1/llm/voice/elevenlabs', async (c) => { return stream(c, async (stream) => { const body = await c.req.json() - const apiKey = c.req.header('Authorization') + const apiKeyUnknown = c.req.header('Authorization') - const client = new ElevenLabsClient({ - apiKey: apiKey?.trim().substring('Bearer '.length), - }) + let apiKey = apiKeyUnknown?.trim().substring('Bearer '.length) + const { ELEVENLABS_API_KEY } = env<{ ELEVENLABS_API_KEY?: string }>(c) + if (!apiKey && !!ELEVENLABS_API_KEY) { + apiKey = ELEVENLABS_API_KEY + } + + const client = new ElevenLabsClient({ apiKey }) const res = await client.generate(body) diff --git a/packages/stage/package.json b/packages/stage/package.json index ac024aa..842d798 100644 --- a/packages/stage/package.json +++ b/packages/stage/package.json @@ -32,6 +32,8 @@ "@pixi/sprite": "6", "@pixi/ticker": "^6.5.10", "@pixi/utils": "6", + "@pixiv/three-vrm": "^3.2.0", + "@tresjs/core": "^4.3.1", "@types/yauzl": "^2.10.3", "@unhead/vue": "^1.11.13", "@unocss/reset": "^0.65.0", @@ -46,6 +48,7 @@ "rehype-stringify": "^10.0.1", "remark-parse": "^11.0.0", "remark-rehype": "^11.1.1", + "three": "^0.171.0", "unified": "^11.0.5", "vue": "^3.5.13", "vue-demi": "^0.14.10", @@ -61,6 +64,7 @@ "@shikijs/markdown-it": "^1.24.0", "@types/markdown-it-link-attributes": "^3.0.5", "@types/nprogress": "^0.2.3", + "@types/three": "^0.170.0", "@vitejs/plugin-vue": "^5.2.1", "@vue-macros/volar": "^0.30.6", "markdown-it-link-attributes": "^4.0.1", diff --git a/packages/stage/src/App.vue b/packages/stage/src/App.vue index 009cad0..7c2aa3f 100644 --- a/packages/stage/src/App.vue +++ b/packages/stage/src/App.vue @@ -1,37 +1,3 @@ - - diff --git a/packages/stage/src/auto-imports.d.ts b/packages/stage/src/auto-imports.d.ts index 0369144..769d353 100644 --- a/packages/stage/src/auto-imports.d.ts +++ b/packages/stage/src/auto-imports.d.ts @@ -244,6 +244,7 @@ declare global { const useScrollLock: typeof import('@vueuse/core')['useScrollLock'] const useSeoMeta: typeof import('@vueuse/head')['useSeoMeta'] const useSessionStorage: typeof import('@vueuse/core')['useSessionStorage'] + const useSettings: typeof import('./stores/settings')['useSettings'] const useShare: typeof import('@vueuse/core')['useShare'] const useSlots: typeof import('vue')['useSlots'] const useSorted: typeof import('@vueuse/core')['useSorted'] @@ -550,6 +551,7 @@ declare module 'vue' { readonly useScrollLock: UnwrapRef readonly useSeoMeta: UnwrapRef readonly useSessionStorage: UnwrapRef + readonly useSettings: UnwrapRef readonly useShare: UnwrapRef readonly useSlots: UnwrapRef readonly useSorted: UnwrapRef diff --git a/packages/stage/src/components/MainStage.vue b/packages/stage/src/components/MainStage.vue index beb666d..0c5a30e 100644 --- a/packages/stage/src/components/MainStage.vue +++ b/packages/stage/src/components/MainStage.vue @@ -9,7 +9,9 @@ import type { } from '../constants/emotions' import { useLocalStorage } from '@vueuse/core' +import { storeToRefs } from 'pinia' import { computed, onMounted, ref, watch } from 'vue' + import Avatar from '../assets/live2d/models/hiyori_free_zh/avatar.png' import { useMarkdown } from '../composables/markdown' @@ -26,18 +28,18 @@ import { } from '../constants/emotions' import SystemPromptV2 from '../constants/prompts/system-v2' import { useLLM } from '../stores/llm' +import { useSettings } from '../stores/settings' import BasicTextarea from './BasicTextarea.vue' // import AudioWaveform from './AudioWaveform.vue' import Live2DViewer from './Live2DViewer.vue' +import Settings from './Settings.vue' const nowSpeakingAvatarBorderOpacityMin = 30 const nowSpeakingAvatarBorderOpacityMax = 100 -const openAiApiKey = useLocalStorage('openai-api-key', '') -const openAiApiBaseURL = useLocalStorage('openai-api-base-url', '') +const { elevenLabsApiKey, openAiApiBaseURL, openAiApiKey } = storeToRefs(useSettings()) const openAIModel = useLocalStorage<{ id: string, name?: string }>('openai-model', { id: 'openai/gpt-3.5-turbo', name: 'OpenAI GPT3.5 Turbo' }) -const elevenLabsApiKey = useLocalStorage('elevenlabs-api-key', '') const { setupOpenAI, @@ -270,37 +272,10 @@ onUnmounted(() => {