mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2026-02-04 01:25:30 +08:00
Compare commits
1 Commits
feat/suppo
...
fix/the-2t
| Author | SHA1 | Date | |
|---|---|---|---|
| 754b77657b |
@ -1,21 +0,0 @@
|
|||||||
import { type NextRequest } from 'next/server'
|
|
||||||
import { client } from '@/app/api/utils/common'
|
|
||||||
import { API_KEY, API_URL, APP_ID } from '@/config'
|
|
||||||
|
|
||||||
// import { commonClient } from 'dify-client'
|
|
||||||
import axios from "axios";
|
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
|
||||||
const headers = {
|
|
||||||
Authorization: `Bearer ${API_KEY}`,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
'X-App-Code': APP_ID
|
|
||||||
};
|
|
||||||
const res = await axios({
|
|
||||||
url: 'https://api.dify.ai/v1/passport',
|
|
||||||
headers,
|
|
||||||
responseType: "json",
|
|
||||||
})
|
|
||||||
console.log(res)
|
|
||||||
return new Response(res.data)
|
|
||||||
}
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import { type NextRequest } from 'next/server'
|
import { type NextRequest } from 'next/server'
|
||||||
import { ChatClient, DifyClient } from 'dify-client'
|
import { ChatClient } from 'dify-client'
|
||||||
import { v4 } from 'uuid'
|
import { v4 } from 'uuid'
|
||||||
import { API_KEY, API_URL, APP_ID } from '@/config'
|
import { API_KEY, API_URL, APP_ID } from '@/config'
|
||||||
|
|
||||||
@ -19,4 +19,3 @@ export const setSession = (sessionId: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const client = new ChatClient(API_KEY, API_URL || undefined)
|
export const client = new ChatClient(API_KEY, API_URL || undefined)
|
||||||
export const commonClient = new ChatClient(API_KEY, API_URL || undefined)
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import Loading from '@/app/components/base/loading'
|
|||||||
import { replaceVarWithValues, userInputsFormToPromptVariables } from '@/utils/prompt'
|
import { replaceVarWithValues, userInputsFormToPromptVariables } from '@/utils/prompt'
|
||||||
import AppUnavailable from '@/app/components/app-unavailable'
|
import AppUnavailable from '@/app/components/app-unavailable'
|
||||||
import { API_KEY, APP_ID, APP_INFO, isShowPrompt, promptTemplate } from '@/config'
|
import { API_KEY, APP_ID, APP_INFO, isShowPrompt, promptTemplate } from '@/config'
|
||||||
import { checkOrSetAccessToken } from '@/utils/access-token'
|
|
||||||
|
|
||||||
const Main: FC = () => {
|
const Main: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -64,6 +63,8 @@ const Main: FC = () => {
|
|||||||
const [conversationIdChangeBecauseOfNew, setConversationIdChangeBecauseOfNew, getConversationIdChangeBecauseOfNew] = useGetState(false)
|
const [conversationIdChangeBecauseOfNew, setConversationIdChangeBecauseOfNew, getConversationIdChangeBecauseOfNew] = useGetState(false)
|
||||||
const [isChatStarted, { setTrue: setChatStarted, setFalse: setChatNotStarted }] = useBoolean(false)
|
const [isChatStarted, { setTrue: setChatStarted, setFalse: setChatNotStarted }] = useBoolean(false)
|
||||||
const handleStartChat = (inputs: Record<string, any>) => {
|
const handleStartChat = (inputs: Record<string, any>) => {
|
||||||
|
createNewChat()
|
||||||
|
setConversationIdChangeBecauseOfNew(true)
|
||||||
setCurrInputs(inputs)
|
setCurrInputs(inputs)
|
||||||
setChatStarted()
|
setChatStarted()
|
||||||
// parse variables in introduction
|
// parse variables in introduction
|
||||||
@ -198,8 +199,6 @@ const Main: FC = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
(async () => {
|
(async () => {
|
||||||
await checkOrSetAccessToken()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [conversationData, appParams] = await Promise.all([fetchConversations(), fetchAppParams()])
|
const [conversationData, appParams] = await Promise.all([fetchConversations(), fetchAppParams()])
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { API_PREFIX, APP_ID } from '@/config'
|
import { API_PREFIX } from '@/config'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
|
|
||||||
const TIME_OUT = 100000
|
const TIME_OUT = 100000
|
||||||
@ -102,16 +102,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
|
|||||||
|
|
||||||
const baseFetch = (url: string, fetchOptions: any, { needAllResponseContent }: IOtherOptions) => {
|
const baseFetch = (url: string, fetchOptions: any, { needAllResponseContent }: IOtherOptions) => {
|
||||||
const options = Object.assign({}, baseOptions, fetchOptions)
|
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
|
const urlPrefix = API_PREFIX
|
||||||
|
|
||||||
let urlWithPrefix = `${urlPrefix}${url.startsWith('/') ? url : `/${url}`}`
|
let urlWithPrefix = `${urlPrefix}${url.startsWith('/') ? url : `/${url}`}`
|
||||||
|
|||||||
@ -31,7 +31,3 @@ export const fetchAppParams = async () => {
|
|||||||
export const updateFeedback = async ({ url, body }: { url: string; body: Feedbacktype }) => {
|
export const updateFeedback = async ({ url, body }: { url: string; body: Feedbacktype }) => {
|
||||||
return post(url, { body })
|
return post(url, { body })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchAccessToken = async (appId: string) => {
|
|
||||||
return get('/passport') as Promise<{ access_token: string }>
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
import { fetchAccessToken } from '@/service'
|
|
||||||
import { APP_ID } from '@/config'
|
|
||||||
|
|
||||||
export const checkOrSetAccessToken = async () => {
|
|
||||||
const sharedToken = APP_ID
|
|
||||||
const accessToken = localStorage.getItem('token') || JSON.stringify({ [sharedToken]: '' })
|
|
||||||
let accessTokenJson = { [sharedToken]: '' }
|
|
||||||
try {
|
|
||||||
accessTokenJson = JSON.parse(accessToken)
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (!accessTokenJson[sharedToken]) {
|
|
||||||
const res = await fetchAccessToken(sharedToken)
|
|
||||||
accessTokenJson[sharedToken] = res.access_token
|
|
||||||
localStorage.setItem('token', JSON.stringify(accessTokenJson))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user