mirror of https://github.com/langgenius/dify.git
feat: main api ok
This commit is contained in:
parent
3401949be9
commit
6f7fe943d1
|
|
@ -24,6 +24,8 @@ export interface IGenerationItemProps {
|
|||
onFeedback?: (feedback: Feedbacktype) => void
|
||||
onSave?: (messageId: string) => void
|
||||
isMobile?: boolean
|
||||
isInstalledApp: boolean,
|
||||
installedAppId?: string,
|
||||
}
|
||||
|
||||
export const SimpleBtn = ({ className, onClick, children }: {
|
||||
|
|
@ -75,7 +77,9 @@ const GenerationItem: FC<IGenerationItemProps> = ({
|
|||
onFeedback,
|
||||
onSave,
|
||||
depth = 1,
|
||||
isMobile
|
||||
isMobile,
|
||||
isInstalledApp,
|
||||
installedAppId,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const isTop = depth === 1
|
||||
|
|
@ -88,7 +92,7 @@ const GenerationItem: FC<IGenerationItemProps> = ({
|
|||
})
|
||||
|
||||
const handleFeedback = async (childFeedback: Feedbacktype) => {
|
||||
await updateFeedback({ url: `/messages/${childMessageId}/feedbacks`, body: { rating: childFeedback.rating } })
|
||||
await updateFeedback({ url: `/messages/${childMessageId}/feedbacks`, body: { rating: childFeedback.rating } }, isInstalledApp, installedAppId)
|
||||
setChildFeedback(childFeedback)
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +108,9 @@ const GenerationItem: FC<IGenerationItemProps> = ({
|
|||
isLoading: isQuerying,
|
||||
feedback: childFeedback,
|
||||
onSave,
|
||||
isMobile
|
||||
isMobile,
|
||||
isInstalledApp,
|
||||
installedAppId,
|
||||
}
|
||||
|
||||
const handleMoreLikeThis = async () => {
|
||||
|
|
@ -113,7 +119,7 @@ const GenerationItem: FC<IGenerationItemProps> = ({
|
|||
return
|
||||
}
|
||||
startQuerying()
|
||||
const res: any = await fetchMoreLikeThis(messageId as string)
|
||||
const res: any = await fetchMoreLikeThis(messageId as string, isInstalledApp, installedAppId)
|
||||
setCompletionRes(res.answer)
|
||||
setChildMessageId(res.id)
|
||||
stopQuerying()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
'use client'
|
||||
import React, { FC, useEffect } from 'react'
|
||||
import React, { FC, useEffect, useState } from 'react'
|
||||
import ExploreContext from '@/context/explore-context'
|
||||
import Sidebar from '@/app/components/explore/sidebar'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
import { fetchMembers } from '@/service/common'
|
||||
import { InstalledApp } from '@/models/explore'
|
||||
|
||||
export interface IExploreProps {
|
||||
children: React.ReactNode
|
||||
|
|
@ -12,9 +13,10 @@ export interface IExploreProps {
|
|||
const Explore: FC<IExploreProps> = ({
|
||||
children
|
||||
}) => {
|
||||
const [controlUpdateInstalledApps, setControlUpdateInstalledApps] = React.useState(0)
|
||||
const [controlUpdateInstalledApps, setControlUpdateInstalledApps] = useState(0)
|
||||
const { userProfile } = useAppContext()
|
||||
const [hasEditPermission, setHasEditPermission] = React.useState(false)
|
||||
const [hasEditPermission, setHasEditPermission] = useState(false)
|
||||
const [installedApps, setInstalledApps] = useState<InstalledApp[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
|
|
@ -32,7 +34,9 @@ const Explore: FC<IExploreProps> = ({
|
|||
{
|
||||
controlUpdateInstalledApps,
|
||||
setControlUpdateInstalledApps,
|
||||
hasEditPermission
|
||||
hasEditPermission,
|
||||
installedApps,
|
||||
setInstalledApps
|
||||
}
|
||||
}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
'use client'
|
||||
import React, { FC, useEffect } from 'react'
|
||||
import { App } from '@/types/app'
|
||||
import React, { FC } from 'react'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import ExploreContext from '@/context/explore-context'
|
||||
import ChatApp from '@/app/components/share/chat'
|
||||
import TextGenerationApp from '@/app/components/share/text-generation'
|
||||
import { fetchAppDetail } from '@/service/explore'
|
||||
import Loading from '@/app/components/base/loading'
|
||||
|
||||
export interface IInstalledAppProps {
|
||||
|
|
@ -13,20 +13,15 @@ export interface IInstalledAppProps {
|
|||
const InstalledApp: FC<IInstalledAppProps> = ({
|
||||
id,
|
||||
}) => {
|
||||
const [app, setApp] = React.useState<App | null>(null)
|
||||
const [isLoaded, setIsLoaded] = React.useState(false)
|
||||
useEffect(() => {
|
||||
if(id) {
|
||||
setIsLoaded(false);
|
||||
(async () => {
|
||||
const appDetail = await fetchAppDetail(id)
|
||||
setApp(appDetail)
|
||||
setIsLoaded(true)
|
||||
})()
|
||||
}
|
||||
}, [id])
|
||||
const { installedApps } = useContext(ExploreContext)
|
||||
const installedApp = installedApps.find(item => item.id === id)
|
||||
const app = installedApp ? {
|
||||
id: installedApp.id,
|
||||
name
|
||||
} : null
|
||||
|
||||
|
||||
if(!isLoaded) {
|
||||
if(!installedApp) {
|
||||
return (
|
||||
<div className='flex h-full items-center'>
|
||||
<Loading type='area' />
|
||||
|
|
@ -36,12 +31,11 @@ const InstalledApp: FC<IInstalledAppProps> = ({
|
|||
|
||||
return (
|
||||
<div className='h-full'>
|
||||
{app?.mode === 'chat' ? (
|
||||
<ChatApp isInstalledApp installedAppInfo={app as App}/>
|
||||
{installedApp?.app.mode === 'chat' ? (
|
||||
<ChatApp isInstalledApp installedAppInfo={installedApp}/>
|
||||
): (
|
||||
<TextGenerationApp isInstalledApp installedAppInfo={app as App}/>
|
||||
<TextGenerationApp isInstalledApp installedAppInfo={installedApp}/>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
'use client'
|
||||
import React, { FC, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import ExploreContext from '@/context/explore-context'
|
||||
import cn from 'classnames'
|
||||
import { useSelectedLayoutSegments } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import Item from './app-nav-item'
|
||||
import { InstalledApp } from '@/models/explore'
|
||||
import { fetchInstalledAppList as doFetchInstalledAppList } from '@/service/explore'
|
||||
|
||||
const SelectedDiscoveryIcon = () => (
|
||||
|
|
@ -21,15 +22,15 @@ const DiscoveryIcon = () => (
|
|||
)
|
||||
|
||||
const SideBar: FC<{
|
||||
controlUpdateInstalledApps: number
|
||||
controlUpdateInstalledApps: number,
|
||||
}> = ({
|
||||
controlUpdateInstalledApps
|
||||
controlUpdateInstalledApps,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const segments = useSelectedLayoutSegments()
|
||||
const lastSegment = segments.slice(-1)[0]
|
||||
const isDiscoverySelected = lastSegment === 'apps'
|
||||
const [installedApps, setInstalledApps] = React.useState<InstalledApp[]>([])
|
||||
const { installedApps, setInstalledApps } = useContext(ExploreContext)
|
||||
|
||||
const fetchInstalledAppList = async () => {
|
||||
const {installed_apps} : any = await doFetchInstalledAppList()
|
||||
|
|
@ -60,7 +61,7 @@ const SideBar: FC<{
|
|||
<div className='mt-10'>
|
||||
<div className='pl-2 text-xs text-gray-500 font-medium uppercase'>{t('explore.sidebar.workspace')}</div>
|
||||
<div className='mt-3 space-y-1'>
|
||||
{installedApps.map(({app : {id, name}}) => {
|
||||
{installedApps.map(({id, app : { name }}) => {
|
||||
return (
|
||||
<Item key={id} name={name} id={id} isSelected={lastSegment?.toLowerCase() === id} />
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ import { replaceStringWithValues } from '@/app/components/app/configuration/prom
|
|||
import AppUnavailable from '../../base/app-unavailable'
|
||||
import { userInputsFormToPromptVariables } from '@/utils/model-config'
|
||||
import { SuggestedQuestionsAfterAnswerConfig } from '@/models/debug'
|
||||
import { App } from '@/types/app'
|
||||
import { InstalledApp } from '@/models/explore'
|
||||
|
||||
export type IMainProps = {
|
||||
isInstalledApp?: boolean,
|
||||
installedAppInfo? : App
|
||||
installedAppInfo? : InstalledApp
|
||||
}
|
||||
|
||||
const Main: FC<IMainProps> = ({
|
||||
|
|
@ -227,11 +227,10 @@ const Main: FC<IMainProps> = ({
|
|||
return Promise.all([isInstalledApp ? {
|
||||
app_id: installedAppInfo?.id,
|
||||
site: {
|
||||
title: installedAppInfo?.name,
|
||||
title: installedAppInfo?.app.name,
|
||||
prompt_public: false,
|
||||
copyright: ''
|
||||
},
|
||||
model_config: installedAppInfo?.app_model_config,
|
||||
plan: 'basic',
|
||||
}: fetchAppInfo(), fetchConversations(isInstalledApp, installedAppInfo?.id), fetchAppParams(isInstalledApp, installedAppInfo?.id)])
|
||||
}
|
||||
|
|
@ -242,12 +241,12 @@ const Main: FC<IMainProps> = ({
|
|||
(async () => {
|
||||
try {
|
||||
const [appData, conversationData, appParams]: any = await fetchInitData()
|
||||
const { app_id: appId, site: siteInfo, model_config, plan }: any = appData
|
||||
const { app_id: appId, site: siteInfo, plan }: any = appData
|
||||
setAppId(appId)
|
||||
setPlan(plan)
|
||||
const tempIsPublicVersion = siteInfo.prompt_public
|
||||
setIsPublicVersion(tempIsPublicVersion)
|
||||
const prompt_template = tempIsPublicVersion ? model_config.pre_prompt : ''
|
||||
const prompt_template = ''
|
||||
// handle current conversation id
|
||||
const { data: conversations } = conversationData as { data: ConversationItem[] }
|
||||
const _conversationId = getConversationIdFromStorage(appId)
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ import { XMarkIcon } from '@heroicons/react/24/outline'
|
|||
import s from './style.module.css'
|
||||
import Button from '../../base/button'
|
||||
import { App } from '@/types/app'
|
||||
import { InstalledApp } from '@/models/explore'
|
||||
|
||||
export type IMainProps = {
|
||||
isInstalledApp?: boolean,
|
||||
installedAppInfo? : App
|
||||
installedAppInfo? : InstalledApp
|
||||
}
|
||||
|
||||
const TextGeneration: FC<IMainProps> = ({
|
||||
|
|
@ -167,11 +168,10 @@ const TextGeneration: FC<IMainProps> = ({
|
|||
return Promise.all([isInstalledApp ? {
|
||||
app_id: installedAppInfo?.id,
|
||||
site: {
|
||||
title: installedAppInfo?.name,
|
||||
title: installedAppInfo?.app.name,
|
||||
prompt_public: false,
|
||||
copyright: ''
|
||||
},
|
||||
model_config: installedAppInfo?.app_model_config,
|
||||
plan: 'basic',
|
||||
}: fetchAppInfo(), fetchAppParams(isInstalledApp, installedAppInfo?.id)])
|
||||
}
|
||||
|
|
@ -249,6 +249,8 @@ const TextGeneration: FC<IMainProps> = ({
|
|||
feedback={feedback}
|
||||
onSave={handleSaveMessage}
|
||||
isMobile={isMoble}
|
||||
isInstalledApp={isInstalledApp}
|
||||
installedAppId={installedAppInfo?.id}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,20 @@
|
|||
import { createContext } from 'use-context-selector'
|
||||
import { InstalledApp } from '@/models/explore'
|
||||
|
||||
type IExplore = {
|
||||
controlUpdateInstalledApps: number
|
||||
setControlUpdateInstalledApps: (controlUpdateInstalledApps: number) => void
|
||||
hasEditPermission: boolean
|
||||
installedApps: InstalledApp[]
|
||||
setInstalledApps: (installedApps: InstalledApp[]) => void
|
||||
}
|
||||
|
||||
const ExploreContext = createContext<IExplore>({
|
||||
controlUpdateInstalledApps: 0,
|
||||
setControlUpdateInstalledApps: () => { },
|
||||
hasEditPermission: false,
|
||||
installedApps: [],
|
||||
setInstalledApps: () => { },
|
||||
})
|
||||
|
||||
export default ExploreContext
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export const sendChatMessage = async (body: Record<string, any>, { onData, onCom
|
|||
...body,
|
||||
response_mode: 'streaming',
|
||||
},
|
||||
}, { onData, onCompleted, isPublicAPI: true, onError, getAbortController })
|
||||
}, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError, getAbortController })
|
||||
}
|
||||
|
||||
export const sendCompletionMessage = async (body: Record<string, any>, { onData, onCompleted, onError }: {
|
||||
|
|
@ -44,7 +44,7 @@ export const sendCompletionMessage = async (body: Record<string, any>, { onData,
|
|||
...body,
|
||||
response_mode: 'streaming',
|
||||
},
|
||||
}, { onData, onCompleted, isPublicAPI: true, onError })
|
||||
}, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError })
|
||||
}
|
||||
|
||||
export const fetchAppInfo = async () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue