mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 10:38:32 +08:00
refactor(web): migrate agent v2 app context consumers (#38558)
This commit is contained in:
parent
eca2d419b2
commit
af5b08ac5c
@ -142,11 +142,19 @@ vi.mock('@/context/i18n', () => ({
|
||||
useDocLink: () => 'https://docs.example.com',
|
||||
}))
|
||||
|
||||
vi.mock('@/context/app-context', () => ({
|
||||
useSelector: (selector: (value: { currentWorkspace: { id: string } }) => string) => selector({
|
||||
vi.mock('@/context/app-context-state', async (importOriginal) => {
|
||||
const { createAppContextStateAtomMock } = await import('@/__tests__/utils/mock-app-context-state')
|
||||
|
||||
return createAppContextStateAtomMock(importOriginal, () => ({
|
||||
currentWorkspace: { id: 'workspace-123' },
|
||||
}),
|
||||
}))
|
||||
}))
|
||||
})
|
||||
|
||||
vi.mock('jotai', async (importOriginal) => {
|
||||
const { createAppContextStateJotaiMock } = await import('@/__tests__/utils/mock-app-context-state')
|
||||
|
||||
return createAppContextStateJotaiMock(importOriginal)
|
||||
})
|
||||
|
||||
vi.mock('@/service/use-tools', () => ({
|
||||
useAllBuiltInTools: () => ({ data: mockBuiltInTools }),
|
||||
|
||||
@ -2,9 +2,10 @@
|
||||
|
||||
import type { ToolWithProvider } from '@/app/components/workflow/types'
|
||||
import type { AgentTool } from '@/features/agent-v2/agent-composer/form-state'
|
||||
import { useAtomValue } from 'jotai'
|
||||
import { useMemo } from 'react'
|
||||
import { API_PREFIX } from '@/config'
|
||||
import { useSelector } from '@/context/app-context'
|
||||
import { currentWorkspaceIdAtom } from '@/context/app-context-state'
|
||||
import useTheme from '@/hooks/use-theme'
|
||||
import {
|
||||
useAllBuiltInTools,
|
||||
@ -67,7 +68,7 @@ function createProviderMap(providers: ToolWithProvider[]) {
|
||||
|
||||
export function useAgentPromptToolIconResolver() {
|
||||
const { theme } = useTheme()
|
||||
const currentWorkspaceId = useSelector(s => s.currentWorkspace.id)
|
||||
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom)
|
||||
const { data: builtInTools } = useAllBuiltInTools()
|
||||
const { data: customTools } = useAllCustomTools()
|
||||
const { data: workflowTools } = useAllWorkflowTools()
|
||||
|
||||
@ -96,14 +96,22 @@ vi.mock('@/app/components/base/chat/chat/hooks', () => ({
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('@/context/app-context', () => ({
|
||||
useAppContext: () => ({
|
||||
vi.mock('@/context/app-context-state', async (importOriginal) => {
|
||||
const { createAppContextStateAtomMock } = await import('@/__tests__/utils/mock-app-context-state')
|
||||
|
||||
return createAppContextStateAtomMock(importOriginal, () => ({
|
||||
userProfile: {
|
||||
avatar_url: '',
|
||||
name: 'User',
|
||||
},
|
||||
}),
|
||||
}))
|
||||
}))
|
||||
})
|
||||
|
||||
vi.mock('jotai', async (importOriginal) => {
|
||||
const { createAppContextStateJotaiMock } = await import('@/__tests__/utils/mock-app-context-state')
|
||||
|
||||
return createAppContextStateJotaiMock(importOriginal)
|
||||
})
|
||||
|
||||
vi.mock('@/app/components/header/account-setting/model-provider-page/hooks', () => ({
|
||||
useTextGenerationCurrentProviderAndModelAndModelList: () => ({
|
||||
|
||||
@ -58,16 +58,23 @@ vi.mock('@/service/client', () => ({
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@/context/app-context', () => ({
|
||||
useSelector: <T,>(selector: (state: { userProfile: { id: string, name: string, email: string } }) => T) =>
|
||||
selector({
|
||||
userProfile: {
|
||||
id: 'user-1',
|
||||
name: 'Alice',
|
||||
email: 'alice@example.com',
|
||||
},
|
||||
}),
|
||||
}))
|
||||
vi.mock('@/context/app-context-state', async (importOriginal) => {
|
||||
const { createAppContextStateAtomMock } = await import('@/__tests__/utils/mock-app-context-state')
|
||||
|
||||
return createAppContextStateAtomMock(importOriginal, () => ({
|
||||
userProfile: {
|
||||
id: 'user-1',
|
||||
name: 'Alice',
|
||||
email: 'alice@example.com',
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
vi.mock('jotai', async (importOriginal) => {
|
||||
const { createAppContextStateJotaiMock } = await import('@/__tests__/utils/mock-app-context-state')
|
||||
|
||||
return createAppContextStateJotaiMock(importOriginal)
|
||||
})
|
||||
|
||||
describe('AgentPreviewVersionsPanel', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@ -35,7 +35,7 @@ import { useTextGenerationCurrentProviderAndModelAndModelList } from '@/app/comp
|
||||
import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils'
|
||||
import { InputVarType, SupportUploadFileTypes } from '@/app/components/workflow/types'
|
||||
import { DEFAULT_CHAT_PROMPT_CONFIG, DEFAULT_COMPLETION_PROMPT_CONFIG } from '@/config'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
import { userProfileAtom } from '@/context/app-context-state'
|
||||
import { agentComposerModelAtom } from '@/features/agent-v2/agent-composer/store-modules/model'
|
||||
import { agentComposerPromptAtom } from '@/features/agent-v2/agent-composer/store-modules/prompt'
|
||||
import { ENABLE_AGENT_CLI_TOOLS } from '@/features/agent-v2/agent-detail/configure/feature-flags'
|
||||
@ -589,7 +589,7 @@ function AgentPreviewChatSession({
|
||||
}) {
|
||||
const { t } = useTranslation('agentV2')
|
||||
const queryClient = useQueryClient()
|
||||
const { userProfile } = useAppContext()
|
||||
const userProfile = useAtomValue(userProfileAtom)
|
||||
const prompt = useAtomValue(agentComposerPromptAtom)
|
||||
const currentModel = useAtomValue(agentComposerModelAtom)
|
||||
const config = useMemo(() => buildChatConfig({
|
||||
|
||||
@ -2,9 +2,10 @@
|
||||
|
||||
import type { AgentVersionFilter } from './filter'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useAtomValue } from 'jotai'
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useSelector as useAppContextSelector } from '@/context/app-context'
|
||||
import { userProfileAtom } from '@/context/app-context-state'
|
||||
import { consoleQuery } from '@/service/client'
|
||||
import { CurrentDraftItem } from './current-draft-item'
|
||||
import { VersionFilter } from './filter'
|
||||
@ -27,7 +28,7 @@ export function AgentPreviewVersionsPanel({
|
||||
const { t } = useTranslation('agentV2')
|
||||
const { t: tCommon } = useTranslation('common')
|
||||
const { t: tWorkflow } = useTranslation('workflow')
|
||||
const userProfile = useAppContextSelector(state => state.userProfile)
|
||||
const userProfile = useAtomValue(userProfileAtom)
|
||||
const [filterValue, setFilterValue] = useState<AgentVersionFilter>('all')
|
||||
const versionsQuery = useQuery(consoleQuery.agent.byAgentId.versions.get.queryOptions({
|
||||
input: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user