index.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* eslint-disable import/no-mutable-exports */
  2. const isDevelopment = process.env.NODE_ENV === 'development'
  3. export let apiPrefix = ''
  4. export let publicApiPrefix = ''
  5. // NEXT_PUBLIC_API_PREFIX=/console/api NEXT_PUBLIC_PUBLIC_API_PREFIX=/api npm run start
  6. if (process.env.NEXT_PUBLIC_API_PREFIX && process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX) {
  7. apiPrefix = process.env.NEXT_PUBLIC_API_PREFIX
  8. publicApiPrefix = process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX
  9. }
  10. else if (
  11. globalThis.document?.body?.getAttribute('data-api-prefix')
  12. && globalThis.document?.body?.getAttribute('data-pubic-api-prefix')
  13. ) {
  14. // Not bulild 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
  15. apiPrefix = globalThis.document.body.getAttribute('data-api-prefix') as string
  16. publicApiPrefix = globalThis.document.body.getAttribute('data-pubic-api-prefix') as string
  17. }
  18. else {
  19. if (isDevelopment) {
  20. apiPrefix = 'https://cloud.dify.dev/console/api'
  21. publicApiPrefix = 'https://dev.udify.app/api'
  22. }
  23. else {
  24. // const domainParts = globalThis.location?.host?.split('.');
  25. // in production env, the host is dify.app . In other env, the host is [dev].dify.app
  26. // const env = domainParts.length === 2 ? 'ai' : domainParts?.[0];
  27. apiPrefix = '/console/api'
  28. publicApiPrefix = '/api' // avoid browser private mode api cross origin
  29. }
  30. }
  31. export const API_PREFIX: string = apiPrefix
  32. export const PUBLIC_API_PREFIX: string = publicApiPrefix
  33. const EDITION = process.env.NEXT_PUBLIC_EDITION || globalThis.document?.body?.getAttribute('data-public-edition')
  34. export const IS_CE_EDITION = EDITION === 'SELF_HOSTED'
  35. export const TONE_LIST = [
  36. {
  37. id: 1,
  38. name: 'Creative',
  39. config: {
  40. temperature: 0.8,
  41. top_p: 0.9,
  42. presence_penalty: 0.1,
  43. frequency_penalty: 0.1,
  44. },
  45. },
  46. {
  47. id: 2,
  48. name: 'Balanced',
  49. config: {
  50. temperature: 0.5,
  51. top_p: 0.85,
  52. presence_penalty: 0.2,
  53. frequency_penalty: 0.3,
  54. },
  55. },
  56. {
  57. id: 3,
  58. name: 'Precise',
  59. config: {
  60. temperature: 0.2,
  61. top_p: 0.75,
  62. presence_penalty: 0.5,
  63. frequency_penalty: 0.5,
  64. },
  65. },
  66. {
  67. id: 4,
  68. name: 'Custom',
  69. },
  70. ]
  71. export const LOCALE_COOKIE_NAME = 'locale'
  72. export const DEFAULT_VALUE_MAX_LEN = 48
  73. export const zhRegex = /^[\u4E00-\u9FA5]$/m
  74. export const emojiRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/m
  75. export const emailRegex = /^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$/m
  76. const MAX_ZN_VAR_NAME_LENGHT = 8
  77. const MAX_EN_VAR_VALUE_LENGHT = 16
  78. export const getMaxVarNameLength = (value: string) => {
  79. if (zhRegex.test(value))
  80. return MAX_ZN_VAR_NAME_LENGHT
  81. return MAX_EN_VAR_VALUE_LENGHT
  82. }
  83. export const MAX_VAR_KEY_LENGHT = 16
  84. export const VAR_ITEM_TEMPLATE = {
  85. key: '',
  86. name: '',
  87. type: 'string',
  88. max_length: DEFAULT_VALUE_MAX_LEN,
  89. required: true,
  90. }
  91. export const appDefaultIconBackground = '#D5F5F6'
  92. export const NEED_REFRESH_APP_LIST_KEY = 'needRefreshAppList'