fix(web): agent tool credentials mismatch (#38637)

This commit is contained in:
KVOJJJin 2026-07-10 12:35:52 +08:00 committed by GitHub
parent b325597d29
commit 0038bcc4bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -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({

View File

@ -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
})