You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

declarations.ts 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import type { SchemaRoot } from '@/app/components/workflow/nodes/llm/types'
  2. export type FormValue = Record<string, any>
  3. export type TypeWithI18N<T = string> = {
  4. en_US: T
  5. zh_Hans: T
  6. [key: string]: T
  7. }
  8. export enum FormTypeEnum {
  9. textInput = 'text-input',
  10. textNumber = 'number-input',
  11. secretInput = 'secret-input',
  12. select = 'select',
  13. radio = 'radio',
  14. boolean = 'boolean',
  15. files = 'files',
  16. file = 'file',
  17. modelSelector = 'model-selector',
  18. toolSelector = 'tool-selector',
  19. multiToolSelector = 'array[tools]',
  20. appSelector = 'app-selector',
  21. any = 'any',
  22. object = 'object',
  23. array = 'array',
  24. dynamicSelect = 'dynamic-select',
  25. }
  26. export type FormOption = {
  27. label: TypeWithI18N
  28. value: string
  29. show_on: FormShowOnObject[]
  30. icon?: string
  31. }
  32. export enum ModelTypeEnum {
  33. textGeneration = 'llm',
  34. textEmbedding = 'text-embedding',
  35. rerank = 'rerank',
  36. speech2text = 'speech2text',
  37. moderation = 'moderation',
  38. tts = 'tts',
  39. }
  40. export const MODEL_TYPE_TEXT = {
  41. [ModelTypeEnum.textGeneration]: 'LLM',
  42. [ModelTypeEnum.textEmbedding]: 'Text Embedding',
  43. [ModelTypeEnum.rerank]: 'Rerank',
  44. [ModelTypeEnum.speech2text]: 'Speech2text',
  45. [ModelTypeEnum.moderation]: 'Moderation',
  46. [ModelTypeEnum.tts]: 'TTS',
  47. }
  48. export enum ConfigurationMethodEnum {
  49. predefinedModel = 'predefined-model',
  50. customizableModel = 'customizable-model',
  51. fetchFromRemote = 'fetch-from-remote',
  52. }
  53. export enum ModelFeatureEnum {
  54. toolCall = 'tool-call',
  55. multiToolCall = 'multi-tool-call',
  56. agentThought = 'agent-thought',
  57. streamToolCall = 'stream-tool-call',
  58. vision = 'vision',
  59. video = 'video',
  60. document = 'document',
  61. audio = 'audio',
  62. StructuredOutput = 'structured-output',
  63. }
  64. export enum ModelFeatureTextEnum {
  65. toolCall = 'Tool Call',
  66. multiToolCall = 'Multi Tool Call',
  67. agentThought = 'Agent Thought',
  68. vision = 'Vision',
  69. video = 'Video',
  70. document = 'Document',
  71. audio = 'Audio',
  72. }
  73. export enum ModelStatusEnum {
  74. active = 'active',
  75. noConfigure = 'no-configure',
  76. quotaExceeded = 'quota-exceeded',
  77. noPermission = 'no-permission',
  78. disabled = 'disabled',
  79. credentialRemoved = 'credential-removed',
  80. }
  81. export const MODEL_STATUS_TEXT: { [k: string]: TypeWithI18N } = {
  82. 'no-configure': {
  83. en_US: 'No Configure',
  84. zh_Hans: '未配置凭据',
  85. },
  86. 'quota-exceeded': {
  87. en_US: 'Quota Exceeded',
  88. zh_Hans: '额度不足',
  89. },
  90. 'no-permission': {
  91. en_US: 'No Permission',
  92. zh_Hans: '无使用权限',
  93. },
  94. }
  95. export enum CustomConfigurationStatusEnum {
  96. active = 'active',
  97. noConfigure = 'no-configure',
  98. }
  99. export type FormShowOnObject = {
  100. variable: string
  101. value: string
  102. }
  103. export type CredentialFormSchemaBase = {
  104. name: string
  105. variable: string
  106. label: TypeWithI18N
  107. type: FormTypeEnum
  108. required: boolean
  109. default?: string
  110. tooltip?: TypeWithI18N
  111. show_on: FormShowOnObject[]
  112. url?: string
  113. scope?: string
  114. input_schema?: SchemaRoot
  115. }
  116. export type CredentialFormSchemaTextInput = CredentialFormSchemaBase & {
  117. max_length?: number;
  118. placeholder?: TypeWithI18N,
  119. template?: {
  120. enabled: boolean
  121. },
  122. auto_generate?: {
  123. type: string
  124. }
  125. }
  126. export type CredentialFormSchemaNumberInput = CredentialFormSchemaBase & { min?: number; max?: number; placeholder?: TypeWithI18N }
  127. export type CredentialFormSchemaSelect = CredentialFormSchemaBase & { options: FormOption[]; placeholder?: TypeWithI18N }
  128. export type CredentialFormSchemaRadio = CredentialFormSchemaBase & { options: FormOption[] }
  129. export type CredentialFormSchemaSecretInput = CredentialFormSchemaBase & { placeholder?: TypeWithI18N }
  130. export type CredentialFormSchema = CredentialFormSchemaTextInput | CredentialFormSchemaSelect | CredentialFormSchemaRadio | CredentialFormSchemaSecretInput
  131. export type ModelItem = {
  132. model: string
  133. label: TypeWithI18N
  134. model_type: ModelTypeEnum
  135. features?: ModelFeatureEnum[]
  136. fetch_from: ConfigurationMethodEnum
  137. status: ModelStatusEnum
  138. model_properties: Record<string, string | number>
  139. load_balancing_enabled: boolean
  140. deprecated?: boolean
  141. has_invalid_load_balancing_configs?: boolean
  142. }
  143. export enum PreferredProviderTypeEnum {
  144. system = 'system',
  145. custom = 'custom',
  146. }
  147. export enum CurrentSystemQuotaTypeEnum {
  148. trial = 'trial',
  149. free = 'free',
  150. paid = 'paid',
  151. }
  152. export enum QuotaUnitEnum {
  153. times = 'times',
  154. tokens = 'tokens',
  155. credits = 'credits',
  156. }
  157. export type QuotaConfiguration = {
  158. quota_type: CurrentSystemQuotaTypeEnum
  159. quota_unit: QuotaUnitEnum
  160. quota_limit: number
  161. quota_used: number
  162. last_used: number
  163. is_valid: boolean
  164. }
  165. export type Credential = {
  166. credential_id: string
  167. credential_name?: string
  168. from_enterprise?: boolean
  169. not_allowed_to_use?: boolean
  170. }
  171. export type CustomModel = {
  172. model: string
  173. model_type: ModelTypeEnum
  174. }
  175. export type CustomModelCredential = CustomModel & {
  176. credentials?: Record<string, any>
  177. available_model_credentials?: Credential[]
  178. current_credential_id?: string
  179. }
  180. export type CredentialWithModel = Credential & {
  181. model: string
  182. model_type: ModelTypeEnum
  183. }
  184. export type ModelProvider = {
  185. provider: string
  186. label: TypeWithI18N
  187. description?: TypeWithI18N
  188. help: {
  189. title: TypeWithI18N
  190. url: TypeWithI18N
  191. }
  192. icon_small: TypeWithI18N
  193. icon_large: TypeWithI18N
  194. background?: string
  195. supported_model_types: ModelTypeEnum[]
  196. configurate_methods: ConfigurationMethodEnum[]
  197. provider_credential_schema: {
  198. credential_form_schemas: CredentialFormSchema[]
  199. }
  200. model_credential_schema: {
  201. model: {
  202. label: TypeWithI18N
  203. placeholder: TypeWithI18N
  204. }
  205. credential_form_schemas: CredentialFormSchema[]
  206. }
  207. preferred_provider_type: PreferredProviderTypeEnum
  208. custom_configuration: {
  209. status: CustomConfigurationStatusEnum
  210. current_credential_id?: string
  211. current_credential_name?: string
  212. available_credentials?: Credential[]
  213. custom_models?: CustomModelCredential[]
  214. }
  215. system_configuration: {
  216. enabled: boolean
  217. current_quota_type: CurrentSystemQuotaTypeEnum
  218. quota_configurations: QuotaConfiguration[]
  219. }
  220. allow_custom_token?: boolean
  221. }
  222. export type Model = {
  223. provider: string
  224. icon_large: TypeWithI18N
  225. icon_small: TypeWithI18N
  226. label: TypeWithI18N
  227. models: ModelItem[]
  228. status: ModelStatusEnum
  229. }
  230. export type DefaultModelResponse = {
  231. model: string
  232. model_type: ModelTypeEnum
  233. provider: {
  234. provider: string
  235. icon_large: TypeWithI18N
  236. icon_small: TypeWithI18N
  237. }
  238. }
  239. export type DefaultModel = {
  240. provider: string
  241. model: string
  242. }
  243. export type CustomConfigurationModelFixedFields = {
  244. __model_name: string
  245. __model_type: ModelTypeEnum
  246. }
  247. export type ModelParameterRule = {
  248. default?: number | string | boolean | string[]
  249. help?: TypeWithI18N
  250. label: TypeWithI18N
  251. min?: number
  252. max?: number
  253. name: string
  254. precision?: number
  255. required: false
  256. type: string
  257. use_template?: string
  258. options?: string[]
  259. tagPlaceholder?: TypeWithI18N
  260. }
  261. export type ModelLoadBalancingConfigEntry = {
  262. /** model balancing config entry id */
  263. id?: string
  264. /** is config entry enabled */
  265. enabled?: boolean
  266. /** config entry name */
  267. name: string
  268. /** model balancing credential */
  269. credentials: Record<string, string | undefined | boolean>
  270. /** is config entry currently removed from Round-robin queue */
  271. in_cooldown?: boolean
  272. /** cooldown time (in seconds) */
  273. ttl?: number
  274. credential_id?: string
  275. }
  276. export type ModelLoadBalancingConfig = {
  277. enabled: boolean
  278. configs: ModelLoadBalancingConfigEntry[]
  279. }
  280. export type ProviderCredential = {
  281. credentials: Record<string, any>
  282. name: string
  283. credential_id: string
  284. }
  285. export type ModelCredential = {
  286. credentials: Record<string, any>
  287. load_balancing: ModelLoadBalancingConfig
  288. available_credentials: Credential[]
  289. current_credential_id?: string
  290. current_credential_name?: string
  291. }