Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

11 місяці тому
7 місяці тому
11 місяці тому
11 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
Introduce Plugins (#13836) Signed-off-by: yihong0618 <zouzou0208@gmail.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: xhe <xw897002528@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: takatost <takatost@gmail.com> Co-authored-by: kurokobo <kuro664@gmail.com> Co-authored-by: Novice Lee <novicelee@NoviPro.local> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: AkaraChen <akarachen@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: Hiroshi Fujita <fujita-h@users.noreply.github.com> Co-authored-by: AkaraChen <85140972+AkaraChen@users.noreply.github.com> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Novice <857526207@qq.com> Co-authored-by: Hiroki Nagai <82458324+nagaihiroki-git@users.noreply.github.com> Co-authored-by: Gen Sato <52241300+halogen22@users.noreply.github.com> Co-authored-by: eux <euxuuu@gmail.com> Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com> Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com> Co-authored-by: lotsik <lotsik@mail.ru> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: gakkiyomi <gakkiyomi@aliyun.com> Co-authored-by: CN-P5 <heibai2006@gmail.com> Co-authored-by: CN-P5 <heibai2006@qq.com> Co-authored-by: Chuehnone <1897025+chuehnone@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Kevin9703 <51311316+Kevin9703@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Boris Feld <lothiraldan@gmail.com> Co-authored-by: mbo <himabo@gmail.com> Co-authored-by: mabo <mabo@aeyes.ai> Co-authored-by: Warren Chen <warren.chen830@gmail.com> Co-authored-by: JzoNgKVO <27049666+JzoNgKVO@users.noreply.github.com> Co-authored-by: jiandanfeng <chenjh3@wangsu.com> Co-authored-by: zhu-an <70234959+xhdd123321@users.noreply.github.com> Co-authored-by: zhaoqingyu.1075 <zhaoqingyu.1075@bytedance.com> Co-authored-by: 海狸大師 <86974027+yenslife@users.noreply.github.com> Co-authored-by: Xu Song <xusong.vip@gmail.com> Co-authored-by: rayshaw001 <396301947@163.com> Co-authored-by: Ding Jiatong <dingjiatong@gmail.com> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: JasonVV <jasonwangiii@outlook.com> Co-authored-by: le0zh <newlight@qq.com> Co-authored-by: zhuxinliang <zhuxinliang@didiglobal.com> Co-authored-by: k-zaku <zaku99@outlook.jp> Co-authored-by: luckylhb90 <luckylhb90@gmail.com> Co-authored-by: hobo.l <hobo.l@binance.com> Co-authored-by: jiangbo721 <365065261@qq.com> Co-authored-by: 刘江波 <jiangbo721@163.com> Co-authored-by: Shun Miyazawa <34241526+miya@users.noreply.github.com> Co-authored-by: EricPan <30651140+Egfly@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Jhvcc <37662342+Jhvcc@users.noreply.github.com> Co-authored-by: lowell <lowell.hu@zkteco.in> Co-authored-by: Boris Polonsky <BorisPolonsky@users.noreply.github.com> Co-authored-by: Ademílson Tonato <ademilsonft@outlook.com> Co-authored-by: Ademílson Tonato <ademilson.tonato@refurbed.com> Co-authored-by: IWAI, Masaharu <iwaim.sub@gmail.com> Co-authored-by: Yueh-Po Peng (Yabi) <94939112+y10ab1@users.noreply.github.com> Co-authored-by: Jason <ggbbddjm@gmail.com> Co-authored-by: Xin Zhang <sjhpzx@gmail.com> Co-authored-by: yjc980121 <3898524+yjc980121@users.noreply.github.com> Co-authored-by: heyszt <36215648+hieheihei@users.noreply.github.com> Co-authored-by: Abdullah AlOsaimi <osaimiacc@gmail.com> Co-authored-by: Abdullah AlOsaimi <189027247+osaimi@users.noreply.github.com> Co-authored-by: Yingchun Lai <laiyingchun@apache.org> Co-authored-by: Hash Brown <hi@xzd.me> Co-authored-by: zuodongxu <192560071+zuodongxu@users.noreply.github.com> Co-authored-by: Masashi Tomooka <tmokmss@users.noreply.github.com> Co-authored-by: aplio <ryo.091219@gmail.com> Co-authored-by: Obada Khalili <54270856+obadakhalili@users.noreply.github.com> Co-authored-by: Nam Vu <zuzoovn@gmail.com> Co-authored-by: Kei YAMAZAKI <1715090+kei-yamazaki@users.noreply.github.com> Co-authored-by: TechnoHouse <13776377+deephbz@users.noreply.github.com> Co-authored-by: Riddhimaan-Senapati <114703025+Riddhimaan-Senapati@users.noreply.github.com> Co-authored-by: MaFee921 <31881301+2284730142@users.noreply.github.com> Co-authored-by: te-chan <t-nakanome@sakura-is.co.jp> Co-authored-by: HQidea <HQidea@users.noreply.github.com> Co-authored-by: Joshbly <36315710+Joshbly@users.noreply.github.com> Co-authored-by: xhe <xw897002528@gmail.com> Co-authored-by: weiwenyan-dev <154779315+weiwenyan-dev@users.noreply.github.com> Co-authored-by: ex_wenyan.wei <ex_wenyan.wei@tcl.com> Co-authored-by: engchina <12236799+engchina@users.noreply.github.com> Co-authored-by: engchina <atjapan2015@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: Kemal <kemalmeler@outlook.com> Co-authored-by: Lazy_Frog <4590648+lazyFrogLOL@users.noreply.github.com> Co-authored-by: Yi Xiao <54782454+YIXIAO0@users.noreply.github.com> Co-authored-by: Steven sun <98230804+Tuyohai@users.noreply.github.com> Co-authored-by: steven <sunzwj@digitalchina.com> Co-authored-by: Kalo Chin <91766386+fdb02983rhy@users.noreply.github.com> Co-authored-by: Katy Tao <34019945+KatyTao@users.noreply.github.com> Co-authored-by: depy <42985524+h4ckdepy@users.noreply.github.com> Co-authored-by: 胡春东 <gycm520@gmail.com> Co-authored-by: Junjie.M <118170653@qq.com> Co-authored-by: MuYu <mr.muzea@gmail.com> Co-authored-by: Naoki Takashima <39912547+takatea@users.noreply.github.com> Co-authored-by: Summer-Gu <37869445+gubinjie@users.noreply.github.com> Co-authored-by: Fei He <droxer.he@gmail.com> Co-authored-by: ybalbert001 <120714773+ybalbert001@users.noreply.github.com> Co-authored-by: Yuanbo Li <ybalbert@amazon.com> Co-authored-by: douxc <7553076+douxc@users.noreply.github.com> Co-authored-by: liuzhenghua <1090179900@qq.com> Co-authored-by: Wu Jiayang <62842862+Wu-Jiayang@users.noreply.github.com> Co-authored-by: Your Name <you@example.com> Co-authored-by: kimjion <45935338+kimjion@users.noreply.github.com> Co-authored-by: AugNSo <song.tiankai@icloud.com> Co-authored-by: llinvokerl <38915183+llinvokerl@users.noreply.github.com> Co-authored-by: liusurong.lsr <liusurong.lsr@alibaba-inc.com> Co-authored-by: Vasu Negi <vasu-negi@users.noreply.github.com> Co-authored-by: Hundredwz <1808096180@qq.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
8 місяці тому
11 місяці тому
7 місяці тому
Introduce Plugins (#13836) Signed-off-by: yihong0618 <zouzou0208@gmail.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: xhe <xw897002528@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: takatost <takatost@gmail.com> Co-authored-by: kurokobo <kuro664@gmail.com> Co-authored-by: Novice Lee <novicelee@NoviPro.local> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: AkaraChen <akarachen@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: Hiroshi Fujita <fujita-h@users.noreply.github.com> Co-authored-by: AkaraChen <85140972+AkaraChen@users.noreply.github.com> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Novice <857526207@qq.com> Co-authored-by: Hiroki Nagai <82458324+nagaihiroki-git@users.noreply.github.com> Co-authored-by: Gen Sato <52241300+halogen22@users.noreply.github.com> Co-authored-by: eux <euxuuu@gmail.com> Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com> Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com> Co-authored-by: lotsik <lotsik@mail.ru> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: gakkiyomi <gakkiyomi@aliyun.com> Co-authored-by: CN-P5 <heibai2006@gmail.com> Co-authored-by: CN-P5 <heibai2006@qq.com> Co-authored-by: Chuehnone <1897025+chuehnone@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Kevin9703 <51311316+Kevin9703@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Boris Feld <lothiraldan@gmail.com> Co-authored-by: mbo <himabo@gmail.com> Co-authored-by: mabo <mabo@aeyes.ai> Co-authored-by: Warren Chen <warren.chen830@gmail.com> Co-authored-by: JzoNgKVO <27049666+JzoNgKVO@users.noreply.github.com> Co-authored-by: jiandanfeng <chenjh3@wangsu.com> Co-authored-by: zhu-an <70234959+xhdd123321@users.noreply.github.com> Co-authored-by: zhaoqingyu.1075 <zhaoqingyu.1075@bytedance.com> Co-authored-by: 海狸大師 <86974027+yenslife@users.noreply.github.com> Co-authored-by: Xu Song <xusong.vip@gmail.com> Co-authored-by: rayshaw001 <396301947@163.com> Co-authored-by: Ding Jiatong <dingjiatong@gmail.com> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: JasonVV <jasonwangiii@outlook.com> Co-authored-by: le0zh <newlight@qq.com> Co-authored-by: zhuxinliang <zhuxinliang@didiglobal.com> Co-authored-by: k-zaku <zaku99@outlook.jp> Co-authored-by: luckylhb90 <luckylhb90@gmail.com> Co-authored-by: hobo.l <hobo.l@binance.com> Co-authored-by: jiangbo721 <365065261@qq.com> Co-authored-by: 刘江波 <jiangbo721@163.com> Co-authored-by: Shun Miyazawa <34241526+miya@users.noreply.github.com> Co-authored-by: EricPan <30651140+Egfly@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Jhvcc <37662342+Jhvcc@users.noreply.github.com> Co-authored-by: lowell <lowell.hu@zkteco.in> Co-authored-by: Boris Polonsky <BorisPolonsky@users.noreply.github.com> Co-authored-by: Ademílson Tonato <ademilsonft@outlook.com> Co-authored-by: Ademílson Tonato <ademilson.tonato@refurbed.com> Co-authored-by: IWAI, Masaharu <iwaim.sub@gmail.com> Co-authored-by: Yueh-Po Peng (Yabi) <94939112+y10ab1@users.noreply.github.com> Co-authored-by: Jason <ggbbddjm@gmail.com> Co-authored-by: Xin Zhang <sjhpzx@gmail.com> Co-authored-by: yjc980121 <3898524+yjc980121@users.noreply.github.com> Co-authored-by: heyszt <36215648+hieheihei@users.noreply.github.com> Co-authored-by: Abdullah AlOsaimi <osaimiacc@gmail.com> Co-authored-by: Abdullah AlOsaimi <189027247+osaimi@users.noreply.github.com> Co-authored-by: Yingchun Lai <laiyingchun@apache.org> Co-authored-by: Hash Brown <hi@xzd.me> Co-authored-by: zuodongxu <192560071+zuodongxu@users.noreply.github.com> Co-authored-by: Masashi Tomooka <tmokmss@users.noreply.github.com> Co-authored-by: aplio <ryo.091219@gmail.com> Co-authored-by: Obada Khalili <54270856+obadakhalili@users.noreply.github.com> Co-authored-by: Nam Vu <zuzoovn@gmail.com> Co-authored-by: Kei YAMAZAKI <1715090+kei-yamazaki@users.noreply.github.com> Co-authored-by: TechnoHouse <13776377+deephbz@users.noreply.github.com> Co-authored-by: Riddhimaan-Senapati <114703025+Riddhimaan-Senapati@users.noreply.github.com> Co-authored-by: MaFee921 <31881301+2284730142@users.noreply.github.com> Co-authored-by: te-chan <t-nakanome@sakura-is.co.jp> Co-authored-by: HQidea <HQidea@users.noreply.github.com> Co-authored-by: Joshbly <36315710+Joshbly@users.noreply.github.com> Co-authored-by: xhe <xw897002528@gmail.com> Co-authored-by: weiwenyan-dev <154779315+weiwenyan-dev@users.noreply.github.com> Co-authored-by: ex_wenyan.wei <ex_wenyan.wei@tcl.com> Co-authored-by: engchina <12236799+engchina@users.noreply.github.com> Co-authored-by: engchina <atjapan2015@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: Kemal <kemalmeler@outlook.com> Co-authored-by: Lazy_Frog <4590648+lazyFrogLOL@users.noreply.github.com> Co-authored-by: Yi Xiao <54782454+YIXIAO0@users.noreply.github.com> Co-authored-by: Steven sun <98230804+Tuyohai@users.noreply.github.com> Co-authored-by: steven <sunzwj@digitalchina.com> Co-authored-by: Kalo Chin <91766386+fdb02983rhy@users.noreply.github.com> Co-authored-by: Katy Tao <34019945+KatyTao@users.noreply.github.com> Co-authored-by: depy <42985524+h4ckdepy@users.noreply.github.com> Co-authored-by: 胡春东 <gycm520@gmail.com> Co-authored-by: Junjie.M <118170653@qq.com> Co-authored-by: MuYu <mr.muzea@gmail.com> Co-authored-by: Naoki Takashima <39912547+takatea@users.noreply.github.com> Co-authored-by: Summer-Gu <37869445+gubinjie@users.noreply.github.com> Co-authored-by: Fei He <droxer.he@gmail.com> Co-authored-by: ybalbert001 <120714773+ybalbert001@users.noreply.github.com> Co-authored-by: Yuanbo Li <ybalbert@amazon.com> Co-authored-by: douxc <7553076+douxc@users.noreply.github.com> Co-authored-by: liuzhenghua <1090179900@qq.com> Co-authored-by: Wu Jiayang <62842862+Wu-Jiayang@users.noreply.github.com> Co-authored-by: Your Name <you@example.com> Co-authored-by: kimjion <45935338+kimjion@users.noreply.github.com> Co-authored-by: AugNSo <song.tiankai@icloud.com> Co-authored-by: llinvokerl <38915183+llinvokerl@users.noreply.github.com> Co-authored-by: liusurong.lsr <liusurong.lsr@alibaba-inc.com> Co-authored-by: Vasu Negi <vasu-negi@users.noreply.github.com> Co-authored-by: Hundredwz <1808096180@qq.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
8 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
11 місяці тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. from enum import StrEnum
  2. from pydantic import BaseModel, ConfigDict, Field
  3. from configs import dify_config
  4. from services.billing_service import BillingService
  5. from services.enterprise.enterprise_service import EnterpriseService
  6. class SubscriptionModel(BaseModel):
  7. plan: str = "sandbox"
  8. interval: str = ""
  9. class BillingModel(BaseModel):
  10. enabled: bool = False
  11. subscription: SubscriptionModel = SubscriptionModel()
  12. class EducationModel(BaseModel):
  13. enabled: bool = False
  14. activated: bool = False
  15. class LimitationModel(BaseModel):
  16. size: int = 0
  17. limit: int = 0
  18. class LicenseLimitationModel(BaseModel):
  19. """
  20. - enabled: whether this limit is enforced
  21. - size: current usage count
  22. - limit: maximum allowed count; 0 means unlimited
  23. """
  24. enabled: bool = Field(False, description="Whether this limit is currently active")
  25. size: int = Field(0, description="Number of resources already consumed")
  26. limit: int = Field(0, description="Maximum number of resources allowed; 0 means no limit")
  27. def is_available(self, required: int = 1) -> bool:
  28. """
  29. Determine whether the requested amount can be allocated.
  30. Returns True if:
  31. - this limit is not active, or
  32. - the limit is zero (unlimited), or
  33. - there is enough remaining quota.
  34. """
  35. if not self.enabled or self.limit == 0:
  36. return True
  37. return (self.limit - self.size) >= required
  38. class LicenseStatus(StrEnum):
  39. NONE = "none"
  40. INACTIVE = "inactive"
  41. ACTIVE = "active"
  42. EXPIRING = "expiring"
  43. EXPIRED = "expired"
  44. LOST = "lost"
  45. class LicenseModel(BaseModel):
  46. status: LicenseStatus = LicenseStatus.NONE
  47. expired_at: str = ""
  48. workspaces: LicenseLimitationModel = LicenseLimitationModel(enabled=False, size=0, limit=0)
  49. class BrandingModel(BaseModel):
  50. enabled: bool = False
  51. application_title: str = ""
  52. login_page_logo: str = ""
  53. workspace_logo: str = ""
  54. favicon: str = ""
  55. class WebAppAuthSSOModel(BaseModel):
  56. protocol: str = ""
  57. class WebAppAuthModel(BaseModel):
  58. enabled: bool = False
  59. allow_sso: bool = False
  60. sso_config: WebAppAuthSSOModel = WebAppAuthSSOModel()
  61. allow_email_code_login: bool = False
  62. allow_email_password_login: bool = False
  63. class KnowledgePipeline(BaseModel):
  64. publish_enabled: bool = False
  65. class PluginInstallationScope(StrEnum):
  66. NONE = "none"
  67. OFFICIAL_ONLY = "official_only"
  68. OFFICIAL_AND_SPECIFIC_PARTNERS = "official_and_specific_partners"
  69. ALL = "all"
  70. class PluginInstallationPermissionModel(BaseModel):
  71. # Plugin installation scope – possible values:
  72. # none: prohibit all plugin installations
  73. # official_only: allow only Dify official plugins
  74. # official_and_specific_partners: allow official and specific partner plugins
  75. # all: allow installation of all plugins
  76. plugin_installation_scope: PluginInstallationScope = PluginInstallationScope.ALL
  77. # If True, restrict plugin installation to the marketplace only
  78. # Equivalent to ForceEnablePluginVerification
  79. restrict_to_marketplace_only: bool = False
  80. class FeatureModel(BaseModel):
  81. billing: BillingModel = BillingModel()
  82. education: EducationModel = EducationModel()
  83. members: LimitationModel = LimitationModel(size=0, limit=1)
  84. apps: LimitationModel = LimitationModel(size=0, limit=10)
  85. vector_space: LimitationModel = LimitationModel(size=0, limit=5)
  86. knowledge_rate_limit: int = 10
  87. annotation_quota_limit: LimitationModel = LimitationModel(size=0, limit=10)
  88. documents_upload_quota: LimitationModel = LimitationModel(size=0, limit=50)
  89. docs_processing: str = "standard"
  90. can_replace_logo: bool = False
  91. model_load_balancing_enabled: bool = False
  92. dataset_operator_enabled: bool = False
  93. webapp_copyright_enabled: bool = False
  94. workspace_members: LicenseLimitationModel = LicenseLimitationModel(enabled=False, size=0, limit=0)
  95. is_allow_transfer_workspace: bool = True
  96. # pydantic configs
  97. model_config = ConfigDict(protected_namespaces=())
  98. knowledge_pipeline: KnowledgePipeline = KnowledgePipeline()
  99. class KnowledgeRateLimitModel(BaseModel):
  100. enabled: bool = False
  101. limit: int = 10
  102. subscription_plan: str = ""
  103. class PluginManagerModel(BaseModel):
  104. enabled: bool = False
  105. class SystemFeatureModel(BaseModel):
  106. sso_enforced_for_signin: bool = False
  107. sso_enforced_for_signin_protocol: str = ""
  108. enable_marketplace: bool = False
  109. max_plugin_package_size: int = dify_config.PLUGIN_MAX_PACKAGE_SIZE
  110. enable_email_code_login: bool = False
  111. enable_email_password_login: bool = True
  112. enable_social_oauth_login: bool = False
  113. is_allow_register: bool = False
  114. is_allow_create_workspace: bool = False
  115. is_email_setup: bool = False
  116. license: LicenseModel = LicenseModel()
  117. branding: BrandingModel = BrandingModel()
  118. webapp_auth: WebAppAuthModel = WebAppAuthModel()
  119. plugin_installation_permission: PluginInstallationPermissionModel = PluginInstallationPermissionModel()
  120. enable_change_email: bool = True
  121. plugin_manager: PluginManagerModel = PluginManagerModel()
  122. class FeatureService:
  123. @classmethod
  124. def get_features(cls, tenant_id: str) -> FeatureModel:
  125. features = FeatureModel()
  126. cls._fulfill_params_from_env(features)
  127. if dify_config.BILLING_ENABLED and tenant_id:
  128. cls._fulfill_params_from_billing_api(features, tenant_id)
  129. if dify_config.ENTERPRISE_ENABLED:
  130. features.webapp_copyright_enabled = True
  131. cls._fulfill_params_from_workspace_info(features, tenant_id)
  132. return features
  133. @classmethod
  134. def get_knowledge_rate_limit(cls, tenant_id: str):
  135. knowledge_rate_limit = KnowledgeRateLimitModel()
  136. if dify_config.BILLING_ENABLED and tenant_id:
  137. knowledge_rate_limit.enabled = True
  138. limit_info = BillingService.get_knowledge_rate_limit(tenant_id)
  139. knowledge_rate_limit.limit = limit_info.get("limit", 10)
  140. knowledge_rate_limit.subscription_plan = limit_info.get("subscription_plan", "sandbox")
  141. return knowledge_rate_limit
  142. @classmethod
  143. def get_system_features(cls) -> SystemFeatureModel:
  144. system_features = SystemFeatureModel()
  145. cls._fulfill_system_params_from_env(system_features)
  146. if dify_config.ENTERPRISE_ENABLED:
  147. system_features.branding.enabled = True
  148. system_features.webapp_auth.enabled = True
  149. system_features.enable_change_email = False
  150. system_features.plugin_manager.enabled = True
  151. cls._fulfill_params_from_enterprise(system_features)
  152. if dify_config.MARKETPLACE_ENABLED:
  153. system_features.enable_marketplace = True
  154. return system_features
  155. @classmethod
  156. def _fulfill_system_params_from_env(cls, system_features: SystemFeatureModel):
  157. system_features.enable_email_code_login = dify_config.ENABLE_EMAIL_CODE_LOGIN
  158. system_features.enable_email_password_login = dify_config.ENABLE_EMAIL_PASSWORD_LOGIN
  159. system_features.enable_social_oauth_login = dify_config.ENABLE_SOCIAL_OAUTH_LOGIN
  160. system_features.is_allow_register = dify_config.ALLOW_REGISTER
  161. system_features.is_allow_create_workspace = dify_config.ALLOW_CREATE_WORKSPACE
  162. system_features.is_email_setup = dify_config.MAIL_TYPE is not None and dify_config.MAIL_TYPE != ""
  163. @classmethod
  164. def _fulfill_params_from_env(cls, features: FeatureModel):
  165. features.can_replace_logo = dify_config.CAN_REPLACE_LOGO
  166. features.model_load_balancing_enabled = dify_config.MODEL_LB_ENABLED
  167. features.dataset_operator_enabled = dify_config.DATASET_OPERATOR_ENABLED
  168. features.education.enabled = dify_config.EDUCATION_ENABLED
  169. @classmethod
  170. def _fulfill_params_from_workspace_info(cls, features: FeatureModel, tenant_id: str):
  171. workspace_info = EnterpriseService.get_workspace_info(tenant_id)
  172. if "WorkspaceMembers" in workspace_info:
  173. features.workspace_members.size = workspace_info["WorkspaceMembers"]["used"]
  174. features.workspace_members.limit = workspace_info["WorkspaceMembers"]["limit"]
  175. features.workspace_members.enabled = workspace_info["WorkspaceMembers"]["enabled"]
  176. @classmethod
  177. def _fulfill_params_from_billing_api(cls, features: FeatureModel, tenant_id: str):
  178. billing_info = BillingService.get_info(tenant_id)
  179. features.billing.enabled = billing_info["enabled"]
  180. features.billing.subscription.plan = billing_info["subscription"]["plan"]
  181. features.billing.subscription.interval = billing_info["subscription"]["interval"]
  182. features.education.activated = billing_info["subscription"].get("education", False)
  183. if features.billing.subscription.plan != "sandbox":
  184. features.webapp_copyright_enabled = True
  185. else:
  186. features.is_allow_transfer_workspace = False
  187. if "members" in billing_info:
  188. features.members.size = billing_info["members"]["size"]
  189. features.members.limit = billing_info["members"]["limit"]
  190. if "apps" in billing_info:
  191. features.apps.size = billing_info["apps"]["size"]
  192. features.apps.limit = billing_info["apps"]["limit"]
  193. if "vector_space" in billing_info:
  194. features.vector_space.size = billing_info["vector_space"]["size"]
  195. features.vector_space.limit = billing_info["vector_space"]["limit"]
  196. if "documents_upload_quota" in billing_info:
  197. features.documents_upload_quota.size = billing_info["documents_upload_quota"]["size"]
  198. features.documents_upload_quota.limit = billing_info["documents_upload_quota"]["limit"]
  199. if "annotation_quota_limit" in billing_info:
  200. features.annotation_quota_limit.size = billing_info["annotation_quota_limit"]["size"]
  201. features.annotation_quota_limit.limit = billing_info["annotation_quota_limit"]["limit"]
  202. if "docs_processing" in billing_info:
  203. features.docs_processing = billing_info["docs_processing"]
  204. if "can_replace_logo" in billing_info:
  205. features.can_replace_logo = billing_info["can_replace_logo"]
  206. if "model_load_balancing_enabled" in billing_info:
  207. features.model_load_balancing_enabled = billing_info["model_load_balancing_enabled"]
  208. if "knowledge_rate_limit" in billing_info:
  209. features.knowledge_rate_limit = billing_info["knowledge_rate_limit"]["limit"]
  210. if "knowledge_pipeline_publish_enabled" in billing_info:
  211. features.knowledge_pipeline.publish_enabled = billing_info["knowledge_pipeline_publish_enabled"]
  212. @classmethod
  213. def _fulfill_params_from_enterprise(cls, features: SystemFeatureModel):
  214. enterprise_info = EnterpriseService.get_info()
  215. if "SSOEnforcedForSignin" in enterprise_info:
  216. features.sso_enforced_for_signin = enterprise_info["SSOEnforcedForSignin"]
  217. if "SSOEnforcedForSigninProtocol" in enterprise_info:
  218. features.sso_enforced_for_signin_protocol = enterprise_info["SSOEnforcedForSigninProtocol"]
  219. if "EnableEmailCodeLogin" in enterprise_info:
  220. features.enable_email_code_login = enterprise_info["EnableEmailCodeLogin"]
  221. if "EnableEmailPasswordLogin" in enterprise_info:
  222. features.enable_email_password_login = enterprise_info["EnableEmailPasswordLogin"]
  223. if "IsAllowRegister" in enterprise_info:
  224. features.is_allow_register = enterprise_info["IsAllowRegister"]
  225. if "IsAllowCreateWorkspace" in enterprise_info:
  226. features.is_allow_create_workspace = enterprise_info["IsAllowCreateWorkspace"]
  227. if "Branding" in enterprise_info:
  228. features.branding.application_title = enterprise_info["Branding"].get("applicationTitle", "")
  229. features.branding.login_page_logo = enterprise_info["Branding"].get("loginPageLogo", "")
  230. features.branding.workspace_logo = enterprise_info["Branding"].get("workspaceLogo", "")
  231. features.branding.favicon = enterprise_info["Branding"].get("favicon", "")
  232. if "WebAppAuth" in enterprise_info:
  233. features.webapp_auth.allow_sso = enterprise_info["WebAppAuth"].get("allowSso", False)
  234. features.webapp_auth.allow_email_code_login = enterprise_info["WebAppAuth"].get(
  235. "allowEmailCodeLogin", False
  236. )
  237. features.webapp_auth.allow_email_password_login = enterprise_info["WebAppAuth"].get(
  238. "allowEmailPasswordLogin", False
  239. )
  240. features.webapp_auth.sso_config.protocol = enterprise_info.get("SSOEnforcedForWebProtocol", "")
  241. if "License" in enterprise_info:
  242. license_info = enterprise_info["License"]
  243. if "status" in license_info:
  244. features.license.status = LicenseStatus(license_info.get("status", LicenseStatus.INACTIVE))
  245. if "expiredAt" in license_info:
  246. features.license.expired_at = license_info["expiredAt"]
  247. if "workspaces" in license_info:
  248. features.license.workspaces.enabled = license_info["workspaces"]["enabled"]
  249. features.license.workspaces.limit = license_info["workspaces"]["limit"]
  250. features.license.workspaces.size = license_info["workspaces"]["used"]
  251. if "PluginInstallationPermission" in enterprise_info:
  252. plugin_installation_info = enterprise_info["PluginInstallationPermission"]
  253. features.plugin_installation_permission.plugin_installation_scope = plugin_installation_info[
  254. "pluginInstallationScope"
  255. ]
  256. features.plugin_installation_permission.restrict_to_marketplace_only = plugin_installation_info[
  257. "restrictToMarketplaceOnly"
  258. ]