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