@ -1,49 +1,44 @@
import { InputVarType } from '@/app/components/workflow/types'
import { AgentStrategy } from '@/types/app'
import { PromptRole } from '@/models/debug'
import { DatasetAttr } from '@/types/feature'
export let apiPrefix = ''
export let publicApiPrefix = ''
export let marketplaceApiPrefix = ''
export let marketplaceUrlPrefix = ''
// NEXT_PUBLIC_API_PREFIX=/console/api NEXT_PUBLIC_PUBLIC_API_PREFIX=/api npm run start
if ( process . env . NEXT_PUBLIC_API_PREFIX && process . env . NEXT_PUBLIC_PUBLIC_API_PREFIX ) {
apiPrefix = process . env . NEXT_PUBLIC_API_PREFIX
publicApiPrefix = process . env . NEXT_PUBLIC_PUBLIC_API_PREFIX
}
else if (
globalThis . document ? . body ? . getAttribute ( 'data-api-prefix' )
&& globalThis . document ? . body ? . getAttribute ( 'data-pubic-api-prefix' )
) {
// Not build can not get env from process.env.NEXT_PUBLIC_ in browser https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser
apiPrefix = globalThis . document . body . getAttribute ( 'data-api-prefix' ) as string
publicApiPrefix = globalThis . document . body . getAttribute ( 'data-pubic-api-prefix' ) as string
}
else {
// const domainParts = globalThis.location?.host?.split('.');
// in production env, the host is dify.app . In other env, the host is [dev].dify.app
// const env = domainParts.length === 2 ? 'ai' : domainParts?.[0];
apiPrefix = 'http://localhost:5001/console/api'
publicApiPrefix = 'http://localhost:5001/api' // avoid browser private mode api cross origin
marketplaceApiPrefix = 'http://localhost:5002/api'
const getBooleanConfig = ( envVar : string | undefined , dataAttrKey : DatasetAttr , defaultValue : boolean = true ) = > {
if ( envVar !== undefined && envVar !== '' )
return envVar === 'true'
const attrValue = globalThis . document ? . body ? . getAttribute ( dataAttrKey )
if ( attrValue !== undefined && attrValue !== '' )
return attrValue === 'true'
return defaultValue
}
if ( process . env . NEXT_PUBLIC_MARKETPLACE_API_PREFIX && process . env . NEXT_PUBLIC_MARKETPLACE_URL_PREFIX ) {
marketplaceApiPrefix = process . env . NEXT_PUBLIC_MARKETPLACE_API_PREFIX
marketplaceUrlPrefix = process . env . NEXT_PUBLIC_MARKETPLACE_URL_PREFIX
const getNumberConfig = ( envVar : string | undefined , dataAttrKey : DatasetAttr , defaultValue : number ) = > {
if ( envVar )
return Number . parseInt ( envVar )
const attrValue = globalThis . document ? . body ? . getAttribute ( dataAttrKey )
if ( attrValue )
return Number . parseInt ( attrValue )
return defaultValue
}
else {
marketplaceApiPrefix = globalThis . document ? . body ? . getAttribute ( 'data-marketplace-api-prefix' ) || ''
marketplaceUrlPrefix = globalThis . document ? . body ? . getAttribute ( 'data-marketplace-url-prefix' ) || ''
const getStringConfig = ( envVar : string | undefined , dataAttrKey : DatasetAttr , defaultValue : string ) = > {
if ( envVar )
return envVar
const attrValue = globalThis . document ? . body ? . getAttribute ( dataAttrKey )
if ( attrValue )
return attrValue
return defaultValue
}
export const API_PREFIX : string = apiPrefix
export const PUBLIC_API_PREFIX : string = publicApiPrefix
export const MARKETPLACE_API_PREFIX : string = marketplaceApiPrefix
export const MARKETPLACE_URL_PREFIX : string = marketplaceUrlPrefix
export const API_PREFIX = getStringConfig ( process . env . NEXT_PUBLIC_API_PREFIX , DatasetAttr . DATA_API_PREFIX , 'http://localhost:5001/console/api' )
export const PUBLIC_API_PREFIX = getStringConfig ( process . env . NEXT_PUBLIC_PUBLIC_API_PREFIX , DatasetAttr . DATA_PUBLIC_API_PREFIX , 'http://localhost:5001/api' )
export const MARKETPLACE_API_PREFIX = getStringConfig ( process . env . NEXT_PUBLIC_MARKETPLACE_API_PREFIX , DatasetAttr . DATA_MARKETPLACE_API_PREFIX , 'http://localhost:5002/api' )
export const MARKETPLACE_URL_PREFIX = getStringConfig ( process . env . NEXT_PUBLIC_MARKETPLACE_URL_PREFIX , DatasetAttr . DATA_MARKETPLACE_URL_PREFIX , '' )
const EDITION = getStringConfig ( process . env . NEXT_PUBLIC_EDITION , DatasetAttr . DATA_PUBLIC_EDITION , 'SELF_HOSTED' )
const EDITION = process . env . NEXT_PUBLIC_EDITION || globalThis . document ? . body ? . getAttribute ( 'data-public-edition' ) || 'SELF_HOSTED'
export const IS_CE_EDITION = EDITION === 'SELF_HOSTED'
export const IS_CLOUD_EDITION = EDITION === 'CLOUD'
@ -162,15 +157,6 @@ export const ANNOTATION_DEFAULT = {
score_threshold : 0.9 ,
}
export let maxToolsNum = 10
if ( process . env . NEXT_PUBLIC_MAX_TOOLS_NUM && process . env . NEXT_PUBLIC_MAX_TOOLS_NUM !== '' )
maxToolsNum = Number . parseInt ( process . env . NEXT_PUBLIC_MAX_TOOLS_NUM )
else if ( globalThis . document ? . body ? . getAttribute ( 'data-public-max-tools-num' ) && globalThis . document . body . getAttribute ( 'data-public-max-tools-num' ) !== '' )
maxToolsNum = Number . parseInt ( globalThis . document . body . getAttribute ( 'data-public-max-tools-num' ) as string )
export const MAX_TOOLS_NUM = maxToolsNum
export const DEFAULT_AGENT_SETTING = {
enabled : false ,
max_iteration : 10 ,
@ -269,15 +255,6 @@ export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_]\w{0,29}){1,10}#)
export const resetReg = ( ) = > VAR_REGEX . lastIndex = 0
export let textGenerationTimeoutMs = 60000
if ( process . env . NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS && process . env . NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS !== '' )
textGenerationTimeoutMs = Number . parseInt ( process . env . NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS )
else if ( globalThis . document ? . body ? . getAttribute ( 'data-public-text-generation-timeout-ms' ) && globalThis . document . body . getAttribute ( 'data-public-text-generation-timeout-ms' ) !== '' )
textGenerationTimeoutMs = Number . parseInt ( globalThis . document . body . getAttribute ( 'data-public-text-generation-timeout-ms' ) as string )
export const TEXT_GENERATION_TIMEOUT_MS = textGenerationTimeoutMs
export const DISABLE_UPLOAD_IMAGE_AS_ICON = process . env . NEXT_PUBLIC_DISABLE_UPLOAD_IMAGE_AS_ICON === 'true'
export const GITHUB_ACCESS_TOKEN = process . env . NEXT_PUBLIC_GITHUB_ACCESS_TOKEN || ''
@ -286,40 +263,13 @@ export const SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS = '.difypkg,.difybndl'
export const FULL_DOC_PREVIEW_LENGTH = 50
export const JSON_SCHEMA_MAX_DEPTH = 10
let loopNodeMaxCount = 100
if ( process . env . NEXT_PUBLIC_LOOP_NODE_MAX_COUNT && process . env . NEXT_PUBLIC_LOOP_NODE_MAX_COUNT !== '' )
loopNodeMaxCount = Number . parseInt ( process . env . NEXT_PUBLIC_LOOP_NODE_MAX_COUNT )
else if ( globalThis . document ? . body ? . getAttribute ( 'data-public-loop-node-max-count' ) && globalThis . document . body . getAttribute ( 'data-public-loop-node-max-count' ) !== '' )
loopNodeMaxCount = Number . parseInt ( globalThis . document . body . getAttribute ( 'data-public-loop-node-max-count' ) as string )
export const LOOP_NODE_MAX_COUNT = loopNodeMaxCount
let maxIterationsNum = 99
if ( process . env . NEXT_PUBLIC_MAX_ITERATIONS_NUM && process . env . NEXT_PUBLIC_MAX_ITERATIONS_NUM !== '' )
maxIterationsNum = Number . parseInt ( process . env . NEXT_PUBLIC_MAX_ITERATIONS_NUM )
else if ( globalThis . document ? . body ? . getAttribute ( 'data-public-max-iterations-num' ) && globalThis . document . body . getAttribute ( 'data-public-max-iterations-num' ) !== '' )
maxIterationsNum = Number . parseInt ( globalThis . document . body . getAttribute ( 'data-public-max-iterations-num' ) as string )
export const MAX_ITERATIONS_NUM = maxIterationsNum
let enableWebsiteJinaReader = true
let enableWebsiteFireCrawl = true
let enableWebsiteWaterCrawl = false
const getBooleanConfig = ( envVar : string | undefined , attr : string ) = > {
if ( envVar !== undefined && envVar !== '' )
return envVar === 'true'
const attrValue = globalThis . document ? . body ? . getAttribute ( attr )
if ( attrValue !== undefined && attrValue !== '' )
return attrValue === 'true'
return false
}
export const MAX_TOOLS_NUM = getNumberConfig ( process . env . NEXT_PUBLIC_MAX_TOOLS_NUM , DatasetAttr . DATA_PUBLIC_MAX_TOOLS_NUM , 10 )
export const TEXT_GENERATION_TIMEOUT_MS = getNumberConfig ( process . env . NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS , DatasetAttr . DATA_PUBLIC_TEXT_GENERATION_TIMEOUT_MS , 60000 )
export const LOOP_NODE_MAX_COUNT = getNumberConfig ( process . env . NEXT_PUBLIC_LOOP_NODE_MAX_COUNT , DatasetAttr . DATA_PUBLIC_LOOP_NODE_MAX_COUNT , 100 )
export const MAX_ITERATIONS_NUM = getNumberConfig ( process . env . NEXT_PUBLIC_MAX_ITERATIONS_NUM , DatasetAttr . DATA_PUBLIC_MAX_ITERATIONS_NUM , 99 )
export const MAX_TREE_DEPTH = getNumberConfig ( process . env . NEXT_PUBLIC_MAX_TREE_DEPTH , DatasetAttr . DATA_PUBLIC_MAX_TREE_DEPTH , 50 )
enableWebsiteJinaReader = getBooleanConfig ( process . env . NEXT_PUBLIC_ENABLE_WEBSITE_JINAREADER , 'data-public-enable-website-jinareader' )
enableWebsiteFireCrawl = getBooleanConfig ( process . env . NEXT_PUBLIC_ENABLE_WEBSITE_FIRECRAWL , 'data-public-enable-website-firecrawl' )
enableWebsiteWaterCrawl = getBooleanConfig ( process . env . NEXT_PUBLIC_ENABLE_WEBSITE_WATERCRAWL , 'data-public-enable-website-watercrawl' )
export const ENABLE_WEBSITE_JINAREADER = enableWebsiteJinaReader
export const ENABLE_WEBSITE_FIRECRAWL = enableWebsiteFireCrawl
export const ENABLE_WEBSITE_WATERCRAWL = enableWebsiteWaterCrawl
export const ENABLE_WEBSITE_JINAREADER = getBooleanConfig ( process . env . NEXT_PUBLIC_ENABLE_WEBSITE_JINAREADER , DatasetAttr . DATA_PUBLIC_ENABLE_WEBSITE_JINAREADER , true )
export const ENABLE_WEBSITE_FIRECRAWL = getBooleanConfig ( process . env . NEXT_PUBLIC_ENABLE_WEBSITE_FIRECRAWL , DatasetAttr . DATA_PUBLIC_ENABLE_WEBSITE_FIRECRAWL , true )
export const ENABLE_WEBSITE_WATERCRAWL = getBooleanConfig ( process . env . NEXT_PUBLIC_ENABLE_WEBSITE_WATERCRAWL , DatasetAttr . DATA_PUBLIC_ENABLE_WEBSITE_WATERCRAWL , false )