2024-01-29 13:52:29 +04:00
|
|
|
import { option, AuthDefinition } from '@typebot.io/forge'
|
|
|
|
import { defaultBaseUrl } from './constants'
|
2024-02-12 11:41:57 +01:00
|
|
|
import { isURL } from '@typebot.io/lib/validators/isURL'
|
|
|
|
|
|
|
|
const extractBaseUrl = (val: string | undefined) => {
|
|
|
|
if (!val) return val
|
|
|
|
const url = new URL(val)
|
|
|
|
return url.origin
|
|
|
|
}
|
2024-01-29 13:52:29 +04:00
|
|
|
|
|
|
|
export const auth = {
|
|
|
|
type: 'encryptedCredentials',
|
2024-02-16 10:07:29 +01:00
|
|
|
name: 'Dify.AI assistant',
|
2024-01-29 13:52:29 +04:00
|
|
|
schema: option.object({
|
2024-02-12 11:41:57 +01:00
|
|
|
apiEndpoint: option.string
|
|
|
|
.layout({
|
|
|
|
label: 'API Endpoint',
|
|
|
|
isRequired: true,
|
|
|
|
helperText: 'URI where the Service API is hosted.',
|
|
|
|
withVariableButton: false,
|
|
|
|
defaultValue: defaultBaseUrl,
|
|
|
|
})
|
|
|
|
.refine((val) => !val || isURL(val))
|
|
|
|
.transform(extractBaseUrl),
|
2024-01-29 13:52:29 +04:00
|
|
|
apiKey: option.string.layout({
|
|
|
|
label: 'App API key',
|
|
|
|
isRequired: true,
|
|
|
|
helperText: 'API Secret Key for your Dify App.',
|
|
|
|
inputType: 'password',
|
|
|
|
withVariableButton: false,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
} satisfies AuthDefinition
|