mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2025-12-23 07:08:08 +08:00
just add
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { ChatClient } from 'dify-client'
|
||||
import { ChatClient, DifyClient } from 'dify-client'
|
||||
import { v4 } from 'uuid'
|
||||
import { API_KEY, API_URL, APP_ID } from '@/config'
|
||||
|
||||
@ -19,3 +19,4 @@ export const setSession = (sessionId: string) => {
|
||||
}
|
||||
|
||||
export const client = new ChatClient(API_KEY, API_URL || undefined)
|
||||
export const commonClient = new ChatClient(API_KEY, API_URL || undefined)
|
||||
|
||||
@ -19,6 +19,7 @@ import Loading from '@/app/components/base/loading'
|
||||
import { replaceVarWithValues, userInputsFormToPromptVariables } from '@/utils/prompt'
|
||||
import AppUnavailable from '@/app/components/app-unavailable'
|
||||
import { API_KEY, APP_ID, APP_INFO, isShowPrompt, promptTemplate } from '@/config'
|
||||
import { checkOrSetAccessToken } from '@/utils/access-token'
|
||||
|
||||
const Main: FC = () => {
|
||||
const { t } = useTranslation()
|
||||
@ -197,6 +198,8 @@ const Main: FC = () => {
|
||||
return
|
||||
}
|
||||
(async () => {
|
||||
await checkOrSetAccessToken()
|
||||
|
||||
try {
|
||||
const [conversationData, appParams] = await Promise.all([fetchConversations(), fetchAppParams()])
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { AppInfo } from '@/types/app'
|
||||
export const APP_ID = ''
|
||||
export const API_KEY = ''
|
||||
export const APP_ID = '3caee4a2-273e-4686-b53e-59b4aaee8006'
|
||||
export const API_KEY = 'app-j0LqnaHykYouvz8PnYgldWcM'
|
||||
export const API_URL = ''
|
||||
export const APP_INFO: AppInfo = {
|
||||
title: 'Chat APP',
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { API_PREFIX } from '@/config'
|
||||
import { API_PREFIX, APP_ID } from '@/config'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
|
||||
const TIME_OUT = 100000
|
||||
@ -102,7 +102,16 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
|
||||
|
||||
const baseFetch = (url: string, fetchOptions: any, { needAllResponseContent }: IOtherOptions) => {
|
||||
const options = Object.assign({}, baseOptions, fetchOptions)
|
||||
const sharedToken = APP_ID
|
||||
const accessToken = localStorage.getItem('token') || JSON.stringify({ [sharedToken]: '' })
|
||||
let accessTokenJson = { [sharedToken]: '' }
|
||||
try {
|
||||
accessTokenJson = JSON.parse(accessToken)
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
}
|
||||
options.headers.set('Authorization', `Bearer ${accessTokenJson[sharedToken]}`)
|
||||
const urlPrefix = API_PREFIX
|
||||
|
||||
let urlWithPrefix = `${urlPrefix}${url.startsWith('/') ? url : `/${url}`}`
|
||||
|
||||
@ -31,3 +31,7 @@ export const fetchAppParams = async () => {
|
||||
export const updateFeedback = async ({ url, body }: { url: string; body: Feedbacktype }) => {
|
||||
return post(url, { body })
|
||||
}
|
||||
|
||||
export const fetchAccessToken = async (appId: string) => {
|
||||
return get('/passport') as Promise<{ access_token: string }>
|
||||
}
|
||||
Reference in New Issue
Block a user