mindee 5.3.0 → 5.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8eb9e96fa7c4b8a41479c87152f858112a72c52f18c23ad247c220615d4df15
4
- data.tar.gz: 44da90b0f6e814f13cd418502998e3e17610e76857199744c8f2e98b217d72c0
3
+ metadata.gz: cda258819aabaa34266728d26130b0137ad8d86d770c9d395245e373b1bc96e4
4
+ data.tar.gz: 5fbbd21a967ff60ddc059fa9ed9d5f3fd7422890e3f3675d38347f82a5463da8
5
5
  SHA512:
6
- metadata.gz: 543a63c5085472676f044b20721f03844ad3f425f4fef936c147240b0c286da6f81d8ceffb9ebb90b6c70340426e0529350406b0acfb685176cedb85968ddc06
7
- data.tar.gz: 591a11727b309a1ac91840ae3dc260f1bcd5186c840b82a71bdc815a8dd3741500191801491ce25edcc44178077d5dd02d437b1c388f9164f1b80c49114a9ea4
6
+ metadata.gz: 956efea9a0245e734c9c1b313ad0e1a74f9c5245df05f3bb1e17ab2a3b4a5031b9d0fc21110f0db33dd08d85d0427cfda1c6f265b05177e1900b761274398fb0
7
+ data.tar.gz: c2845fc9b049a1b123b15678e4effdfb55f382650cb9eecc90244ec553a78679dd1523226e8826a5e3abfbcc95bff85c790aeabcde10d36696cffa977594e3c4
data/.rubocop.yml CHANGED
@@ -47,3 +47,7 @@ Metrics/AbcSize:
47
47
 
48
48
  Style/RegexpLiteral:
49
49
  EnforcedStyle: percent_r
50
+
51
+ Style/ArrayIntersect:
52
+ Exclude:
53
+ - 'lib/mindee/pdf/pdf_tools.rb'
data/CHANGELOG.md CHANGED
@@ -1,12 +1,23 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
+ ## v5.4.0 - 2026-07-21
4
+ ### Changes
5
+ * :sparkles: add field confidence comparators
6
+ * :sparkles: add support for cancellation token
7
+
8
+
9
+ ## v5.3.1 - 2026-07-15
10
+ ### Fixes
11
+ * :bug: fix file alias being sent as an invalid parameter
12
+
13
+
3
14
  ## v5.3.0 - 2026-07-03
4
- ### Changes:
15
+ ### Changes
5
16
  * :memo: add SKILL file
6
17
  * :recycle: use generic array types for images, PDFs
7
18
  * :sparkles: allow passing webhooks to the CLI
8
19
  * :sparkles: add webhook error response
9
- ### Fixes:
20
+ ### Fixes
10
21
  * :bug: fix for extraction method naming
11
22
 
12
23
  ## v5.2.2 - 2026-06-18
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module HTTP
5
+ # Custom cancellation token class for polling.
6
+ class CancellationToken
7
+ private attr_reader :is_canceled
8
+
9
+ def initialize
10
+ @is_cancelled = false
11
+ end
12
+
13
+ # Cancel the token.
14
+ def cancel
15
+ @is_cancelled = true
16
+ end
17
+
18
+ # Check if the token is canceled.
19
+ def canceled?
20
+ @is_cancelled
21
+ end
22
+ end
23
+ end
24
+ end
data/lib/mindee/http.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'http/cancellation_token'
3
4
  require_relative 'http/http_error_handler'
@@ -101,7 +101,7 @@ module Mindee
101
101
  # @param [Array] form_data Array of form fields
102
102
  # @return [Array]
103
103
  def append_form_data(form_data)
104
- form_data.push(['file_alias', @file_alias]) if @file_alias
104
+ form_data.push(['alias', @file_alias]) if @file_alias
105
105
  webhook_ids = @webhook_ids || []
106
106
  form_data.push(['webhook_ids', webhook_ids.join(',')]) unless @webhook_ids.nil? || webhook_ids.empty?
107
107
  form_data
@@ -219,6 +219,7 @@ module Mindee
219
219
  Mindee::V1::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http)
220
220
  end
221
221
 
222
+ # rubocop:disable Metrics/CyclomaticComplexity
222
223
  # Enqueue a document for async parsing and automatically try to retrieve it
223
224
  #
224
225
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
@@ -247,13 +248,23 @@ module Mindee
247
248
  # * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5.
248
249
  # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80.
249
250
  # @param endpoint [Mindee::V1::HTTP::Endpoint] Endpoint of the API.
251
+ # @param cancellation_token [Mindee::HTTP::CancellationToken, nil] Token for cancellation.
250
252
  # @return [Mindee::V1::Parsing::Common::ApiResponse]
251
- def enqueue_and_parse(input_source, product_class, endpoint, options)
253
+ # rubocop:disable Metrics/PerceivedComplexity
254
+ def enqueue_and_parse(
255
+ input_source,
256
+ product_class,
257
+ endpoint,
258
+ options,
259
+ cancellation_token = nil
260
+ )
252
261
  validate_async_params(options.initial_delay_sec, options.delay_sec, options.max_retries)
253
262
  enqueue_res = enqueue(input_source, product_class, endpoint: endpoint, options: options)
254
263
  job = enqueue_res.job or raise Error::MindeeAPIError, 'Expected job to be present'
255
264
  job_id = job.id
256
265
 
266
+ raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
267
+
257
268
  sleep(options.initial_delay_sec)
258
269
  polling_attempts = 1
259
270
  logger.debug("Successfully enqueued document with job id: '#{job_id}'")
@@ -266,6 +277,8 @@ module Mindee
266
277
  # @type var valid_statuses: Array[(:waiting | :processing | :completed | :failed)]
267
278
  while valid_statuses.include?(queue_res_job.status) && polling_attempts < options.max_retries
268
279
  logger.debug("Polling server for parsing result with job id: '#{job_id}'. Attempt #{polling_attempts}")
280
+ raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
281
+
269
282
  sleep(options.delay_sec)
270
283
  queue_res = parse_queued(job_id, product_class, endpoint: endpoint)
271
284
  queue_res_job = queue_res.job or raise Error::MindeeAPIError, 'Expected job to be present'
@@ -280,7 +293,9 @@ module Mindee
280
293
 
281
294
  queue_res
282
295
  end
296
+ # rubocop:enable Metrics/PerceivedComplexity
283
297
 
298
+ # rubocop:enable Metrics/CyclomaticComplexity
284
299
  # Sends a document to a workflow.
285
300
  #
286
301
  # Accepts options either as a Hash or as a WorkflowOptions struct.
@@ -58,12 +58,15 @@ module Mindee
58
58
  # The source of the input document (local file or URL).
59
59
  # @param params [Hash, Input::BaseParameters] Parameters for the inference.
60
60
  # @param polling_options [Hash, PollingOptions, nil] Parameters for polling.
61
+ # @param cancellation_token [Mindee::HTTP::CancellationToken, nil] Token for cancellation.
61
62
  # @return [Parsing::BaseResponse]
63
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
62
64
  def enqueue_and_get_result(
63
65
  product,
64
66
  input_source,
65
67
  params,
66
- polling_options = nil
68
+ polling_options = nil,
69
+ cancellation_token = nil
67
70
  )
68
71
  enqueue_response = enqueue(product, input_source, params)
69
72
  normalized_params = normalize_parameters(product.params_type, params, polling_options: polling_options)
@@ -77,6 +80,8 @@ module Mindee
77
80
  job_id = enqueue_response.job.id
78
81
  logger.debug("Successfully enqueued document with job id: #{job_id}.")
79
82
 
83
+ raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
84
+
80
85
  sleep(normalized_params.polling_options.initial_delay_sec)
81
86
  retry_counter = 1
82
87
  poll_results = get_job(job_id)
@@ -94,6 +99,8 @@ module Mindee
94
99
  "Job status: #{poll_results.job.status}."
95
100
  )
96
101
 
102
+ raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
103
+
97
104
  sleep(normalized_params.polling_options.delay_sec)
98
105
  poll_results = get_job(job_id)
99
106
  retry_counter += 1
@@ -110,6 +117,7 @@ module Mindee
110
117
  raise Mindee::Error::MindeeError,
111
118
  "Asynchronous parsing request timed out after #{sec_count} seconds"
112
119
  end
120
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
113
121
 
114
122
  # Searches for a list of available models for the given API key.
115
123
  # @param model_name [String]
@@ -203,7 +203,6 @@ module Mindee
203
203
  [['file', file_data, file_metadata]] # : Array[Array[untyped]]
204
204
  end
205
205
  form_data.push(['model_id', params.model_id])
206
- form_data.push ['file_alias', params.file_alias] if params.file_alias
207
206
  if params.is_a?(V2::Product::Extraction::Params::ExtractionParameters)
208
207
  form_data = enqueue_form_options(form_data, params)
209
208
  end
@@ -87,8 +87,8 @@ module Mindee
87
87
  end
88
88
  end
89
89
 
90
- # less than or equality of two FieldConfidence instances.
91
- # # @param other [String, Integer, FieldConfidence] The other confidence to compare.
90
+ # Less than or equality of two FieldConfidence instances.
91
+ # @param other [String, Integer, FieldConfidence] The other confidence to compare.
92
92
  def <=(other)
93
93
  if other.is_a?(FieldConfidence)
94
94
  to_i <= val_to_i(other.value)
@@ -101,12 +101,47 @@ module Mindee
101
101
  end
102
102
  end
103
103
 
104
+ # Greater than comparison of two FieldConfidence instances.
105
+ # @param other [String, Integer, FieldConfidence] The other confidence to compare.
106
+ def >(other)
107
+ if other.is_a?(FieldConfidence)
108
+ to_i > val_to_i(other.value)
109
+ elsif other.is_a?(String)
110
+ to_i > val_to_i(other)
111
+ elsif other.is_a?(Integer)
112
+ to_i > other
113
+ else
114
+ raise ArgumentError, "Invalid type: #{other.class}"
115
+ end
116
+ end
117
+
118
+ # Less than comparison of two FieldConfidence instances.
119
+ # @param other [String, Integer, FieldConfidence] The other confidence to compare.
120
+ def <(other)
121
+ if other.is_a?(FieldConfidence)
122
+ to_i < val_to_i(other.value)
123
+ elsif other.is_a?(String)
124
+ to_i < val_to_i(other)
125
+ elsif other.is_a?(Integer)
126
+ to_i < other
127
+ else
128
+ raise ArgumentError, "Invalid type: #{other.class}"
129
+ end
130
+ end
131
+
104
132
  # rubocop:enable Style/CaseLikeIf
105
133
 
106
134
  # Aliases for the comparison operators.
107
135
  alias eql? ==
136
+ alias equal? ==
108
137
  alias gteql? >=
138
+ alias greater_than_or_equal? >=
109
139
  alias lteql? <=
140
+ alias less_than_or_equal? <=
141
+ alias gt? >
142
+ alias greater_than? >
143
+ alias lt? <
144
+ alias less_than? <
110
145
 
111
146
  protected
112
147
 
@@ -46,7 +46,7 @@ module Mindee
46
46
  # @param [String, nil] file_alias File alias, if applicable.
47
47
  # @param [Array<String>, nil] webhook_ids
48
48
  # @param [String, nil] text_context
49
- # @param [Hash, PollingOptions, nil] polling_options
49
+ # @param [Hash, Input::PollingOptions, nil] polling_options
50
50
  # @param [Boolean, nil] close_file
51
51
  # @param [DataSchemaField, String, Hash nil] data_schema
52
52
  def initialize(
@@ -3,7 +3,7 @@
3
3
  # Mindee
4
4
  module Mindee
5
5
  # Current version.
6
- VERSION = '5.3.0'
6
+ VERSION = '5.4.0'
7
7
 
8
8
  # Finds and return the current platform.
9
9
  # @return [Symbol, Hash[String | Symbol, Regexp], Nil?]
@@ -0,0 +1,15 @@
1
+ # lib/http/cancellation_token.rb
2
+
3
+ module Mindee
4
+ module HTTP
5
+ class CancellationToken
6
+ @is_cancelled: bool
7
+
8
+ attr_reader is_canceled: bool
9
+
10
+ def canceled?: -> bool
11
+ def initialize: -> void
12
+ def cancel: -> void
13
+ end
14
+ end
15
+ end
@@ -20,17 +20,17 @@ module Mindee
20
20
  String,
21
21
  ?file_alias: String?,
22
22
  ?webhook_ids: Array[String]?,
23
- ?polling_options: Hash[Symbol | String, untyped] | PollingOptions?,
23
+ ?polling_options: Hash[Symbol | String, untyped] | PollingOptions | nil,
24
24
  ?close_file: bool?
25
25
  ) -> void
26
26
 
27
27
  def append_form_data: (Array[Array[untyped]]) -> Array[Array[untyped]]
28
28
  def validate_async_params: () -> void
29
- def polling_options=: (Hash[Symbol | String, untyped] | PollingOptions?) -> PollingOptions
29
+ def polling_options=: (Hash[Symbol | String, untyped] | PollingOptions | nil) -> PollingOptions
30
30
 
31
31
  private
32
32
 
33
- def get_clean_polling_options: (Hash[String | Symbol, untyped] | PollingOptions?) -> PollingOptions
33
+ def get_clean_polling_options: (Hash[String | Symbol, untyped] | PollingOptions | nil) -> PollingOptions
34
34
  end
35
35
  end
36
36
  end
@@ -17,13 +17,13 @@ module Mindee
17
17
 
18
18
  def enqueue: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> V2::Parsing::JobResponse
19
19
 
20
- def enqueue_and_get_result: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params, ?Hash[String | Symbol, untyped] | Input::PollingOptions?) -> T
20
+ def enqueue_and_get_result: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params, ?Hash[String | Symbol, untyped] | Input::PollingOptions | nil) -> T
21
21
 
22
22
  def search_models: (String?, String?) -> Mindee::V2::Parsing::Search::SearchResponse
23
23
 
24
24
  def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void
25
25
 
26
- def normalize_parameters: (singleton(Input::BaseParameters) param_class, Hash[String | Symbol, untyped] | Input::BaseParameters params, ?polling_options: Hash[String | Symbol, untyped] | Input::PollingOptions?) -> Input::BaseParameters
26
+ def normalize_parameters: (singleton(Input::BaseParameters) param_class, Hash[String | Symbol, untyped] | Input::BaseParameters params, ?polling_options: Hash[String | Symbol, untyped] | Input::PollingOptions | nil) -> Input::BaseParameters
27
27
  end
28
28
  end
29
29
  end
@@ -20,6 +20,15 @@ module Mindee
20
20
  def lteql? : (String | Integer | FieldConfidence) -> bool
21
21
  def >=: (String | Integer | FieldConfidence) -> bool
22
22
  def gteql?: (String | Integer | FieldConfidence) -> bool
23
+ def greater_than_or_equal?: (String | Integer | FieldConfidence) -> bool
24
+ def >: (String | Integer | FieldConfidence) -> bool
25
+ def gt?: (String | Integer | FieldConfidence) -> bool
26
+ def greater_than?: (String | Integer | FieldConfidence) -> bool
27
+ def <: (String | Integer | FieldConfidence) -> bool
28
+ def lt?: (String | Integer | FieldConfidence) -> bool
29
+ def less_than?: (String | Integer | FieldConfidence) -> bool
30
+ def less_than_or_equal?: (String | Integer | FieldConfidence) -> bool
31
+ def equal?: (String | Integer | FieldConfidence) -> bool
23
32
  def inspect: -> String
24
33
 
25
34
  def val_to_i: (String) -> Integer
@@ -12,7 +12,7 @@ module Mindee
12
12
  String,
13
13
  ?file_alias: String?,
14
14
  ?webhook_ids: Array[String]?,
15
- ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions?,
15
+ ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions | nil,
16
16
  ?close_file: bool?
17
17
  ) -> void
18
18
  end
@@ -12,7 +12,7 @@ module Mindee
12
12
  String,
13
13
  ?file_alias: String?,
14
14
  ?webhook_ids: Array[String]?,
15
- ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions?,
15
+ ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions | nil,
16
16
  ?close_file: bool?
17
17
  ) -> void
18
18
  end
@@ -23,7 +23,7 @@ module Mindee
23
23
  ?file_alias: String?,
24
24
  ?text_context: String?,
25
25
  ?webhook_ids: Array[String]?,
26
- ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions?,
26
+ ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions | nil,
27
27
  ?close_file: bool?,
28
28
  ?data_schema: V2::Product::Extraction::Params::DataSchema|String|Hash[Symbol | String, untyped]?
29
29
  ) -> void
@@ -12,7 +12,7 @@ module Mindee
12
12
  String,
13
13
  ?file_alias: String?,
14
14
  ?webhook_ids: Array[String]?,
15
- ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions?,
15
+ ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions | nil,
16
16
  ?close_file: bool?
17
17
  ) -> void
18
18
  end
@@ -12,7 +12,7 @@ module Mindee
12
12
  String,
13
13
  ?file_alias: String?,
14
14
  ?webhook_ids: Array[String]?,
15
- ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions?,
15
+ ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions | nil,
16
16
  ?close_file: bool?
17
17
  ) -> void
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindee
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindee, SA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-03 00:00:00.000000000 Z
11
+ date: 2026-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -247,6 +247,7 @@ files:
247
247
  - lib/mindee/geometry/utils.rb
248
248
  - lib/mindee/http.rb
249
249
  - lib/mindee/http/.rubocop.yml
250
+ - lib/mindee/http/cancellation_token.rb
250
251
  - lib/mindee/http/http_error_handler.rb
251
252
  - lib/mindee/http/response_validation.rb
252
253
  - lib/mindee/image.rb
@@ -491,6 +492,7 @@ files:
491
492
  - sig/mindee/geometry/polygon.rbs
492
493
  - sig/mindee/geometry/quadrilateral.rbs
493
494
  - sig/mindee/geometry/utils.rbs
495
+ - sig/mindee/http/cancellation_token.rbs
494
496
  - sig/mindee/http/http_error_handler.rbs
495
497
  - sig/mindee/http/response_validation.rbs
496
498
  - sig/mindee/image/extracted_image.rbs