index.ts 2.9 KB

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