mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
Signed-off-by: yyh <yuanyouhuilyz@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: statxc <tyleradams93226@gmail.com>
27 lines
987 B
TypeScript
27 lines
987 B
TypeScript
import type {
|
|
ModelProvider,
|
|
} from '../../declarations'
|
|
import { useMemo } from 'react'
|
|
|
|
export const useCredentialStatus = (provider: ModelProvider | undefined) => {
|
|
const {
|
|
current_credential_id,
|
|
current_credential_name,
|
|
available_credentials,
|
|
} = provider?.custom_configuration ?? {}
|
|
const hasCredential = !!available_credentials?.length
|
|
const authorized = current_credential_id && current_credential_name
|
|
const authRemoved = hasCredential && !current_credential_id && !current_credential_name
|
|
const currentCredential = available_credentials?.find(credential => credential.credential_id === current_credential_id)
|
|
|
|
return useMemo(() => ({
|
|
hasCredential,
|
|
authorized,
|
|
authRemoved,
|
|
current_credential_id,
|
|
current_credential_name,
|
|
available_credentials,
|
|
notAllowedToUse: currentCredential?.not_allowed_to_use,
|
|
}), [hasCredential, authorized, authRemoved, current_credential_id, current_credential_name, available_credentials])
|
|
}
|