From cfd0c9532fc7286a58db08e245b46729ba2c3694 Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 10 Jun 2023 14:04:40 +0800 Subject: [PATCH] feat: lint code --- .eslintrc.json | 2 +- .gitignore | 1 + .vscode/launch.json | 2 +- .vscode/settings.json | 2 +- app/api/chat-messages/route.ts | 8 +-- app/api/conversations/route.ts | 10 +-- .../messages/[messageId]/feedbacks/route.ts | 6 +- app/api/messages/route.ts | 12 ++-- app/api/parameters/route.ts | 10 +-- app/api/utils/common.ts | 12 ++-- app/api/utils/stream.ts | 20 +++--- app/components/app-unavailable.tsx | 3 +- .../base/auto-height-textarea/index.tsx | 1 + app/components/base/markdown.tsx | 2 +- app/components/chat/index.tsx | 27 +++---- app/components/chat/loading-anim/index.tsx | 7 +- app/components/index.tsx | 15 ++-- app/components/welcome/index.tsx | 4 +- config/index.ts | 14 ++-- hooks/use-breakpoints.ts | 24 ++++--- hooks/use-conversation.ts | 13 ++-- i18n/client.ts | 3 +- i18n/i18next-config.ts | 2 +- i18n/i18next-serverside-config.ts | 6 +- i18n/lang/app.en.ts | 40 +++++------ i18n/lang/app.zh.ts | 40 +++++------ i18n/lang/common.en.ts | 2 +- i18n/lang/common.zh.ts | 2 +- next.config.js | 2 +- package.json | 19 +++-- service/vercel.json | 2 +- tailwind.config.js | 10 +-- tsconfig.json | 2 +- types/app.ts | 29 ++++---- typography.js | 70 +++++++++---------- utils/prompt.ts | 12 ++-- 36 files changed, 226 insertions(+), 210 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9d8ea2c..631cb2b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,4 +25,4 @@ ], "react-hooks/exhaustive-deps": "warn" } -} \ No newline at end of file +} diff --git a/.gitignore b/.gitignore index 2c01328..837200e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ # misc .DS_Store +.vscode *.pem # debug diff --git a/.vscode/launch.json b/.vscode/launch.json index 9e36291..2a80d06 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,4 +25,4 @@ } } ] -} \ No newline at end of file +} diff --git a/.vscode/settings.json b/.vscode/settings.json index e35fdc6..45d5fcf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,4 +29,4 @@ "i18n/lang", "app/api/messages" ] -} \ No newline at end of file +} diff --git a/app/api/chat-messages/route.ts b/app/api/chat-messages/route.ts index a046f95..88d6f81 100644 --- a/app/api/chat-messages/route.ts +++ b/app/api/chat-messages/route.ts @@ -1,5 +1,5 @@ import { type NextRequest } from 'next/server' -import { getInfo, client } from '@/app/api/utils/common' +import { client, getInfo } from '@/app/api/utils/common' import { OpenAIStream } from '@/app/api/utils/stream' export async function POST(request: NextRequest) { @@ -8,10 +8,10 @@ export async function POST(request: NextRequest) { inputs, query, conversation_id: conversationId, - response_mode: responseMode + response_mode: responseMode, } = body - const { user } = getInfo(request); + const { user } = getInfo(request) const res = await client.createChatMessage(inputs, query, user, responseMode, conversationId) const stream = await OpenAIStream(res as any) return new Response(stream as any) -} \ No newline at end of file +} diff --git a/app/api/conversations/route.ts b/app/api/conversations/route.ts index 9a73a3d..eef0555 100644 --- a/app/api/conversations/route.ts +++ b/app/api/conversations/route.ts @@ -1,11 +1,11 @@ import { type NextRequest } from 'next/server' import { NextResponse } from 'next/server' -import { getInfo, setSession, client } from '@/app/api/utils/common' +import { client, getInfo, setSession } from '@/app/api/utils/common' export async function GET(request: NextRequest) { - const { sessionId, user } = getInfo(request); - const { data }: any = await client.getConversations(user); + const { sessionId, user } = getInfo(request) + const { data }: any = await client.getConversations(user) return NextResponse.json(data, { - headers: setSession(sessionId) + headers: setSession(sessionId), }) -} \ No newline at end of file +} diff --git a/app/api/messages/[messageId]/feedbacks/route.ts b/app/api/messages/[messageId]/feedbacks/route.ts index f41a136..c701e15 100644 --- a/app/api/messages/[messageId]/feedbacks/route.ts +++ b/app/api/messages/[messageId]/feedbacks/route.ts @@ -1,16 +1,16 @@ import { type NextRequest } from 'next/server' import { NextResponse } from 'next/server' -import { getInfo, client } from '@/app/api/utils/common' +import { client, getInfo } from '@/app/api/utils/common' export async function POST(request: NextRequest, { params }: { params: { messageId: string } }) { const body = await request.json() const { - rating + rating, } = body const { messageId } = params - const { user } = getInfo(request); + const { user } = getInfo(request) const { data } = await client.messageFeedback(messageId, rating, user) return NextResponse.json(data) } diff --git a/app/api/messages/route.ts b/app/api/messages/route.ts index 57a027c..0edafe7 100644 --- a/app/api/messages/route.ts +++ b/app/api/messages/route.ts @@ -1,13 +1,13 @@ import { type NextRequest } from 'next/server' import { NextResponse } from 'next/server' -import { getInfo, setSession, client } from '@/app/api/utils/common' +import { client, getInfo, setSession } from '@/app/api/utils/common' export async function GET(request: NextRequest) { - const { sessionId, user } = getInfo(request); - const { searchParams } = new URL(request.url); + const { sessionId, user } = getInfo(request) + const { searchParams } = new URL(request.url) const conversationId = searchParams.get('conversation_id') - const { data }: any = await client.getConversationMessages(user, conversationId as string); + const { data }: any = await client.getConversationMessages(user, conversationId as string) return NextResponse.json(data, { - headers: setSession(sessionId) + headers: setSession(sessionId), }) -} \ No newline at end of file +} diff --git a/app/api/parameters/route.ts b/app/api/parameters/route.ts index 1c1d917..97bbdb2 100644 --- a/app/api/parameters/route.ts +++ b/app/api/parameters/route.ts @@ -1,11 +1,11 @@ import { type NextRequest } from 'next/server' import { NextResponse } from 'next/server' -import { getInfo, setSession, client } from '@/app/api/utils/common' +import { client, getInfo, setSession } from '@/app/api/utils/common' export async function GET(request: NextRequest) { - const { sessionId, user } = getInfo(request); - const { data } = await client.getApplicationParameters(user); + const { sessionId, user } = getInfo(request) + const { data } = await client.getApplicationParameters(user) return NextResponse.json(data as object, { - headers: setSession(sessionId) + headers: setSession(sessionId), }) -} \ No newline at end of file +} diff --git a/app/api/utils/common.ts b/app/api/utils/common.ts index a26c885..109ee4b 100644 --- a/app/api/utils/common.ts +++ b/app/api/utils/common.ts @@ -1,16 +1,16 @@ import { type NextRequest } from 'next/server' -import { APP_ID, API_KEY, API_URL } from '@/config' import { ChatClient } from 'dify-client' import { v4 } from 'uuid' +import { API_KEY, API_URL, APP_ID } from '@/config' -const userPrefix = `user_${APP_ID}:`; +const userPrefix = `user_${APP_ID}:` export const getInfo = (request: NextRequest) => { - const sessionId = request.cookies.get('session_id')?.value || v4(); - const user = userPrefix + sessionId; + const sessionId = request.cookies.get('session_id')?.value || v4() + const user = userPrefix + sessionId return { sessionId, - user + user, } } @@ -18,4 +18,4 @@ export const setSession = (sessionId: string) => { return { 'Set-Cookie': `session_id=${sessionId}` } } -export const client = new ChatClient(API_KEY, API_URL ? API_URL : undefined) +export const client = new ChatClient(API_KEY, API_URL || undefined) diff --git a/app/api/utils/stream.ts b/app/api/utils/stream.ts index 2da1359..2262d22 100644 --- a/app/api/utils/stream.ts +++ b/app/api/utils/stream.ts @@ -1,25 +1,25 @@ export async function OpenAIStream(res: { body: any }) { - const reader = res.body.getReader(); + const reader = res.body.getReader() const stream = new ReadableStream({ // https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams // https://github.com/whichlight/chatgpt-api-streaming/blob/master/pages/api/OpenAIStream.ts start(controller) { - return pump(); + return pump() function pump() { return reader.read().then(({ done, value }: any) => { // When no more data needs to be consumed, close the stream if (done) { - controller.close(); - return; + controller.close() + return } // Enqueue the next data chunk into our target stream - controller.enqueue(value); - return pump(); - }); + controller.enqueue(value) + return pump() + }) } }, - }); + }) - return stream; -} \ No newline at end of file + return stream +} diff --git a/app/components/app-unavailable.tsx b/app/components/app-unavailable.tsx index ce4d7c7..b018875 100644 --- a/app/components/app-unavailable.tsx +++ b/app/components/app-unavailable.tsx @@ -14,9 +14,8 @@ const AppUnavailable: FC = ({ }) => { const { t } = useTranslation() let message = errMessage - if (!errMessage) { + if (!errMessage) message = (isUnknwonReason ? t('app.common.appUnkonwError') : t('app.common.appUnavailable')) as string - } return (
diff --git a/app/components/base/auto-height-textarea/index.tsx b/app/components/base/auto-height-textarea/index.tsx index 0fe7ef8..ee015fb 100644 --- a/app/components/base/auto-height-textarea/index.tsx +++ b/app/components/base/auto-height-textarea/index.tsx @@ -19,6 +19,7 @@ const AutoHeightTextarea = forwardRef( { value, onChange, placeholder, className, minHeight = 36, maxHeight = 96, autoFocus, controlFocus, onKeyDown, onKeyUp }: IProps, outerRef: any, ) => { + // eslint-disable-next-line react-hooks/rules-of-hooks const ref = outerRef || useRef(null) const doFocus = () => { diff --git a/app/components/base/markdown.tsx b/app/components/base/markdown.tsx index aac5f7b..29e1b80 100644 --- a/app/components/base/markdown.tsx +++ b/app/components/base/markdown.tsx @@ -18,7 +18,7 @@ export function Markdown(props: { content: string }) { components={{ code({ node, inline, className, children, ...props }) { const match = /language-(\w+)/.exec(className || '') - return !inline && match + return (!inline && match) ? ( Promise @@ -168,8 +168,8 @@ const Answer: FC = ({ item, feedbackDisabled = false, onFeedback,
- {isResponsing && -
+ {isResponsing + &&
} @@ -183,13 +183,15 @@ const Answer: FC = ({ item, feedbackDisabled = false, onFeedback,
{t('app.chat.openingStatementTitle')}
)} - {(isResponsing && !content) ? ( -
- -
- ) : ( - - )} + {(isResponsing && !content) + ? ( +
+ +
+ ) + : ( + + )}
{!feedbackDisabled && !item.feedbackDisabled && renderItemOperation()} @@ -282,9 +284,8 @@ const Chat: FC = ({ if (e.code === 'Enter') { e.preventDefault() // prevent send message when using input method enter - if (!e.shiftKey && !isUseInputMethod.current) { + if (!e.shiftKey && !isUseInputMethod.current) handleSend() - } } } diff --git a/app/components/chat/loading-anim/index.tsx b/app/components/chat/loading-anim/index.tsx index 0cd4111..09f8a54 100644 --- a/app/components/chat/loading-anim/index.tsx +++ b/app/components/chat/loading-anim/index.tsx @@ -1,13 +1,14 @@ 'use client' -import React, { FC } from 'react' +import type { FC } from 'react' +import React from 'react' import s from './style.module.css' -export interface ILoaidingAnimProps { +export type ILoaidingAnimProps = { type: 'text' | 'avatar' } const LoaidingAnim: FC = ({ - type + type, }) => { return (
diff --git a/app/components/index.tsx b/app/components/index.tsx index 448f763..6164f35 100644 --- a/app/components/index.tsx +++ b/app/components/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-use-before-define */ 'use client' import type { FC } from 'react' import React, { useEffect, useRef, useState } from 'react' @@ -10,15 +11,14 @@ import Sidebar from '@/app/components/sidebar' import ConfigSence from '@/app/components/config-scence' import Header from '@/app/components/header' import { fetchAppParams, fetchChatList, fetchConversations, sendChatMessage, updateFeedback } from '@/service' -import type { ConversationItem, Feedbacktype, IChatItem, PromptConfig, AppInfo } from '@/types/app' +import type { ConversationItem, Feedbacktype, IChatItem, PromptConfig } from '@/types/app' import Chat from '@/app/components/chat' import { setLocaleOnClient } from '@/i18n/client' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import Loading from '@/app/components/base/loading' -import { replaceVarWithValues } from '@/utils/prompt' +import { replaceVarWithValues, userInputsFormToPromptVariables } from '@/utils/prompt' import AppUnavailable from '@/app/components/app-unavailable' -import { APP_ID, API_KEY, APP_INFO, isShowPrompt, promptTemplate } from '@/config' -import { userInputsFormToPromptVariables } from '@/utils/prompt' +import { API_KEY, APP_ID, APP_INFO, isShowPrompt, promptTemplate } from '@/config' const Main: FC = () => { const { t } = useTranslation() @@ -37,9 +37,8 @@ const Main: FC = () => { const [isShowSidebar, { setTrue: showSidebar, setFalse: hideSidebar }] = useBoolean(false) useEffect(() => { - if (APP_INFO?.title) { + if (APP_INFO?.title) document.title = `${APP_INFO.title} - Powered by Dify` - } }, [APP_INFO?.title]) /* @@ -318,9 +317,9 @@ const Main: FC = () => { }, async onCompleted() { setResponsingFalse() - if (!tempNewConversationId) { + if (!tempNewConversationId) return - } + if (getConversationIdChangeBecauseOfNew()) { const { data: conversations }: any = await fetchConversations() setConversationList(conversations as ConversationItem[]) diff --git a/app/components/welcome/index.tsx b/app/components/welcome/index.tsx index 633261d..90476f0 100644 --- a/app/components/welcome/index.tsx +++ b/app/components/welcome/index.tsx @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next' import TemplateVarPanel, { PanelTitle, VarOpBtnGroup } from '../value-panel' import s from './style.module.css' import { AppInfoComp, ChatBtn, EditBtn, FootLogo, PromptTemplate } from './massive-component' -import type { PromptConfig, AppInfo } from '@/types/app' +import type { AppInfo, PromptConfig } from '@/types/app' import Toast from '@/app/components/base/toast' import Select from '@/app/components/base/select' import { DEFAULT_VALUE_MAX_LEN } from '@/config' @@ -276,7 +276,7 @@ const Welcome: FC = ({ } const renderHasSetInputs = () => { - if (!isPublicVersion && !canEidtInpus || !hasVar) + if ((!isPublicVersion && !canEidtInpus) || !hasVar) return null return ( diff --git a/config/index.ts b/config/index.ts index 30fd79e..df0247c 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,19 +1,19 @@ -import { AppInfo } from "@/types/app" +import type { AppInfo } from '@/types/app' export const APP_ID = '' export const API_KEY = '' export const API_URL = '' export const APP_INFO: AppInfo = { - "title": 'Chat APP', - "description": '', - "copyright": '', - "privacy_policy": '', - "default_language": 'zh-Hans' + title: 'Chat APP', + description: '', + copyright: '', + privacy_policy: '', + default_language: 'zh-Hans', } export const isShowPrompt = false export const promptTemplate = 'I want you to act as a javascript console.' -export const API_PREFIX = '/api'; +export const API_PREFIX = '/api' export const LOCALE_COOKIE_NAME = 'locale' diff --git a/hooks/use-breakpoints.ts b/hooks/use-breakpoints.ts index 1aab56a..99c2b75 100644 --- a/hooks/use-breakpoints.ts +++ b/hooks/use-breakpoints.ts @@ -8,20 +8,22 @@ export enum MediaType { } const useBreakpoints = () => { - const [width, setWidth] = React.useState(globalThis.innerWidth); + const [width, setWidth] = React.useState(globalThis.innerWidth) const media = (() => { - if (width <= 640) return MediaType.mobile; - if (width <= 768) return MediaType.tablet; - return MediaType.pc; - })(); + if (width <= 640) + return MediaType.mobile + if (width <= 768) + return MediaType.tablet + return MediaType.pc + })() React.useEffect(() => { - const handleWindowResize = () => setWidth(window.innerWidth); - window.addEventListener("resize", handleWindowResize); - return () => window.removeEventListener("resize", handleWindowResize); - }, []); + const handleWindowResize = () => setWidth(window.innerWidth) + window.addEventListener('resize', handleWindowResize) + return () => window.removeEventListener('resize', handleWindowResize) + }, []) - return media; + return media } -export default useBreakpoints \ No newline at end of file +export default useBreakpoints diff --git a/hooks/use-conversation.ts b/hooks/use-conversation.ts index b774016..e24e6da 100644 --- a/hooks/use-conversation.ts +++ b/hooks/use-conversation.ts @@ -1,6 +1,6 @@ import { useState } from 'react' -import type { ConversationItem } from '@/types/app' import produce from 'immer' +import type { ConversationItem } from '@/types/app' const storageConversationIdKey = 'conversationIdInfo' @@ -29,9 +29,10 @@ function useConversation() { // input can be updated by user const [newConversationInputs, setNewConversationInputs] = useState | null>(null) const resetNewConversationInputs = () => { - if (!newConversationInputs) return - setNewConversationInputs(produce(newConversationInputs, draft => { - Object.keys(draft).forEach(key => { + if (!newConversationInputs) + return + setNewConversationInputs(produce(newConversationInputs, (draft) => { + Object.keys(draft).forEach((key) => { draft[key] = '' }) })) @@ -59,8 +60,8 @@ function useConversation() { setCurrInputs, currConversationInfo, setNewConversationInfo, - setExistConversationInfo + setExistConversationInfo, } } -export default useConversation; \ No newline at end of file +export default useConversation diff --git a/i18n/client.ts b/i18n/client.ts index 98424d2..f8dafb4 100644 --- a/i18n/client.ts +++ b/i18n/client.ts @@ -12,7 +12,6 @@ export const getLocaleOnClient = (): Locale => { export const setLocaleOnClient = (locale: Locale, notReload?: boolean) => { Cookies.set(LOCALE_COOKIE_NAME, locale) changeLanguage(locale) - if (!notReload) { + if (!notReload) location.reload() - } } diff --git a/i18n/i18next-config.ts b/i18n/i18next-config.ts index 9f949ae..13580b1 100644 --- a/i18n/i18next-config.ts +++ b/i18n/i18next-config.ts @@ -5,7 +5,7 @@ import commonEn from './lang/common.en' import commonZh from './lang/common.zh' import appEn from './lang/app.en' import appZh from './lang/app.zh' -import { Locale } from '.' +import type { Locale } from '.' const resources = { 'en': { diff --git a/i18n/i18next-serverside-config.ts b/i18n/i18next-serverside-config.ts index fe89475..6e0b692 100644 --- a/i18n/i18next-serverside-config.ts +++ b/i18n/i18next-serverside-config.ts @@ -1,7 +1,7 @@ import { createInstance } from 'i18next' import resourcesToBackend from 'i18next-resources-to-backend' import { initReactI18next } from 'react-i18next/initReactI18next' -import { Locale } from '.' +import type { Locale } from '.' // https://locize.com/blog/next-13-app-dir-i18n/ const initI18next = async (lng: Locale, ns: string) => { @@ -21,6 +21,6 @@ export async function useTranslation(lng: Locale, ns = '', options: Record @media (min-width: 100px) { ... } - 'tablet': '640px', // 391 + tablet: '640px', // 391 // => @media (min-width: 600px) { ... } - 'pc': '769px', + pc: '769px', // => @media (min-width: 769px) { ... } }, }, diff --git a/tsconfig.json b/tsconfig.json index 668a47e..1510574 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -40,4 +40,4 @@ "exclude": [ "node_modules" ] -} \ No newline at end of file +} diff --git a/types/app.ts b/types/app.ts index cc3ea12..7055890 100644 --- a/types/app.ts +++ b/types/app.ts @@ -1,31 +1,31 @@ -import { Locale } from '@/i18n' +import type { Locale } from '@/i18n' export type PromptVariable = { - key: string, - name: string, - type: "string" | "number" | "select", - default?: string | number, + key: string + name: string + type: 'string' | 'number' | 'select' + default?: string | number options?: string[] max_length?: number required: boolean } export type PromptConfig = { - prompt_template: string, - prompt_variables: PromptVariable[], + prompt_template: string + prompt_variables: PromptVariable[] } export type TextTypeFormItem = { - label: string, - variable: string, + label: string + variable: string required: boolean max_length: number } export type SelectTypeFormItem = { - label: string, - variable: string, - required: boolean, + label: string + variable: string + required: boolean options: string[] } /** @@ -79,14 +79,13 @@ export type IChatItem = { isOpeningStatement?: boolean } - export type ResponseHolder = {} export type ConversationItem = { id: string name: string inputs: Record | null - introduction: string, + introduction: string } export type AppInfo = { @@ -95,4 +94,4 @@ export type AppInfo = { default_language: Locale copyright?: string privacy_policy?: string -} \ No newline at end of file +} diff --git a/typography.js b/typography.js index 706e456..92bea1e 100644 --- a/typography.js +++ b/typography.js @@ -38,15 +38,15 @@ module.exports = ({ theme }) => ({ '--tw-prose-invert-td-borders': theme('colors.zinc.700'), // Base - color: 'var(--tw-prose-body)', - fontSize: theme('fontSize.sm')[0], - lineHeight: theme('lineHeight.7'), + 'color': 'var(--tw-prose-body)', + 'fontSize': theme('fontSize.sm')[0], + 'lineHeight': theme('lineHeight.7'), // Layout '> *': { - maxWidth: theme('maxWidth.2xl'), - marginLeft: 'auto', - marginRight: 'auto', + 'maxWidth': theme('maxWidth.2xl'), + 'marginLeft': 'auto', + 'marginRight': 'auto', '@screen lg': { maxWidth: theme('maxWidth.3xl'), marginLeft: `calc(50% - min(50%, ${theme('maxWidth.lg')}))`, @@ -55,7 +55,7 @@ module.exports = ({ theme }) => ({ }, // Text - p: { + 'p': { marginTop: theme('spacing.6'), marginBottom: theme('spacing.6'), }, @@ -65,7 +65,7 @@ module.exports = ({ theme }) => ({ }, // Lists - ol: { + 'ol': { listStyleType: 'decimal', marginTop: theme('spacing.5'), marginBottom: theme('spacing.5'), @@ -98,13 +98,13 @@ module.exports = ({ theme }) => ({ 'ol[type="1"]': { listStyleType: 'decimal', }, - ul: { + 'ul': { listStyleType: 'disc', marginTop: theme('spacing.5'), marginBottom: theme('spacing.5'), paddingLeft: '1.625rem', }, - li: { + 'li': { marginTop: theme('spacing.2'), marginBottom: theme('spacing.2'), }, @@ -140,14 +140,14 @@ module.exports = ({ theme }) => ({ }, // Horizontal rules - hr: { - borderColor: 'var(--tw-prose-hr)', - borderTopWidth: 1, - marginTop: theme('spacing.16'), - marginBottom: theme('spacing.16'), - maxWidth: 'none', - marginLeft: `calc(-1 * ${theme('spacing.4')})`, - marginRight: `calc(-1 * ${theme('spacing.4')})`, + 'hr': { + 'borderColor': 'var(--tw-prose-hr)', + 'borderTopWidth': 1, + 'marginTop': theme('spacing.16'), + 'marginBottom': theme('spacing.16'), + 'maxWidth': 'none', + 'marginLeft': `calc(-1 * ${theme('spacing.4')})`, + 'marginRight': `calc(-1 * ${theme('spacing.4')})`, '@screen sm': { marginLeft: `calc(-1 * ${theme('spacing.6')})`, marginRight: `calc(-1 * ${theme('spacing.6')})`, @@ -159,7 +159,7 @@ module.exports = ({ theme }) => ({ }, // Quotes - blockquote: { + 'blockquote': { fontWeight: '500', fontStyle: 'italic', color: 'var(--tw-prose-quotes)', @@ -178,14 +178,14 @@ module.exports = ({ theme }) => ({ }, // Headings - h1: { + 'h1': { color: 'var(--tw-prose-headings)', fontWeight: '700', fontSize: theme('fontSize.2xl')[0], ...theme('fontSize.2xl')[1], marginBottom: theme('spacing.2'), }, - h2: { + 'h2': { color: 'var(--tw-prose-headings)', fontWeight: '600', fontSize: theme('fontSize.lg')[0], @@ -193,7 +193,7 @@ module.exports = ({ theme }) => ({ marginTop: theme('spacing.16'), marginBottom: theme('spacing.2'), }, - h3: { + 'h3': { color: 'var(--tw-prose-headings)', fontSize: theme('fontSize.base')[0], ...theme('fontSize.base')[1], @@ -211,7 +211,7 @@ module.exports = ({ theme }) => ({ marginTop: '0', marginBottom: '0', }, - figcaption: { + 'figcaption': { color: 'var(--tw-prose-captions)', fontSize: theme('fontSize.xs')[0], ...theme('fontSize.xs')[1], @@ -219,7 +219,7 @@ module.exports = ({ theme }) => ({ }, // Tables - table: { + 'table': { width: '100%', tableLayout: 'auto', textAlign: 'left', @@ -227,7 +227,7 @@ module.exports = ({ theme }) => ({ marginBottom: theme('spacing.8'), lineHeight: theme('lineHeight.6'), }, - thead: { + 'thead': { borderBottomWidth: '1px', borderBottomColor: 'var(--tw-prose-th-borders)', }, @@ -255,7 +255,7 @@ module.exports = ({ theme }) => ({ 'tbody td': { verticalAlign: 'baseline', }, - tfoot: { + 'tfoot': { borderTopWidth: '1px', borderTopColor: 'var(--tw-prose-th-borders)', }, @@ -276,13 +276,13 @@ module.exports = ({ theme }) => ({ }, // Inline elements - a: { - color: 'var(--tw-prose-links)', - textDecoration: 'underline transparent', - fontWeight: '500', - transitionProperty: 'color, text-decoration-color', - transitionDuration: theme('transitionDuration.DEFAULT'), - transitionTimingFunction: theme('transitionTimingFunction.DEFAULT'), + 'a': { + 'color': 'var(--tw-prose-links)', + 'textDecoration': 'underline transparent', + 'fontWeight': '500', + 'transitionProperty': 'color, text-decoration-color', + 'transitionDuration': theme('transitionDuration.DEFAULT'), + 'transitionTimingFunction': theme('transitionTimingFunction.DEFAULT'), '&:hover': { color: 'var(--tw-prose-links-hover)', textDecorationColor: 'var(--tw-prose-links-underline)', @@ -291,14 +291,14 @@ module.exports = ({ theme }) => ({ ':is(h1, h2, h3) a': { fontWeight: 'inherit', }, - strong: { + 'strong': { color: 'var(--tw-prose-bold)', fontWeight: '600', }, ':is(a, blockquote, thead th) strong': { color: 'inherit', }, - code: { + 'code': { color: 'var(--tw-prose-code)', borderRadius: theme('borderRadius.lg'), paddingTop: theme('padding.1'), diff --git a/utils/prompt.ts b/utils/prompt.ts index 2b11efe..c23fccd 100644 --- a/utils/prompt.ts +++ b/utils/prompt.ts @@ -1,4 +1,4 @@ -import { PromptVariable, UserInputFormItem } from '@/types/app' +import type { PromptVariable, UserInputFormItem } from '@/types/app' export function replaceVarWithValues(str: string, promptVariables: PromptVariable[], inputs: Record) { return str.replace(/\{\{([^}]+)\}\}/g, (match, key) => { @@ -12,11 +12,12 @@ export function replaceVarWithValues(str: string, promptVariables: PromptVariabl } export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] | null) => { - if (!useInputs) return [] + if (!useInputs) + return [] const promptVariables: PromptVariable[] = [] useInputs.forEach((item: any) => { const type = item['text-input'] ? 'string' : 'select' - const content = type === 'string' ? item['text-input'] : item['select'] + const content = type === 'string' ? item['text-input'] : item.select if (type === 'string') { promptVariables.push({ key: content.variable, @@ -26,7 +27,8 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] | max_length: content.max_length, options: [], }) - } else { + } + else { promptVariables.push({ key: content.variable, name: content.label, @@ -37,4 +39,4 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] | } }) return promptVariables -} \ No newline at end of file +}