algolia 3.40.0 → 3.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/Bug_report.yml +1 -0
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile.lock +4 -4
  5. data/lib/algolia/api/agent_studio_client.rb +2364 -0
  6. data/lib/algolia/models/agent-studio/advanced_syntax_features.rb +34 -0
  7. data/lib/algolia/models/agent-studio/agent_completion_algolia_params.rb +221 -0
  8. data/lib/algolia/models/agent-studio/agent_completion_request.rb +247 -0
  9. data/lib/algolia/models/agent-studio/agent_config_create.rb +288 -0
  10. data/lib/algolia/models/agent-studio/agent_config_update.rb +294 -0
  11. data/lib/algolia/models/agent-studio/agent_status.rb +34 -0
  12. data/lib/algolia/models/agent-studio/agent_test_configuration.rb +271 -0
  13. data/lib/algolia/models/agent-studio/agent_with_version_response.rb +370 -0
  14. data/lib/algolia/models/agent-studio/algolia_display_results_tool_config.rb +254 -0
  15. data/lib/algolia/models/agent-studio/algolia_recommend_tool_config_input.rb +242 -0
  16. data/lib/algolia/models/agent-studio/algolia_recommend_tool_index_config.rb +228 -0
  17. data/lib/algolia/models/agent-studio/algolia_search_tool_config.rb +232 -0
  18. data/lib/algolia/models/agent-studio/algolia_search_tool_index_config.rb +249 -0
  19. data/lib/algolia/models/agent-studio/allowed_domain_bulk_delete.rb +212 -0
  20. data/lib/algolia/models/agent-studio/allowed_domain_bulk_insert.rb +212 -0
  21. data/lib/algolia/models/agent-studio/allowed_domain_create.rb +210 -0
  22. data/lib/algolia/models/agent-studio/allowed_domain_list_response.rb +211 -0
  23. data/lib/algolia/models/agent-studio/allowed_domain_response.rb +264 -0
  24. data/lib/algolia/models/agent-studio/alternatives_as_exact.rb +36 -0
  25. data/lib/algolia/models/agent-studio/anthropic_provider_input.rb +220 -0
  26. data/lib/algolia/models/agent-studio/application_config_patch.rb +209 -0
  27. data/lib/algolia/models/agent-studio/application_config_response.rb +208 -0
  28. data/lib/algolia/models/agent-studio/around_precision_union.rb +108 -0
  29. data/lib/algolia/models/agent-studio/around_radius_union.rb +108 -0
  30. data/lib/algolia/models/agent-studio/assistant_message_v4.rb +252 -0
  31. data/lib/algolia/models/agent-studio/assistant_message_v5.rb +228 -0
  32. data/lib/algolia/models/agent-studio/assistant_part_v4.rb +110 -0
  33. data/lib/algolia/models/agent-studio/assistant_part_v5.rb +110 -0
  34. data/lib/algolia/models/agent-studio/azure_open_ai_provider_input.rb +243 -0
  35. data/lib/algolia/models/agent-studio/base_provider_input.rb +209 -0
  36. data/lib/algolia/models/agent-studio/client_side_tool_config.rb +241 -0
  37. data/lib/algolia/models/agent-studio/client_tools_args_schema.rb +228 -0
  38. data/lib/algolia/models/agent-studio/compatibility_mode.rb +34 -0
  39. data/lib/algolia/models/agent-studio/conversation_base_response.rb +355 -0
  40. data/lib/algolia/models/agent-studio/conversation_full_response.rb +369 -0
  41. data/lib/algolia/models/agent-studio/conversation_metadata.rb +209 -0
  42. data/lib/algolia/models/agent-studio/distinct_union.rb +108 -0
  43. data/lib/algolia/models/agent-studio/episode.rb +243 -0
  44. data/lib/algolia/models/agent-studio/error_base.rb +207 -0
  45. data/lib/algolia/models/agent-studio/exact_on_single_word_query.rb +35 -0
  46. data/lib/algolia/models/agent-studio/facet_filters_union.rb +108 -0
  47. data/lib/algolia/models/agent-studio/facets.rb +208 -0
  48. data/lib/algolia/models/agent-studio/facets_param.rb +220 -0
  49. data/lib/algolia/models/agent-studio/facets_union.rb +108 -0
  50. data/lib/algolia/models/agent-studio/feedback_creation_request.rb +251 -0
  51. data/lib/algolia/models/agent-studio/feedback_response.rb +297 -0
  52. data/lib/algolia/models/agent-studio/ignore_plurals_union.rb +108 -0
  53. data/lib/algolia/models/agent-studio/index_search_parameters.rb +267 -0
  54. data/lib/algolia/models/agent-studio/inside_bounding_box_union.rb +108 -0
  55. data/lib/algolia/models/agent-studio/inside_polygon_union.rb +108 -0
  56. data/lib/algolia/models/agent-studio/location_item_union.rb +108 -0
  57. data/lib/algolia/models/agent-studio/mcp_server_tool_config.rb +276 -0
  58. data/lib/algolia/models/agent-studio/mcp_tool_config.rb +218 -0
  59. data/lib/algolia/models/agent-studio/memory_record.rb +368 -0
  60. data/lib/algolia/models/agent-studio/memory_type.rb +34 -0
  61. data/lib/algolia/models/agent-studio/message_part.rb +132 -0
  62. data/lib/algolia/models/agent-studio/message_response.rb +309 -0
  63. data/lib/algolia/models/agent-studio/message_role.rb +34 -0
  64. data/lib/algolia/models/agent-studio/message_v4.rb +117 -0
  65. data/lib/algolia/models/agent-studio/message_v5.rb +117 -0
  66. data/lib/algolia/models/agent-studio/messages_union.rb +108 -0
  67. data/lib/algolia/models/agent-studio/number_param.rb +230 -0
  68. data/lib/algolia/models/agent-studio/number_param_constraint.rb +219 -0
  69. data/lib/algolia/models/agent-studio/numeric_filters_union.rb +108 -0
  70. data/lib/algolia/models/agent-studio/open_ai_compatible_provider_input.rb +232 -0
  71. data/lib/algolia/models/agent-studio/open_ai_provider_input.rb +220 -0
  72. data/lib/algolia/models/agent-studio/optional_filters_union.rb +108 -0
  73. data/lib/algolia/models/agent-studio/optional_words_union.rb +108 -0
  74. data/lib/algolia/models/agent-studio/paginated_agents_response.rb +221 -0
  75. data/lib/algolia/models/agent-studio/paginated_conversations_response.rb +221 -0
  76. data/lib/algolia/models/agent-studio/paginated_provider_authentications_response.rb +221 -0
  77. data/lib/algolia/models/agent-studio/paginated_secret_keys_response.rb +221 -0
  78. data/lib/algolia/models/agent-studio/pagination_metadata.rb +241 -0
  79. data/lib/algolia/models/agent-studio/provider_authentication_create.rb +230 -0
  80. data/lib/algolia/models/agent-studio/provider_authentication_patch.rb +218 -0
  81. data/lib/algolia/models/agent-studio/provider_authentication_response.rb +274 -0
  82. data/lib/algolia/models/agent-studio/provider_input.rb +111 -0
  83. data/lib/algolia/models/agent-studio/provider_input_nullable.rb +111 -0
  84. data/lib/algolia/models/agent-studio/provider_name.rb +38 -0
  85. data/lib/algolia/models/agent-studio/query_type.rb +35 -0
  86. data/lib/algolia/models/agent-studio/re_ranking_apply_filter_union.rb +108 -0
  87. data/lib/algolia/models/agent-studio/reasoning_part.rb +219 -0
  88. data/lib/algolia/models/agent-studio/reasoning_part_v4.rb +217 -0
  89. data/lib/algolia/models/agent-studio/reasoning_part_v5.rb +217 -0
  90. data/lib/algolia/models/agent-studio/remove_stop_words_union.rb +108 -0
  91. data/lib/algolia/models/agent-studio/remove_words_if_no_results.rb +36 -0
  92. data/lib/algolia/models/agent-studio/search_parameters.rb +950 -0
  93. data/lib/algolia/models/agent-studio/search_parameters_overrides.rb +286 -0
  94. data/lib/algolia/models/agent-studio/secret_key_create.rb +222 -0
  95. data/lib/algolia/models/agent-studio/secret_key_patch.rb +223 -0
  96. data/lib/algolia/models/agent-studio/secret_key_response.rb +287 -0
  97. data/lib/algolia/models/agent-studio/start_part.rb +208 -0
  98. data/lib/algolia/models/agent-studio/start_step_part.rb +208 -0
  99. data/lib/algolia/models/agent-studio/step_start_part_v4.rb +206 -0
  100. data/lib/algolia/models/agent-studio/step_start_part_v5.rb +206 -0
  101. data/lib/algolia/models/agent-studio/string_array_param.rb +242 -0
  102. data/lib/algolia/models/agent-studio/string_array_param_constraint.rb +211 -0
  103. data/lib/algolia/models/agent-studio/supported_language.rb +169 -0
  104. data/lib/algolia/models/agent-studio/tag_filters_union.rb +108 -0
  105. data/lib/algolia/models/agent-studio/text_param.rb +220 -0
  106. data/lib/algolia/models/agent-studio/text_part.rb +216 -0
  107. data/lib/algolia/models/agent-studio/text_part_v4.rb +217 -0
  108. data/lib/algolia/models/agent-studio/text_part_v5.rb +217 -0
  109. data/lib/algolia/models/agent-studio/tool_approval_request_part.rb +285 -0
  110. data/lib/algolia/models/agent-studio/tool_call_part.rb +265 -0
  111. data/lib/algolia/models/agent-studio/tool_config.rb +108 -0
  112. data/lib/algolia/models/agent-studio/tool_config_input.rb +129 -0
  113. data/lib/algolia/models/agent-studio/tool_invocation_part_v4.rb +217 -0
  114. data/lib/algolia/models/agent-studio/tool_invocation_v4.rb +309 -0
  115. data/lib/algolia/models/agent-studio/tool_part_v5.rb +309 -0
  116. data/lib/algolia/models/agent-studio/tool_result_output.rb +221 -0
  117. data/lib/algolia/models/agent-studio/tool_result_output_type.rb +37 -0
  118. data/lib/algolia/models/agent-studio/tool_result_part.rb +254 -0
  119. data/lib/algolia/models/agent-studio/tool_state.rb +36 -0
  120. data/lib/algolia/models/agent-studio/typo_tolerance_enum.rb +36 -0
  121. data/lib/algolia/models/agent-studio/typo_tolerance_union.rb +108 -0
  122. data/lib/algolia/models/agent-studio/unknown_tool_config.rb +220 -0
  123. data/lib/algolia/models/agent-studio/user_data_response.rb +223 -0
  124. data/lib/algolia/models/agent-studio/user_message_metadata_v5.rb +209 -0
  125. data/lib/algolia/models/agent-studio/user_message_v4.rb +250 -0
  126. data/lib/algolia/models/agent-studio/user_message_v5.rb +237 -0
  127. data/lib/algolia/models/agent-studio/validation_error.rb +252 -0
  128. data/lib/algolia/models/agent-studio/vote_enum.rb +34 -0
  129. data/lib/algolia/version.rb +1 -1
  130. metadata +125 -1
@@ -0,0 +1,309 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module AgentStudio
10
+ # Response model for a message.
11
+ class MessageResponse
12
+ attr_accessor :id
13
+
14
+ attr_accessor :conversation_id
15
+
16
+ attr_accessor :role
17
+
18
+ attr_accessor :parts
19
+
20
+ attr_accessor :created_at
21
+
22
+ attr_accessor :updated_at
23
+
24
+ attr_accessor :model
25
+
26
+ attr_accessor :input_tokens
27
+
28
+ attr_accessor :output_tokens
29
+
30
+ attr_accessor :turn_context
31
+
32
+ # Attribute mapping from ruby-style variable name to JSON key.
33
+ def self.attribute_map
34
+ {
35
+ :id => :id,
36
+ :conversation_id => :conversationId,
37
+ :role => :role,
38
+ :parts => :parts,
39
+ :created_at => :createdAt,
40
+ :updated_at => :updatedAt,
41
+ :model => :model,
42
+ :input_tokens => :inputTokens,
43
+ :output_tokens => :outputTokens,
44
+ :turn_context => :turnContext
45
+ }
46
+ end
47
+
48
+ # Attribute type mapping.
49
+ def self.types_mapping
50
+ {
51
+ :id => :"String",
52
+ :conversation_id => :"String",
53
+ :role => :"MessageRole",
54
+ :parts => :"Array<MessagePart>",
55
+ :created_at => :"String",
56
+ :updated_at => :"String",
57
+ :model => :"String",
58
+ :input_tokens => :"Integer",
59
+ :output_tokens => :"Integer",
60
+ :turn_context => :"Hash<String, String>"
61
+ }
62
+ end
63
+
64
+ # List of attributes with nullable: true
65
+ def self.openapi_nullable
66
+ Set.new(
67
+ [
68
+ :model,
69
+ :input_tokens,
70
+ :output_tokens,
71
+ :turn_context
72
+ ]
73
+ )
74
+ end
75
+
76
+ # Initializes the object
77
+ # @param [Hash] attributes Model attributes in the form of hash
78
+ def initialize(attributes = {})
79
+ if (!attributes.is_a?(Hash))
80
+ raise(
81
+ ArgumentError,
82
+ "The input argument (attributes) must be a hash in `Algolia::MessageResponse` initialize method"
83
+ )
84
+ end
85
+
86
+ # check to see if the attribute exists and convert string to symbol for hash key
87
+ attributes = attributes.each_with_object({}) { |(k, v), h|
88
+ if (!self.class.attribute_map.key?(k.to_sym))
89
+ raise(
90
+ ArgumentError,
91
+ "`#{k}` is not a valid attribute in `Algolia::MessageResponse`. Please check the name to make sure it's valid. List of attributes: " +
92
+ self.class.attribute_map.keys.inspect
93
+ )
94
+ end
95
+
96
+ h[k.to_sym] = v
97
+ }
98
+
99
+ if attributes.key?(:id)
100
+ self.id = attributes[:id]
101
+ else
102
+ self.id = nil
103
+ end
104
+
105
+ if attributes.key?(:conversation_id)
106
+ self.conversation_id = attributes[:conversation_id]
107
+ else
108
+ self.conversation_id = nil
109
+ end
110
+
111
+ if attributes.key?(:role)
112
+ self.role = attributes[:role]
113
+ else
114
+ self.role = nil
115
+ end
116
+
117
+ if attributes.key?(:parts)
118
+ if (value = attributes[:parts]).is_a?(Array)
119
+ self.parts = value
120
+ end
121
+ else
122
+ self.parts = nil
123
+ end
124
+
125
+ if attributes.key?(:created_at)
126
+ self.created_at = attributes[:created_at]
127
+ else
128
+ self.created_at = nil
129
+ end
130
+
131
+ if attributes.key?(:updated_at)
132
+ self.updated_at = attributes[:updated_at]
133
+ else
134
+ self.updated_at = nil
135
+ end
136
+
137
+ if attributes.key?(:model)
138
+ self.model = attributes[:model]
139
+ end
140
+
141
+ if attributes.key?(:input_tokens)
142
+ self.input_tokens = attributes[:input_tokens]
143
+ end
144
+
145
+ if attributes.key?(:output_tokens)
146
+ self.output_tokens = attributes[:output_tokens]
147
+ end
148
+
149
+ if attributes.key?(:turn_context)
150
+ if (value = attributes[:turn_context]).is_a?(Hash)
151
+ self.turn_context = value
152
+ end
153
+ end
154
+ end
155
+
156
+ # Checks equality by comparing each attribute.
157
+ # @param [Object] Object to be compared
158
+ def ==(other)
159
+ return true if self.equal?(other)
160
+ self.class == other.class &&
161
+ id == other.id &&
162
+ conversation_id == other.conversation_id &&
163
+ role == other.role &&
164
+ parts == other.parts &&
165
+ created_at == other.created_at &&
166
+ updated_at == other.updated_at &&
167
+ model == other.model &&
168
+ input_tokens == other.input_tokens &&
169
+ output_tokens == other.output_tokens &&
170
+ turn_context == other.turn_context
171
+ end
172
+
173
+ # @see the `==` method
174
+ # @param [Object] Object to be compared
175
+ def eql?(other)
176
+ self == other
177
+ end
178
+
179
+ # Calculates hash code according to all attributes.
180
+ # @return [Integer] Hash code
181
+ def hash
182
+ [id, conversation_id, role, parts, created_at, updated_at, model, input_tokens, output_tokens, turn_context].hash
183
+ end
184
+
185
+ # Builds the object from hash
186
+ # @param [Hash] attributes Model attributes in the form of hash
187
+ # @return [Object] Returns the model itself
188
+ def self.build_from_hash(attributes)
189
+ return nil unless attributes.is_a?(Hash)
190
+ attributes = attributes.transform_keys(&:to_sym)
191
+ transformed_hash = {}
192
+ types_mapping.each_pair do |key, type|
193
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
194
+ transformed_hash[key.to_sym] = nil
195
+ elsif type =~ /\AArray<(.*)>/i
196
+ # check to ensure the input is an array given that the attribute
197
+ # is documented as an array but the input is not
198
+ if attributes[attribute_map[key]].is_a?(Array)
199
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
200
+ _deserialize(::Regexp.last_match(1), v)
201
+ }
202
+ end
203
+ elsif !attributes[attribute_map[key]].nil?
204
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
205
+ end
206
+ end
207
+
208
+ new(transformed_hash)
209
+ end
210
+
211
+ # Deserializes the data based on type
212
+ # @param string type Data type
213
+ # @param string value Value to be deserialized
214
+ # @return [Object] Deserialized data
215
+ def self._deserialize(type, value)
216
+ case type.to_sym
217
+ when :Time
218
+ Time.parse(value)
219
+ when :Date
220
+ Date.parse(value)
221
+ when :String
222
+ value.to_s
223
+ when :Integer
224
+ value.to_i
225
+ when :Float
226
+ value.to_f
227
+ when :Boolean
228
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
229
+ true
230
+ else
231
+ false
232
+ end
233
+
234
+ when :Object
235
+ # generic object (usually a Hash), return directly
236
+ value
237
+ when /\AArray<(?<inner_type>.+)>\z/
238
+ inner_type = Regexp.last_match[:inner_type]
239
+ value.map { |v| _deserialize(inner_type, v) }
240
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
241
+ k_type = Regexp.last_match[:k_type]
242
+ v_type = Regexp.last_match[:v_type]
243
+ {}.tap do |hash|
244
+ value.each do |k, v|
245
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
246
+ end
247
+ end
248
+ # model
249
+ else
250
+ # models (e.g. Pet) or oneOf
251
+ klass = Algolia::AgentStudio.const_get(type)
252
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
253
+ .build_from_hash(value)
254
+ end
255
+ end
256
+
257
+ # Returns the string representation of the object
258
+ # @return [String] String presentation of the object
259
+ def to_s
260
+ to_hash.to_s
261
+ end
262
+
263
+ # to_body is an alias to to_hash (backward compatibility)
264
+ # @return [Hash] Returns the object in the form of hash
265
+ def to_body
266
+ to_hash
267
+ end
268
+
269
+ def to_json(*_args)
270
+ to_hash.to_json
271
+ end
272
+
273
+ # Returns the object in the form of hash
274
+ # @return [Hash] Returns the object in the form of hash
275
+ def to_hash
276
+ hash = {}
277
+ self.class.attribute_map.each_pair do |attr, param|
278
+ value = send(attr)
279
+ if value.nil?
280
+ is_nullable = self.class.openapi_nullable.include?(attr)
281
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
282
+ end
283
+
284
+ hash[param] = _to_hash(value)
285
+ end
286
+
287
+ hash
288
+ end
289
+
290
+ # Outputs non-array value in the form of hash
291
+ # For object, use to_hash. Otherwise, just return the value
292
+ # @param [Object] value Any valid value
293
+ # @return [Hash] Returns the value in the form of hash
294
+ def _to_hash(value)
295
+ if value.is_a?(Array)
296
+ value.compact.map { |v| _to_hash(v) }
297
+ elsif value.is_a?(Hash)
298
+ {}.tap do |hash|
299
+ value.each { |k, v| hash[k] = _to_hash(v) }
300
+ end
301
+ elsif value.respond_to?(:to_hash)
302
+ value.to_hash
303
+ else
304
+ value
305
+ end
306
+ end
307
+ end
308
+ end
309
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module AgentStudio
10
+ class MessageRole
11
+ USER = "user".freeze
12
+ ASSISTANT = "assistant".freeze
13
+
14
+ def self.all_vars
15
+ @all_vars ||= [USER, ASSISTANT].freeze
16
+ end
17
+
18
+ # Builds the enum from string
19
+ # @param [String] The enum value in the form of the string
20
+ # @return [String] The enum value
21
+ def self.build_from_hash(value)
22
+ new.build_from_hash(value)
23
+ end
24
+
25
+ # Builds the enum from string
26
+ # @param [String] The enum value in the form of the string
27
+ # @return [String] The enum value
28
+ def build_from_hash(value)
29
+ return value if MessageRole.all_vars.include?(value)
30
+ raise "Invalid ENUM value #{value} for class #MessageRole"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module AgentStudio
10
+ module MessageV4
11
+ class << self
12
+ # List of class defined in oneOf (OpenAPI v3)
13
+ def openapi_one_of
14
+ [
15
+ :"AssistantMessageV4",
16
+ :"UserMessageV4"
17
+ ]
18
+ end
19
+
20
+ # Builds the object
21
+ # @param [Mixed] Data to be matched against the list of oneOf items
22
+ # @return [Object] Returns the model or the data itself
23
+ def build(data)
24
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
25
+ # Note:
26
+ # - We do not attempt to check whether exactly one item matches.
27
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
28
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
29
+ # - TODO: scalar values are de facto behaving as if they were nullable.
30
+ # - TODO: logging when debugging is set.
31
+ if data.is_a?(Hash) && data.key?("role")
32
+ case data["role"]
33
+ when "assistant"
34
+ return find_and_cast_into_type(:"AssistantMessageV4", data)
35
+ when "user"
36
+ return find_and_cast_into_type(:"UserMessageV4", data)
37
+ end
38
+ end
39
+
40
+ openapi_one_of.each do |klass|
41
+ begin
42
+ # "nullable: true"
43
+ next if klass == :AnyType
44
+ typed_data = find_and_cast_into_type(klass, data)
45
+ return typed_data if typed_data
46
+ # rescue all errors so we keep iterating even if the current item lookup raises
47
+ rescue
48
+ end
49
+ end
50
+
51
+ openapi_one_of.include?(:AnyType) ? data : nil
52
+ end
53
+
54
+ private
55
+
56
+ SchemaMismatchError = Class.new(StandardError)
57
+
58
+ def find_and_cast_into_type(klass, data)
59
+ return if data.nil?
60
+
61
+ case klass.to_s
62
+ when "Boolean"
63
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
64
+ when "Float"
65
+ return data if data.instance_of?(Float)
66
+ when "Integer"
67
+ return data if data.instance_of?(Integer)
68
+ when "Time"
69
+ return Time.parse(data)
70
+ when "Date"
71
+ return Date.parse(data)
72
+ when "String"
73
+ return data if data.instance_of?(String)
74
+ # "type: object"
75
+ when "Object"
76
+ return data if data.instance_of?(Hash)
77
+ # "type: array"
78
+ when /\AArray<(?<sub_type>.+)>\z/
79
+ if data.instance_of?(Array)
80
+ sub_type = Regexp.last_match[:sub_type]
81
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
82
+ end
83
+ # "type: object" with "additionalProperties: { ... }"
84
+ when /\AHash<String, (?<sub_type>.+)>\z/
85
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
86
+ sub_type = Regexp.last_match[:sub_type]
87
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
88
+ end
89
+ # model
90
+ else
91
+ const = Algolia::AgentStudio.const_get(klass)
92
+ if const
93
+ if const.respond_to?(:openapi_one_of)
94
+ # nested oneOf model
95
+ model = const.build(data)
96
+ elsif const.respond_to?(:discriminator_attributes)
97
+ if const.discriminator_attributes.all? { |attr| data.key?(attr) }
98
+ model = const.build_from_hash(data)
99
+ end
100
+ else
101
+ # maybe it's an enum, or doens't have discriminators
102
+ model = const.build_from_hash(data)
103
+ end
104
+
105
+ return model if model
106
+ end
107
+ end
108
+
109
+ # if no match by now, raise
110
+ raise
111
+ rescue
112
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module AgentStudio
10
+ module MessageV5
11
+ class << self
12
+ # List of class defined in oneOf (OpenAPI v3)
13
+ def openapi_one_of
14
+ [
15
+ :"AssistantMessageV5",
16
+ :"UserMessageV5"
17
+ ]
18
+ end
19
+
20
+ # Builds the object
21
+ # @param [Mixed] Data to be matched against the list of oneOf items
22
+ # @return [Object] Returns the model or the data itself
23
+ def build(data)
24
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
25
+ # Note:
26
+ # - We do not attempt to check whether exactly one item matches.
27
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
28
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
29
+ # - TODO: scalar values are de facto behaving as if they were nullable.
30
+ # - TODO: logging when debugging is set.
31
+ if data.is_a?(Hash) && data.key?("role")
32
+ case data["role"]
33
+ when "assistant"
34
+ return find_and_cast_into_type(:"AssistantMessageV5", data)
35
+ when "user"
36
+ return find_and_cast_into_type(:"UserMessageV5", data)
37
+ end
38
+ end
39
+
40
+ openapi_one_of.each do |klass|
41
+ begin
42
+ # "nullable: true"
43
+ next if klass == :AnyType
44
+ typed_data = find_and_cast_into_type(klass, data)
45
+ return typed_data if typed_data
46
+ # rescue all errors so we keep iterating even if the current item lookup raises
47
+ rescue
48
+ end
49
+ end
50
+
51
+ openapi_one_of.include?(:AnyType) ? data : nil
52
+ end
53
+
54
+ private
55
+
56
+ SchemaMismatchError = Class.new(StandardError)
57
+
58
+ def find_and_cast_into_type(klass, data)
59
+ return if data.nil?
60
+
61
+ case klass.to_s
62
+ when "Boolean"
63
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
64
+ when "Float"
65
+ return data if data.instance_of?(Float)
66
+ when "Integer"
67
+ return data if data.instance_of?(Integer)
68
+ when "Time"
69
+ return Time.parse(data)
70
+ when "Date"
71
+ return Date.parse(data)
72
+ when "String"
73
+ return data if data.instance_of?(String)
74
+ # "type: object"
75
+ when "Object"
76
+ return data if data.instance_of?(Hash)
77
+ # "type: array"
78
+ when /\AArray<(?<sub_type>.+)>\z/
79
+ if data.instance_of?(Array)
80
+ sub_type = Regexp.last_match[:sub_type]
81
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
82
+ end
83
+ # "type: object" with "additionalProperties: { ... }"
84
+ when /\AHash<String, (?<sub_type>.+)>\z/
85
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
86
+ sub_type = Regexp.last_match[:sub_type]
87
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
88
+ end
89
+ # model
90
+ else
91
+ const = Algolia::AgentStudio.const_get(klass)
92
+ if const
93
+ if const.respond_to?(:openapi_one_of)
94
+ # nested oneOf model
95
+ model = const.build(data)
96
+ elsif const.respond_to?(:discriminator_attributes)
97
+ if const.discriminator_attributes.all? { |attr| data.key?(attr) }
98
+ model = const.build_from_hash(data)
99
+ end
100
+ else
101
+ # maybe it's an enum, or doens't have discriminators
102
+ model = const.build_from_hash(data)
103
+ end
104
+
105
+ return model if model
106
+ end
107
+ end
108
+
109
+ # if no match by now, raise
110
+ raise
111
+ rescue
112
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module AgentStudio
10
+ module MessagesUnion
11
+ class << self
12
+ # List of class defined in oneOf (OpenAPI v3)
13
+ def openapi_one_of
14
+ [
15
+ :"Array<MessageV4>",
16
+ :"Array<MessageV5>"
17
+ ]
18
+ end
19
+
20
+ # Builds the object
21
+ # @param [Mixed] Data to be matched against the list of oneOf items
22
+ # @return [Object] Returns the model or the data itself
23
+ def build(data)
24
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
25
+ # Note:
26
+ # - We do not attempt to check whether exactly one item matches.
27
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
28
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
29
+ # - TODO: scalar values are de facto behaving as if they were nullable.
30
+ # - TODO: logging when debugging is set.
31
+ openapi_one_of.each do |klass|
32
+ begin
33
+ # "nullable: true"
34
+ next if klass == :AnyType
35
+ typed_data = find_and_cast_into_type(klass, data)
36
+ return typed_data if typed_data
37
+ # rescue all errors so we keep iterating even if the current item lookup raises
38
+ rescue
39
+ end
40
+ end
41
+
42
+ openapi_one_of.include?(:AnyType) ? data : nil
43
+ end
44
+
45
+ private
46
+
47
+ SchemaMismatchError = Class.new(StandardError)
48
+
49
+ def find_and_cast_into_type(klass, data)
50
+ return if data.nil?
51
+
52
+ case klass.to_s
53
+ when "Boolean"
54
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
55
+ when "Float"
56
+ return data if data.instance_of?(Float)
57
+ when "Integer"
58
+ return data if data.instance_of?(Integer)
59
+ when "Time"
60
+ return Time.parse(data)
61
+ when "Date"
62
+ return Date.parse(data)
63
+ when "String"
64
+ return data if data.instance_of?(String)
65
+ # "type: object"
66
+ when "Object"
67
+ return data if data.instance_of?(Hash)
68
+ # "type: array"
69
+ when /\AArray<(?<sub_type>.+)>\z/
70
+ if data.instance_of?(Array)
71
+ sub_type = Regexp.last_match[:sub_type]
72
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
73
+ end
74
+ # "type: object" with "additionalProperties: { ... }"
75
+ when /\AHash<String, (?<sub_type>.+)>\z/
76
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
77
+ sub_type = Regexp.last_match[:sub_type]
78
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
79
+ end
80
+ # model
81
+ else
82
+ const = Algolia::AgentStudio.const_get(klass)
83
+ if const
84
+ if const.respond_to?(:openapi_one_of)
85
+ # nested oneOf model
86
+ model = const.build(data)
87
+ elsif const.respond_to?(:discriminator_attributes)
88
+ if const.discriminator_attributes.all? { |attr| data.key?(attr) }
89
+ model = const.build_from_hash(data)
90
+ end
91
+ else
92
+ # maybe it's an enum, or doens't have discriminators
93
+ model = const.build_from_hash(data)
94
+ end
95
+
96
+ return model if model
97
+ end
98
+ end
99
+
100
+ # if no match by now, raise
101
+ raise
102
+ rescue
103
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end