index.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // mock server
  30. export const MOCK_API_PREFIX = 'http://127.0.0.1:3001'
  31. const EDITION = process.env.NEXT_PUBLIC_EDITION || globalThis.document?.body?.getAttribute('data-public-edition')
  32. export const IS_CE_EDITION = EDITION === 'SELF_HOSTED'
  33. export const TONE_LIST = [
  34. {
  35. id: 1,
  36. name: 'Creative',
  37. config: {
  38. temperature: 0.8,
  39. top_p: 0.9,
  40. presence_penalty: 0.1,
  41. frequency_penalty: 0.1,
  42. },
  43. },
  44. {
  45. id: 2,
  46. name: 'Balanced',
  47. config: {
  48. temperature: 0.5,
  49. top_p: 0.85,
  50. presence_penalty: 0.2,
  51. frequency_penalty: 0.3,
  52. },
  53. },
  54. {
  55. id: 3,
  56. name: 'Precise',
  57. config: {
  58. temperature: 0.2,
  59. top_p: 0.75,
  60. presence_penalty: 0.5,
  61. frequency_penalty: 0.5,
  62. },
  63. },
  64. {
  65. id: 4,
  66. name: 'Custom',
  67. },
  68. ]
  69. export const LOCALE_COOKIE_NAME = 'locale'
  70. export const DEFAULT_VALUE_MAX_LEN = 48
  71. export const zhRegex = /^[\u4e00-\u9fa5]$/gm
  72. export const emojiRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/gm
  73. export const emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  74. const MAX_ZN_VAR_NAME_LENGHT = 8
  75. const MAX_EN_VAR_VALUE_LENGHT = 16
  76. export const getMaxVarNameLength = (value: string) => {
  77. if (zhRegex.test(value)) {
  78. return MAX_ZN_VAR_NAME_LENGHT
  79. }
  80. return MAX_EN_VAR_VALUE_LENGHT
  81. }
  82. export const MAX_VAR_KEY_LENGHT = 16
  83. export const VAR_ITEM_TEMPLATE = {
  84. key: '',
  85. name: '',
  86. type: 'string',
  87. max_length: DEFAULT_VALUE_MAX_LEN,
  88. required: true
  89. }