PointDTO » History » Version 2
Tomislav Pleše, 09/29/2025 06:12 PM
| 1 | 2 | Tomislav Pleše | # PointDTO |
|---|---|---|---|
| 2 | |||
| 3 | |||
| 4 | ``` |
||
| 5 | class PointDTO { |
||
| 6 | final String id; |
||
| 7 | // Possible: Root Point, Shard Point - T007 |
||
| 8 | // parentShardId != parentPointId |
||
| 9 | final String parentPointId; |
||
| 10 | final List<String> pointChildren; |
||
| 11 | // Shard.id - goes into the ShardList if not Root Point - T007-S02 |
||
| 12 | // parentShardId != parentPointId |
||
| 13 | final String? parentShardId; |
||
| 14 | // T007[S01, S02, S03..] |
||
| 15 | final List<ShardDTO> shardsList; |
||
| 16 | final List<ExchangeDTO> exchangesList; |
||
| 17 | final MetadataDTO? metadata; |
||
| 18 | |||
| 19 | PointDTO({ |
||
| 20 | required this.id, |
||
| 21 | required this.parentPointId, |
||
| 22 | List<String>? pointChildren, |
||
| 23 | this.parentShardId, |
||
| 24 | List<ShardDTO>? shardsList, |
||
| 25 | List<ExchangeDTO>? exchangesList, |
||
| 26 | this.metadata, |
||
| 27 | }) : pointChildren = pointChildren ?? [], |
||
| 28 | shardsList = shardsList ?? [], |
||
| 29 | exchangesList = exchangesList ?? []; |
||
| 30 | |||
| 31 | PointDTO.empty({ |
||
| 32 | this.id = '', |
||
| 33 | this.parentPointId = '', |
||
| 34 | this.parentShardId, |
||
| 35 | this.metadata, |
||
| 36 | }) : pointChildren = [], |
||
| 37 | shardsList = [], |
||
| 38 | exchangesList = []; |
||
| 39 | |||
| 40 | factory PointDTO.fromJson(Map<String, dynamic> json) => |
||
| 41 | _$PointDTOFromJson(json); |
||
| 42 | Map<String, dynamic> toJson() => _$PointDTOToJson(this); |
||
| 43 | |||
| 44 | PointDTO copyWith({ |
||
| 45 | String? id, |
||
| 46 | String? parentPointId, |
||
| 47 | List<String>? pointChildren, |
||
| 48 | String? parentShardId, |
||
| 49 | List<ShardDTO>? shardsList, |
||
| 50 | List<ExchangeDTO>? exchangeList, |
||
| 51 | MetadataDTO? metadata, |
||
| 52 | }) { |
||
| 53 | return PointDTO( |
||
| 54 | id: id ?? this.id, |
||
| 55 | parentPointId: parentPointId ?? this.parentPointId, |
||
| 56 | pointChildren: pointChildren ?? this.pointChildren, |
||
| 57 | parentShardId: parentShardId ?? this.parentShardId, |
||
| 58 | shardsList: shardsList ?? this.shardsList, |
||
| 59 | exchangesList: exchangeList ?? this.exchangesList, |
||
| 60 | metadata: metadata ?? this.metadata, |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | @JsonSerializable(explicitToJson: true) |
||
| 66 | class ShardDTO { |
||
| 67 | final String shardId; |
||
| 68 | final List<String> shardChildren; |
||
| 69 | final AnchorDTO anchorDTO; |
||
| 70 | |||
| 71 | ShardDTO({ |
||
| 72 | required this.shardId, |
||
| 73 | required this.shardChildren, |
||
| 74 | required this.anchorDTO, |
||
| 75 | }); |
||
| 76 | |||
| 77 | factory ShardDTO.fromJson(Map<String, dynamic> json) => |
||
| 78 | _$ShardDTOFromJson(json); |
||
| 79 | Map<String, dynamic> toJson() => _$ShardDTOToJson(this); |
||
| 80 | |||
| 81 | |||
| 82 | // TODO TP: add return type -> empty ShardDTO |
||
| 83 | static empty() {} |
||
| 84 | } |
||
| 85 | |||
| 86 | @JsonSerializable(explicitToJson: true) |
||
| 87 | class AnchorDTO { |
||
| 88 | final int startPosition; |
||
| 89 | final int endPosition; |
||
| 90 | final String selectedText; |
||
| 91 | |||
| 92 | AnchorDTO({ |
||
| 93 | required this.startPosition, |
||
| 94 | required this.endPosition, |
||
| 95 | required this.selectedText |
||
| 96 | }); |
||
| 97 | |||
| 98 | factory AnchorDTO.fromJson(Map<String, dynamic> json) => |
||
| 99 | _$AnchorDTOFromJson(json); |
||
| 100 | Map<String, dynamic> toJson() => _$AnchorDTOToJson(this); |
||
| 101 | } |
||
| 102 | |||
| 103 | @JsonSerializable(explicitToJson: true) |
||
| 104 | class ExchangeDTO { |
||
| 105 | final String exchangeId; |
||
| 106 | final String? exchangeTitle; |
||
| 107 | final PromptDTO prompt; |
||
| 108 | final ResponseDTO? response; |
||
| 109 | |||
| 110 | ExchangeDTO({ |
||
| 111 | required this.exchangeId, |
||
| 112 | this.exchangeTitle, |
||
| 113 | required this.prompt, |
||
| 114 | this.response |
||
| 115 | }); |
||
| 116 | |||
| 117 | factory ExchangeDTO.fromJson(Map<String, dynamic> json) => |
||
| 118 | _$ExchangeDTOFromJson(json); |
||
| 119 | Map<String, dynamic> toJson() => _$ExchangeDTOToJson(this); |
||
| 120 | } |
||
| 121 | |||
| 122 | @JsonSerializable(explicitToJson: true) |
||
| 123 | class PromptDTO { |
||
| 124 | final String model; |
||
| 125 | final PromptMessageDTO promptMessage; |
||
| 126 | final int maxTokens; |
||
| 127 | |||
| 128 | PromptDTO({ |
||
| 129 | required this.model, |
||
| 130 | required this.promptMessage, |
||
| 131 | required this.maxTokens |
||
| 132 | }); |
||
| 133 | |||
| 134 | factory PromptDTO.fromJson(Map<String, dynamic> json) => |
||
| 135 | _$PromptDTOFromJson(json); |
||
| 136 | Map<String, dynamic> toJson() => _$PromptDTOToJson(this); |
||
| 137 | } |
||
| 138 | |||
| 139 | @JsonSerializable() |
||
| 140 | class PromptMessageDTO { |
||
| 141 | final String role; |
||
| 142 | final String content; |
||
| 143 | |||
| 144 | PromptMessageDTO({ |
||
| 145 | required this.role, |
||
| 146 | required this.content}); |
||
| 147 | |||
| 148 | factory PromptMessageDTO.fromJson(Map<String, dynamic> json) => |
||
| 149 | _$PromptMessageDTOFromJson(json); |
||
| 150 | Map<String, dynamic> toJson() => _$PromptMessageDTOToJson(this); |
||
| 151 | } |
||
| 152 | |||
| 153 | @JsonSerializable(explicitToJson: true) |
||
| 154 | class ResponseDTO { |
||
| 155 | final String id; |
||
| 156 | final String object; |
||
| 157 | final int created; |
||
| 158 | final String model; |
||
| 159 | final List<ChoiceDTO> choices; |
||
| 160 | final UsageDTO usage; |
||
| 161 | final String serviceTier; |
||
| 162 | final String? systemFingerprint; |
||
| 163 | |||
| 164 | ResponseDTO({ |
||
| 165 | required this.id, |
||
| 166 | required this.object, |
||
| 167 | required this.created, |
||
| 168 | required this.model, |
||
| 169 | required this.choices, |
||
| 170 | required this.usage, |
||
| 171 | required this.serviceTier, |
||
| 172 | this.systemFingerprint, |
||
| 173 | }); |
||
| 174 | |||
| 175 | factory ResponseDTO.fromJson(Map<String, dynamic> json) => |
||
| 176 | _$ResponseDTOFromJson(json); |
||
| 177 | Map<String, dynamic> toJson() => _$ResponseDTOToJson(this); |
||
| 178 | } |
||
| 179 | |||
| 180 | @JsonSerializable(explicitToJson: true) |
||
| 181 | class ChoiceDTO { |
||
| 182 | final int index; |
||
| 183 | final MessageDTO message; |
||
| 184 | final dynamic logprobs; |
||
| 185 | final String finishReason; |
||
| 186 | |||
| 187 | ChoiceDTO({ |
||
| 188 | required this.index, |
||
| 189 | required this.message, |
||
| 190 | this.logprobs, |
||
| 191 | required this.finishReason |
||
| 192 | }); |
||
| 193 | |||
| 194 | factory ChoiceDTO.fromJson(Map<String, dynamic> json) => |
||
| 195 | _$ChoiceDTOFromJson(json); |
||
| 196 | Map<String, dynamic> toJson() => _$ChoiceDTOToJson(this); |
||
| 197 | } |
||
| 198 | |||
| 199 | @JsonSerializable(explicitToJson: true) |
||
| 200 | class MessageDTO { |
||
| 201 | final String role; |
||
| 202 | final String content; |
||
| 203 | final String? refusal; |
||
| 204 | |||
| 205 | MessageDTO({ |
||
| 206 | required this.role, |
||
| 207 | required this.content, |
||
| 208 | this.refusal |
||
| 209 | }); |
||
| 210 | |||
| 211 | factory MessageDTO.fromJson(Map<String, dynamic> json) => |
||
| 212 | _$MessageDTOFromJson(json); |
||
| 213 | Map<String, dynamic> toJson() => _$MessageDTOToJson(this); |
||
| 214 | } |
||
| 215 | |||
| 216 | @JsonSerializable(explicitToJson: true) |
||
| 217 | class UsageDTO { |
||
| 218 | final int promptTokens; |
||
| 219 | final int completionTokens; |
||
| 220 | final int totalTokens; |
||
| 221 | final PromptTokensDetailsDTO promptTokensDetails; |
||
| 222 | final CompletionTokensDetailsDTO completionTokensDetails; |
||
| 223 | |||
| 224 | UsageDTO({ |
||
| 225 | required this.promptTokens, |
||
| 226 | required this.completionTokens, |
||
| 227 | required this.totalTokens, |
||
| 228 | required this.promptTokensDetails, |
||
| 229 | required this.completionTokensDetails, |
||
| 230 | }); |
||
| 231 | |||
| 232 | factory UsageDTO.fromJson(Map<String, dynamic> json) => |
||
| 233 | _$UsageDTOFromJson(json); |
||
| 234 | Map<String, dynamic> toJson() => _$UsageDTOToJson(this); |
||
| 235 | } |
||
| 236 | |||
| 237 | @JsonSerializable() |
||
| 238 | class PromptTokensDetailsDTO { |
||
| 239 | final int cachedTokens; |
||
| 240 | final int audioTokens; |
||
| 241 | |||
| 242 | PromptTokensDetailsDTO({ |
||
| 243 | required this.cachedTokens, |
||
| 244 | required this.audioTokens |
||
| 245 | }); |
||
| 246 | |||
| 247 | factory PromptTokensDetailsDTO.fromJson(Map<String, dynamic> json) => |
||
| 248 | _$PromptTokensDetailsDTOFromJson(json); |
||
| 249 | Map<String, dynamic> toJson() => _$PromptTokensDetailsDTOToJson(this); |
||
| 250 | } |
||
| 251 | |||
| 252 | @JsonSerializable() |
||
| 253 | class CompletionTokensDetailsDTO { |
||
| 254 | final int reasoningTokens; |
||
| 255 | final int audioTokens; |
||
| 256 | final int acceptedPredictionTokens; |
||
| 257 | final int rejectedPredictionTokens; |
||
| 258 | |||
| 259 | CompletionTokensDetailsDTO({ |
||
| 260 | required this.reasoningTokens, |
||
| 261 | required this.audioTokens, |
||
| 262 | required this.acceptedPredictionTokens, |
||
| 263 | required this.rejectedPredictionTokens, |
||
| 264 | }); |
||
| 265 | |||
| 266 | factory CompletionTokensDetailsDTO.fromJson(Map<String, dynamic> json) => |
||
| 267 | _$CompletionTokensDetailsDTOFromJson(json); |
||
| 268 | Map<String, dynamic> toJson() => _$CompletionTokensDetailsDTOToJson(this); |
||
| 269 | } |
||
| 270 | |||
| 271 | @JsonSerializable(explicitToJson: true) |
||
| 272 | class MetadataDTO { |
||
| 273 | final bool openState; |
||
| 274 | |||
| 275 | @JsonKey(fromJson: _parseDateTime, toJson: _formatDateTime) |
||
| 276 | final DateTime created; |
||
| 277 | |||
| 278 | |||
| 279 | // TODO TP: this should be a list of modification times |
||
| 280 | @JsonKey(fromJson: _parseDateTime, toJson: _formatDateTime) |
||
| 281 | final DateTime modified; |
||
| 282 | |||
| 283 | final int modifiedCount; |
||
| 284 | |||
| 285 | @JsonKey(fromJson: _parseDateTime, toJson: _formatDateTime) |
||
| 286 | final DateTime lastAccessed; |
||
| 287 | |||
| 288 | final int hotness; |
||
| 289 | |||
| 290 | // TODO TP: add hash of the Point object - to compare if there were changes |
||
| 291 | |||
| 292 | MetadataDTO({ |
||
| 293 | required this.openState, |
||
| 294 | required this.created, |
||
| 295 | required this.modified, |
||
| 296 | required this.modifiedCount, |
||
| 297 | required this.lastAccessed, |
||
| 298 | required this.hotness, |
||
| 299 | }); |
||
| 300 | |||
| 301 | static DateTime _parseDateTime(String dateString) { |
||
| 302 | return DateTime.parse(dateString); |
||
| 303 | } |
||
| 304 | |||
| 305 | static String _formatDateTime(DateTime date) { |
||
| 306 | return date.toIso8601String(); |
||
| 307 | } |
||
| 308 | |||
| 309 | factory MetadataDTO.fromJson(Map<String, dynamic> json) => |
||
| 310 | _$MetadataDTOFromJson(json); |
||
| 311 | Map<String, dynamic> toJson() => _$MetadataDTOToJson(this); |
||
| 312 | } |
||
| 313 | ``` |