| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  | from collections.abc import Sequence | 
					
						
							| 
									
										
										
										
											2024-12-24 18:38:51 +08:00
										 |  |  | from typing import cast | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  | from uuid import uuid4 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 17:56:04 +08:00
										 |  |  | from pydantic import BaseModel, Field | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | from core.helper import encrypter | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | from .segments import ( | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     ArrayAnySegment, | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |     ArrayFileSegment, | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     ArrayNumberSegment, | 
					
						
							|  |  |  |     ArrayObjectSegment, | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  |     ArraySegment, | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     ArrayStringSegment, | 
					
						
							| 
									
										
										
										
											2024-10-21 10:43:49 +08:00
										 |  |  |     FileSegment, | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  |     FloatSegment, | 
					
						
							|  |  |  |     IntegerSegment, | 
					
						
							|  |  |  |     NoneSegment, | 
					
						
							|  |  |  |     ObjectSegment, | 
					
						
							|  |  |  |     Segment, | 
					
						
							|  |  |  |     StringSegment, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | from .types import SegmentType | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Variable(Segment): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     A variable is a segment that has a name. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     id: str = Field( | 
					
						
							| 
									
										
										
										
											2025-05-08 17:39:51 +08:00
										 |  |  |         default_factory=lambda: str(uuid4()), | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |         description="Unique identity for variable.", | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |     ) | 
					
						
							|  |  |  |     name: str | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |     description: str = Field(default="", description="Description of the variable.") | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |     selector: Sequence[str] = Field(default_factory=list) | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class StringVariable(StringSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | class FloatVariable(FloatSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-25 17:06:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | class IntegerVariable(IntegerSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | class ObjectVariable(ObjectSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-25 17:06:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayVariable(ArraySegment, Variable): | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayAnyVariable(ArrayAnySegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayStringVariable(ArrayStringSegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayNumberVariable(ArrayNumberSegment, ArrayVariable): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ArrayObjectVariable(ArrayObjectSegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | class SecretVariable(StringVariable): | 
					
						
							|  |  |  |     value_type: SegmentType = SegmentType.SECRET | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     def log(self) -> str: | 
					
						
							| 
									
										
										
										
											2024-12-24 18:38:51 +08:00
										 |  |  |         return cast(str, encrypter.obfuscated_token(self.value)) | 
					
						
							| 
									
										
										
										
											2024-07-23 17:59:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-23 21:46:08 +08:00
										 |  |  | class NoneVariable(NoneSegment, Variable): | 
					
						
							| 
									
										
										
										
											2024-07-23 17:59:32 +08:00
										 |  |  |     value_type: SegmentType = SegmentType.NONE | 
					
						
							| 
									
										
										
										
											2024-07-23 21:46:08 +08:00
										 |  |  |     value: None = None | 
					
						
							| 
									
										
										
										
											2024-10-21 10:43:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FileVariable(FileSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-24 15:56:59 +08:00
										 |  |  | class ArrayFileVariable(ArrayFileSegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |     pass | 
					
						
							| 
									
										
										
										
											2025-05-28 17:56:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-03 19:02:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 17:56:04 +08:00
										 |  |  | class RAGPipelineVariable(BaseModel): | 
					
						
							|  |  |  |     belong_to_node_id: str = Field(description="belong to which node id, shared means public") | 
					
						
							|  |  |  |     type: str = Field(description="variable type, text-input, paragraph, select, number,  file, file-list") | 
					
						
							|  |  |  |     label: str = Field(description="label") | 
					
						
							|  |  |  |     description: str | None = Field(description="description", default="") | 
					
						
							|  |  |  |     variable: str = Field(description="variable key", default="") | 
					
						
							| 
									
										
										
										
											2025-06-03 19:02:57 +08:00
										 |  |  |     max_length: int | None = Field( | 
					
						
							|  |  |  |         description="max length, applicable to text-input, paragraph, and file-list", default=0 | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2025-05-28 17:56:04 +08:00
										 |  |  |     default_value: str | None = Field(description="default value", default="") | 
					
						
							|  |  |  |     placeholder: str | None = Field(description="placeholder", default="") | 
					
						
							|  |  |  |     unit: str | None = Field(description="unit, applicable to Number", default="") | 
					
						
							|  |  |  |     tooltips: str | None = Field(description="helpful text", default="") | 
					
						
							| 
									
										
										
										
											2025-06-03 19:02:57 +08:00
										 |  |  |     allowed_file_types: list[str] | None = Field( | 
					
						
							|  |  |  |         description="image, document, audio, video, custom.", default_factory=list | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2025-05-28 17:56:04 +08:00
										 |  |  |     allowed_file_extensions: list[str] | None = Field(description="e.g. ['.jpg', '.mp3']", default_factory=list) | 
					
						
							| 
									
										
										
										
											2025-06-03 19:02:57 +08:00
										 |  |  |     allowed_file_upload_methods: list[str] | None = Field( | 
					
						
							|  |  |  |         description="remote_url, local_file, tool_file.", default_factory=list | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2025-05-28 17:56:04 +08:00
										 |  |  |     required: bool = Field(description="optional, default false", default=False) | 
					
						
							|  |  |  |     options: list[str] | None = Field(default_factory=list) |