mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 10:38:32 +08:00
fix(web): agent tool credentials mismatch (#38637)
This commit is contained in:
parent
b325597d29
commit
0038bcc4bb
@ -454,6 +454,36 @@ describe('AgentTools', () => {
|
||||
expect(formattingDispatcherMock).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should update only the selected tool credential when tools share a provider', async () => {
|
||||
const { getModelConfig } = renderAgentTools([
|
||||
createAgentTool({
|
||||
credential_id: 'credential-search',
|
||||
notAuthor: true,
|
||||
}),
|
||||
createAgentTool({
|
||||
credential_id: 'credential-translate',
|
||||
notAuthor: true,
|
||||
tool_label: 'Translate Tool',
|
||||
tool_name: 'translate',
|
||||
}),
|
||||
])
|
||||
const authorizationButtons = screen.getAllByRole('button', { name: /tools.notAuthorized/ })
|
||||
const secondAuthorizationButton = authorizationButtons[1]
|
||||
if (!secondAuthorizationButton)
|
||||
throw new Error('Second authorization button not found')
|
||||
await userEvent.click(secondAuthorizationButton)
|
||||
settingPanelCredentialId = 'credential-updated'
|
||||
await userEvent.click(screen.getByRole('button', { name: 'auth-from-panel' }))
|
||||
|
||||
await waitFor(() => {
|
||||
const tools = getModelConfig().agentConfig.tools as AgentTool[]
|
||||
expect(tools.map(tool => tool.credential_id)).toEqual([
|
||||
'credential-search',
|
||||
'credential-updated',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it('should reinstate deleted tools after plugin install success event', async () => {
|
||||
const { getModelConfig } = renderAgentTools([
|
||||
createAgentTool({
|
||||
|
||||
@ -136,7 +136,7 @@ const AgentTools: FC = () => {
|
||||
|
||||
const handleAuthorizationItemClick = useCallback((credentialId: string) => {
|
||||
const newModelConfig = produce(modelConfig, (draft) => {
|
||||
const tool = (draft.agentConfig.tools).find((item: any) => item.provider_id === currentTool?.provider_id)
|
||||
const tool = (draft.agentConfig.tools).find((item: any) => item.provider_id === currentTool?.provider_id && item.tool_name === currentTool?.tool_name)
|
||||
if (tool)
|
||||
(tool as AgentTool).credential_id = credentialId
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user