openlayer 0.3.0 → 0.4.1
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 +4 -4
- data/.ignore +2 -0
- data/CHANGELOG.md +36 -0
- data/README.md +280 -39
- data/SECURITY.md +27 -0
- data/lib/openlayer/client.rb +64 -59
- data/lib/openlayer/errors.rb +228 -0
- data/lib/openlayer/file_part.rb +58 -0
- data/lib/openlayer/internal/transport/base_client.rb +567 -0
- data/lib/openlayer/internal/transport/pooled_net_requester.rb +198 -0
- data/lib/openlayer/internal/type/array_of.rb +168 -0
- data/lib/openlayer/internal/type/base_model.rb +531 -0
- data/lib/openlayer/internal/type/base_page.rb +55 -0
- data/lib/openlayer/internal/type/boolean.rb +77 -0
- data/lib/openlayer/internal/type/converter.rb +327 -0
- data/lib/openlayer/internal/type/enum.rb +131 -0
- data/lib/openlayer/internal/type/file_input.rb +111 -0
- data/lib/openlayer/internal/type/hash_of.rb +188 -0
- data/lib/openlayer/internal/type/request_parameters.rb +42 -0
- data/lib/openlayer/internal/type/union.rb +237 -0
- data/lib/openlayer/internal/type/unknown.rb +81 -0
- data/lib/openlayer/internal/util.rb +914 -0
- data/lib/openlayer/internal.rb +20 -0
- data/lib/openlayer/models/commit_retrieve_params.rb +14 -0
- data/lib/openlayer/models/commit_retrieve_response.rb +275 -0
- data/lib/openlayer/models/commits/test_result_list_params.rb +91 -0
- data/lib/openlayer/models/commits/test_result_list_response.rb +566 -0
- data/lib/openlayer/models/inference_pipeline_delete_params.rb +14 -0
- data/lib/openlayer/models/inference_pipeline_retrieve_params.rb +33 -0
- data/lib/openlayer/models/inference_pipeline_retrieve_response.rb +605 -0
- data/lib/openlayer/models/inference_pipeline_update_params.rb +42 -0
- data/lib/openlayer/models/inference_pipeline_update_response.rb +605 -0
- data/lib/openlayer/models/inference_pipelines/data_stream_params.rb +463 -0
- data/lib/openlayer/models/inference_pipelines/data_stream_response.rb +28 -0
- data/lib/openlayer/models/inference_pipelines/row_update_params.rb +90 -0
- data/lib/openlayer/models/inference_pipelines/row_update_response.rb +28 -0
- data/lib/openlayer/models/inference_pipelines/test_result_list_params.rb +83 -0
- data/lib/openlayer/models/inference_pipelines/test_result_list_response.rb +568 -0
- data/lib/openlayer/models/project_create_params.rb +51 -0
- data/lib/openlayer/models/project_create_response.rb +262 -0
- data/lib/openlayer/models/project_list_params.rb +59 -0
- data/lib/openlayer/models/project_list_response.rb +274 -0
- data/lib/openlayer/models/projects/commit_create_params.rb +61 -0
- data/lib/openlayer/models/projects/commit_create_response.rb +277 -0
- data/lib/openlayer/models/projects/commit_list_params.rb +32 -0
- data/lib/openlayer/models/projects/commit_list_response.rb +288 -0
- data/lib/openlayer/models/projects/inference_pipeline_create_params.rb +229 -0
- data/lib/openlayer/models/projects/inference_pipeline_create_response.rb +612 -0
- data/lib/openlayer/models/projects/inference_pipeline_list_params.rb +40 -0
- data/lib/openlayer/models/projects/inference_pipeline_list_response.rb +623 -0
- data/lib/openlayer/models/projects/test_create_params.rb +367 -0
- data/lib/openlayer/models/projects/test_create_response.rb +438 -0
- data/lib/openlayer/models/projects/test_list_params.rb +91 -0
- data/lib/openlayer/models/projects/test_list_response.rb +452 -0
- data/lib/openlayer/models/projects/test_update_params.rb +262 -0
- data/lib/openlayer/models/projects/test_update_response.rb +24 -0
- data/lib/openlayer/models/storage/presigned_url_create_params.rb +24 -0
- data/lib/openlayer/models/storage/presigned_url_create_response.rb +35 -0
- data/lib/openlayer/models.rb +61 -0
- data/lib/openlayer/request_options.rb +77 -0
- data/lib/openlayer/resources/commits/test_results.rb +51 -0
- data/lib/openlayer/resources/commits.rb +38 -0
- data/lib/openlayer/resources/inference_pipelines/data.rb +46 -0
- data/lib/openlayer/resources/inference_pipelines/rows.rb +46 -0
- data/lib/openlayer/resources/inference_pipelines/test_results.rb +49 -0
- data/lib/openlayer/resources/inference_pipelines.rb +101 -0
- data/lib/openlayer/resources/projects/commits.rb +72 -0
- data/lib/openlayer/resources/projects/inference_pipelines.rb +74 -0
- data/lib/openlayer/resources/projects/tests.rb +135 -0
- data/lib/openlayer/resources/projects.rb +80 -0
- data/lib/openlayer/resources/storage/presigned_url.rb +38 -0
- data/lib/openlayer/resources/storage.rb +18 -0
- data/lib/openlayer/version.rb +1 -1
- data/lib/openlayer.rb +96 -12
- data/manifest.yaml +15 -0
- data/rbi/openlayer/client.rbi +58 -0
- data/rbi/openlayer/errors.rbi +205 -0
- data/rbi/openlayer/file_part.rbi +37 -0
- data/rbi/openlayer/internal/transport/base_client.rbi +293 -0
- data/rbi/openlayer/internal/transport/pooled_net_requester.rbi +79 -0
- data/rbi/openlayer/internal/type/array_of.rbi +104 -0
- data/rbi/openlayer/internal/type/base_model.rbi +304 -0
- data/rbi/openlayer/internal/type/base_page.rbi +42 -0
- data/rbi/openlayer/internal/type/boolean.rbi +58 -0
- data/rbi/openlayer/internal/type/converter.rbi +216 -0
- data/rbi/openlayer/internal/type/enum.rbi +82 -0
- data/rbi/openlayer/internal/type/file_input.rbi +59 -0
- data/rbi/openlayer/internal/type/hash_of.rbi +104 -0
- data/rbi/openlayer/internal/type/request_parameters.rbi +29 -0
- data/rbi/openlayer/internal/type/union.rbi +128 -0
- data/rbi/openlayer/internal/type/unknown.rbi +58 -0
- data/rbi/openlayer/internal/util.rbi +487 -0
- data/rbi/openlayer/internal.rbi +18 -0
- data/rbi/openlayer/models/commit_retrieve_params.rbi +27 -0
- data/rbi/openlayer/models/commit_retrieve_response.rbi +393 -0
- data/rbi/openlayer/models/commits/test_result_list_params.rbi +214 -0
- data/rbi/openlayer/models/commits/test_result_list_response.rbi +1256 -0
- data/rbi/openlayer/models/inference_pipeline_delete_params.rbi +30 -0
- data/rbi/openlayer/models/inference_pipeline_retrieve_params.rbi +101 -0
- data/rbi/openlayer/models/inference_pipeline_retrieve_response.rbi +1022 -0
- data/rbi/openlayer/models/inference_pipeline_update_params.rbi +67 -0
- data/rbi/openlayer/models/inference_pipeline_update_response.rbi +1018 -0
- data/rbi/openlayer/models/inference_pipelines/data_stream_params.rbi +750 -0
- data/rbi/openlayer/models/inference_pipelines/data_stream_response.rbi +73 -0
- data/rbi/openlayer/models/inference_pipelines/row_update_params.rbi +153 -0
- data/rbi/openlayer/models/inference_pipelines/row_update_response.rbi +73 -0
- data/rbi/openlayer/models/inference_pipelines/test_result_list_params.rbi +216 -0
- data/rbi/openlayer/models/inference_pipelines/test_result_list_response.rbi +1258 -0
- data/rbi/openlayer/models/project_create_params.rbi +99 -0
- data/rbi/openlayer/models/project_create_response.rbi +401 -0
- data/rbi/openlayer/models/project_list_params.rbi +121 -0
- data/rbi/openlayer/models/project_list_response.rbi +442 -0
- data/rbi/openlayer/models/projects/commit_create_params.rbi +125 -0
- data/rbi/openlayer/models/projects/commit_create_response.rbi +409 -0
- data/rbi/openlayer/models/projects/commit_list_params.rbi +62 -0
- data/rbi/openlayer/models/projects/commit_list_response.rbi +454 -0
- data/rbi/openlayer/models/projects/inference_pipeline_create_params.rbi +560 -0
- data/rbi/openlayer/models/projects/inference_pipeline_create_response.rbi +1027 -0
- data/rbi/openlayer/models/projects/inference_pipeline_list_params.rbi +73 -0
- data/rbi/openlayer/models/projects/inference_pipeline_list_response.rbi +1070 -0
- data/rbi/openlayer/models/projects/test_create_params.rbi +940 -0
- data/rbi/openlayer/models/projects/test_create_response.rbi +1026 -0
- data/rbi/openlayer/models/projects/test_list_params.rbi +165 -0
- data/rbi/openlayer/models/projects/test_list_response.rbi +1067 -0
- data/rbi/openlayer/models/projects/test_update_params.rbi +699 -0
- data/rbi/openlayer/models/projects/test_update_response.rbi +43 -0
- data/rbi/openlayer/models/storage/presigned_url_create_params.rbi +45 -0
- data/rbi/openlayer/models/storage/presigned_url_create_response.rbi +55 -0
- data/rbi/openlayer/models.rbi +26 -0
- data/rbi/openlayer/request_options.rbi +59 -0
- data/rbi/openlayer/resources/commits/test_results.rbi +45 -0
- data/rbi/openlayer/resources/commits.rbi +29 -0
- data/rbi/openlayer/resources/inference_pipelines/data.rbi +41 -0
- data/rbi/openlayer/resources/inference_pipelines/rows.rbi +40 -0
- data/rbi/openlayer/resources/inference_pipelines/test_results.rbi +46 -0
- data/rbi/openlayer/resources/inference_pipelines.rbi +79 -0
- data/rbi/openlayer/resources/projects/commits.rbi +60 -0
- data/rbi/openlayer/resources/projects/inference_pipelines.rbi +69 -0
- data/rbi/openlayer/resources/projects/tests.rbi +123 -0
- data/rbi/openlayer/resources/projects.rbi +64 -0
- data/rbi/openlayer/resources/storage/presigned_url.rbi +28 -0
- data/rbi/openlayer/resources/storage.rbi +15 -0
- data/rbi/openlayer/version.rbi +5 -0
- data/sig/openlayer/client.rbs +32 -0
- data/sig/openlayer/errors.rbs +117 -0
- data/sig/openlayer/file_part.rbs +21 -0
- data/sig/openlayer/internal/transport/base_client.rbs +131 -0
- data/sig/openlayer/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/openlayer/internal/type/array_of.rbs +48 -0
- data/sig/openlayer/internal/type/base_model.rbs +102 -0
- data/sig/openlayer/internal/type/base_page.rbs +24 -0
- data/sig/openlayer/internal/type/boolean.rbs +26 -0
- data/sig/openlayer/internal/type/converter.rbs +79 -0
- data/sig/openlayer/internal/type/enum.rbs +32 -0
- data/sig/openlayer/internal/type/file_input.rbs +25 -0
- data/sig/openlayer/internal/type/hash_of.rbs +48 -0
- data/sig/openlayer/internal/type/request_parameters.rbs +19 -0
- data/sig/openlayer/internal/type/union.rbs +52 -0
- data/sig/openlayer/internal/type/unknown.rbs +26 -0
- data/sig/openlayer/internal/util.rbs +185 -0
- data/sig/openlayer/internal.rbs +9 -0
- data/sig/openlayer/models/commit_retrieve_params.rbs +15 -0
- data/sig/openlayer/models/commit_retrieve_response.rbs +209 -0
- data/sig/openlayer/models/commits/test_result_list_params.rbs +91 -0
- data/sig/openlayer/models/commits/test_result_list_response.rbs +529 -0
- data/sig/openlayer/models/inference_pipeline_delete_params.rbs +15 -0
- data/sig/openlayer/models/inference_pipeline_retrieve_params.rbs +41 -0
- data/sig/openlayer/models/inference_pipeline_retrieve_response.rbs +493 -0
- data/sig/openlayer/models/inference_pipeline_update_params.rbs +34 -0
- data/sig/openlayer/models/inference_pipeline_update_response.rbs +493 -0
- data/sig/openlayer/models/inference_pipelines/data_stream_params.rbs +386 -0
- data/sig/openlayer/models/inference_pipelines/data_stream_response.rbs +32 -0
- data/sig/openlayer/models/inference_pipelines/row_update_params.rbs +75 -0
- data/sig/openlayer/models/inference_pipelines/row_update_response.rbs +32 -0
- data/sig/openlayer/models/inference_pipelines/test_result_list_params.rbs +84 -0
- data/sig/openlayer/models/inference_pipelines/test_result_list_response.rbs +529 -0
- data/sig/openlayer/models/project_create_params.rbs +53 -0
- data/sig/openlayer/models/project_create_response.rbs +210 -0
- data/sig/openlayer/models/project_list_params.rbs +68 -0
- data/sig/openlayer/models/project_list_response.rbs +225 -0
- data/sig/openlayer/models/projects/commit_create_params.rbs +82 -0
- data/sig/openlayer/models/projects/commit_create_response.rbs +211 -0
- data/sig/openlayer/models/projects/commit_list_params.rbs +34 -0
- data/sig/openlayer/models/projects/commit_list_response.rbs +228 -0
- data/sig/openlayer/models/projects/inference_pipeline_create_params.rbs +308 -0
- data/sig/openlayer/models/projects/inference_pipeline_create_response.rbs +495 -0
- data/sig/openlayer/models/projects/inference_pipeline_list_params.rbs +40 -0
- data/sig/openlayer/models/projects/inference_pipeline_list_response.rbs +512 -0
- data/sig/openlayer/models/projects/test_create_params.rbs +388 -0
- data/sig/openlayer/models/projects/test_create_response.rbs +427 -0
- data/sig/openlayer/models/projects/test_list_params.rbs +85 -0
- data/sig/openlayer/models/projects/test_list_response.rbs +442 -0
- data/sig/openlayer/models/projects/test_update_params.rbs +275 -0
- data/sig/openlayer/models/projects/test_update_response.rbs +25 -0
- data/sig/openlayer/models/storage/presigned_url_create_params.rbs +25 -0
- data/sig/openlayer/models/storage/presigned_url_create_response.rbs +22 -0
- data/sig/openlayer/models.rbs +21 -0
- data/sig/openlayer/request_options.rbs +34 -0
- data/sig/openlayer/resources/commits/test_results.rbs +19 -0
- data/sig/openlayer/resources/commits.rbs +14 -0
- data/sig/openlayer/resources/inference_pipelines/data.rbs +16 -0
- data/sig/openlayer/resources/inference_pipelines/rows.rbs +17 -0
- data/sig/openlayer/resources/inference_pipelines/test_results.rbs +18 -0
- data/sig/openlayer/resources/inference_pipelines.rbs +32 -0
- data/sig/openlayer/resources/projects/commits.rbs +25 -0
- data/sig/openlayer/resources/projects/inference_pipelines.rbs +26 -0
- data/sig/openlayer/resources/projects/tests.rbs +45 -0
- data/sig/openlayer/resources/projects.rbs +28 -0
- data/sig/openlayer/resources/storage/presigned_url.rbs +14 -0
- data/sig/openlayer/resources/storage.rbs +9 -0
- data/sig/openlayer/version.rbs +3 -0
- metadata +223 -91
- data/.env +0 -0
- data/.rspec +0 -3
- data/.rubocop.yml +0 -13
- data/LICENSE +0 -21
- data/Rakefile +0 -12
- data/examples/staging/.DS_Store +0 -0
- data/examples/staging/commit.yaml +0 -2
- data/examples/staging/model/model_config.yaml +0 -12
- data/examples/staging/validation/dataset_config.yaml +0 -12
- data/lib/openlayer/error.rb +0 -5
- data/lib/openlayer/inference_pipeline.rb +0 -36
- data/lib/openlayer/object.rb +0 -28
- data/lib/openlayer/objects/project.rb +0 -185
- data/lib/openlayer/objects/project_version.rb +0 -89
- data/lib/openlayer/services/s3_presigned_client.rb +0 -47
- data/lib/openlayer/services/tar_file_helper.rb +0 -55
- data/openlayer.gemspec +0 -45
- data/sig/openlayer.rbs +0 -4
| @@ -0,0 +1,567 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Openlayer
         | 
| 4 | 
            +
              module Internal
         | 
| 5 | 
            +
                module Transport
         | 
| 6 | 
            +
                  # @api private
         | 
| 7 | 
            +
                  #
         | 
| 8 | 
            +
                  # @abstract
         | 
| 9 | 
            +
                  class BaseClient
         | 
| 10 | 
            +
                    extend Openlayer::Internal::Util::SorbetRuntimeSupport
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    # from whatwg fetch spec
         | 
| 13 | 
            +
                    MAX_REDIRECTS = 20
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    # rubocop:disable Style/MutableConstant
         | 
| 16 | 
            +
                    PLATFORM_HEADERS =
         | 
| 17 | 
            +
                      {
         | 
| 18 | 
            +
                        "x-stainless-arch" => Openlayer::Internal::Util.arch,
         | 
| 19 | 
            +
                        "x-stainless-lang" => "ruby",
         | 
| 20 | 
            +
                        "x-stainless-os" => Openlayer::Internal::Util.os,
         | 
| 21 | 
            +
                        "x-stainless-package-version" => Openlayer::VERSION,
         | 
| 22 | 
            +
                        "x-stainless-runtime" => ::RUBY_ENGINE,
         | 
| 23 | 
            +
                        "x-stainless-runtime-version" => ::RUBY_ENGINE_VERSION
         | 
| 24 | 
            +
                      }
         | 
| 25 | 
            +
                    # rubocop:enable Style/MutableConstant
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    class << self
         | 
| 28 | 
            +
                      # @api private
         | 
| 29 | 
            +
                      #
         | 
| 30 | 
            +
                      # @param req [Hash{Symbol=>Object}]
         | 
| 31 | 
            +
                      #
         | 
| 32 | 
            +
                      # @raise [ArgumentError]
         | 
| 33 | 
            +
                      def validate!(req)
         | 
| 34 | 
            +
                        keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :stream, :model, :options]
         | 
| 35 | 
            +
                        case req
         | 
| 36 | 
            +
                        in Hash
         | 
| 37 | 
            +
                          req.each_key do |k|
         | 
| 38 | 
            +
                            unless keys.include?(k)
         | 
| 39 | 
            +
                              raise ArgumentError.new("Request `req` keys must be one of #{keys}, got #{k.inspect}")
         | 
| 40 | 
            +
                            end
         | 
| 41 | 
            +
                          end
         | 
| 42 | 
            +
                        else
         | 
| 43 | 
            +
                          raise ArgumentError.new("Request `req` must be a Hash or RequestOptions, got #{req.inspect}")
         | 
| 44 | 
            +
                        end
         | 
| 45 | 
            +
                      end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                      # @api private
         | 
| 48 | 
            +
                      #
         | 
| 49 | 
            +
                      # @param status [Integer]
         | 
| 50 | 
            +
                      # @param headers [Hash{String=>String}]
         | 
| 51 | 
            +
                      #
         | 
| 52 | 
            +
                      # @return [Boolean]
         | 
| 53 | 
            +
                      def should_retry?(status, headers:)
         | 
| 54 | 
            +
                        coerced = Openlayer::Internal::Util.coerce_boolean(headers["x-should-retry"])
         | 
| 55 | 
            +
                        case [coerced, status]
         | 
| 56 | 
            +
                        in [true | false, _]
         | 
| 57 | 
            +
                          coerced
         | 
| 58 | 
            +
                        in [_, 408 | 409 | 429 | (500..)]
         | 
| 59 | 
            +
                          # retry on:
         | 
| 60 | 
            +
                          # 408: timeouts
         | 
| 61 | 
            +
                          # 409: locks
         | 
| 62 | 
            +
                          # 429: rate limits
         | 
| 63 | 
            +
                          # 500+: unknown errors
         | 
| 64 | 
            +
                          true
         | 
| 65 | 
            +
                        else
         | 
| 66 | 
            +
                          false
         | 
| 67 | 
            +
                        end
         | 
| 68 | 
            +
                      end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                      # @api private
         | 
| 71 | 
            +
                      #
         | 
| 72 | 
            +
                      # @param request [Hash{Symbol=>Object}] .
         | 
| 73 | 
            +
                      #
         | 
| 74 | 
            +
                      #   @option request [Symbol] :method
         | 
| 75 | 
            +
                      #
         | 
| 76 | 
            +
                      #   @option request [URI::Generic] :url
         | 
| 77 | 
            +
                      #
         | 
| 78 | 
            +
                      #   @option request [Hash{String=>String}] :headers
         | 
| 79 | 
            +
                      #
         | 
| 80 | 
            +
                      #   @option request [Object] :body
         | 
| 81 | 
            +
                      #
         | 
| 82 | 
            +
                      #   @option request [Integer] :max_retries
         | 
| 83 | 
            +
                      #
         | 
| 84 | 
            +
                      #   @option request [Float] :timeout
         | 
| 85 | 
            +
                      #
         | 
| 86 | 
            +
                      # @param status [Integer]
         | 
| 87 | 
            +
                      #
         | 
| 88 | 
            +
                      # @param response_headers [Hash{String=>String}]
         | 
| 89 | 
            +
                      #
         | 
| 90 | 
            +
                      # @return [Hash{Symbol=>Object}]
         | 
| 91 | 
            +
                      def follow_redirect(request, status:, response_headers:)
         | 
| 92 | 
            +
                        method, url, headers = request.fetch_values(:method, :url, :headers)
         | 
| 93 | 
            +
                        location =
         | 
| 94 | 
            +
                          Kernel.then do
         | 
| 95 | 
            +
                            URI.join(url, response_headers["location"])
         | 
| 96 | 
            +
                          rescue ArgumentError
         | 
| 97 | 
            +
                            message = "Server responded with status #{status} but no valid location header."
         | 
| 98 | 
            +
                            raise Openlayer::Errors::APIConnectionError.new(
         | 
| 99 | 
            +
                              url: url,
         | 
| 100 | 
            +
                              response: response_headers,
         | 
| 101 | 
            +
                              message: message
         | 
| 102 | 
            +
                            )
         | 
| 103 | 
            +
                          end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                        request = {**request, url: location}
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                        case [url.scheme, location.scheme]
         | 
| 108 | 
            +
                        in ["https", "http"]
         | 
| 109 | 
            +
                          message = "Tried to redirect to a insecure URL"
         | 
| 110 | 
            +
                          raise Openlayer::Errors::APIConnectionError.new(
         | 
| 111 | 
            +
                            url: url,
         | 
| 112 | 
            +
                            response: response_headers,
         | 
| 113 | 
            +
                            message: message
         | 
| 114 | 
            +
                          )
         | 
| 115 | 
            +
                        else
         | 
| 116 | 
            +
                          nil
         | 
| 117 | 
            +
                        end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                        # from whatwg fetch spec
         | 
| 120 | 
            +
                        case [status, method]
         | 
| 121 | 
            +
                        in [301 | 302, :post] | [303, _]
         | 
| 122 | 
            +
                          drop = %w[content-encoding content-language content-length content-location content-type]
         | 
| 123 | 
            +
                          request = {
         | 
| 124 | 
            +
                            **request,
         | 
| 125 | 
            +
                            method: method == :head ? :head : :get,
         | 
| 126 | 
            +
                            headers: headers.except(*drop),
         | 
| 127 | 
            +
                            body: nil
         | 
| 128 | 
            +
                          }
         | 
| 129 | 
            +
                        else
         | 
| 130 | 
            +
                        end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                        # from undici
         | 
| 133 | 
            +
                        if Openlayer::Internal::Util.uri_origin(url) != Openlayer::Internal::Util.uri_origin(location)
         | 
| 134 | 
            +
                          drop = %w[authorization cookie host proxy-authorization]
         | 
| 135 | 
            +
                          request = {**request, headers: request.fetch(:headers).except(*drop)}
         | 
| 136 | 
            +
                        end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                        request
         | 
| 139 | 
            +
                      end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                      # @api private
         | 
| 142 | 
            +
                      #
         | 
| 143 | 
            +
                      # @param status [Integer, Openlayer::Errors::APIConnectionError]
         | 
| 144 | 
            +
                      # @param stream [Enumerable<String>, nil]
         | 
| 145 | 
            +
                      def reap_connection!(status, stream:)
         | 
| 146 | 
            +
                        case status
         | 
| 147 | 
            +
                        in (..199) | (300..499)
         | 
| 148 | 
            +
                          stream&.each { next }
         | 
| 149 | 
            +
                        in Openlayer::Errors::APIConnectionError | (500..)
         | 
| 150 | 
            +
                          Openlayer::Internal::Util.close_fused!(stream)
         | 
| 151 | 
            +
                        else
         | 
| 152 | 
            +
                        end
         | 
| 153 | 
            +
                      end
         | 
| 154 | 
            +
                    end
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                    # @return [URI::Generic]
         | 
| 157 | 
            +
                    attr_reader :base_url
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                    # @return [Float]
         | 
| 160 | 
            +
                    attr_reader :timeout
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                    # @return [Integer]
         | 
| 163 | 
            +
                    attr_reader :max_retries
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                    # @return [Float]
         | 
| 166 | 
            +
                    attr_reader :initial_retry_delay
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                    # @return [Float]
         | 
| 169 | 
            +
                    attr_reader :max_retry_delay
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                    # @return [Hash{String=>String}]
         | 
| 172 | 
            +
                    attr_reader :headers
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                    # @return [String, nil]
         | 
| 175 | 
            +
                    attr_reader :idempotency_header
         | 
| 176 | 
            +
             | 
| 177 | 
            +
                    # @api private
         | 
| 178 | 
            +
                    # @return [Openlayer::Internal::Transport::PooledNetRequester]
         | 
| 179 | 
            +
                    attr_reader :requester
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                    # @api private
         | 
| 182 | 
            +
                    #
         | 
| 183 | 
            +
                    # @param base_url [String]
         | 
| 184 | 
            +
                    # @param timeout [Float]
         | 
| 185 | 
            +
                    # @param max_retries [Integer]
         | 
| 186 | 
            +
                    # @param initial_retry_delay [Float]
         | 
| 187 | 
            +
                    # @param max_retry_delay [Float]
         | 
| 188 | 
            +
                    # @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
         | 
| 189 | 
            +
                    # @param idempotency_header [String, nil]
         | 
| 190 | 
            +
                    def initialize(
         | 
| 191 | 
            +
                      base_url:,
         | 
| 192 | 
            +
                      timeout: 0.0,
         | 
| 193 | 
            +
                      max_retries: 0,
         | 
| 194 | 
            +
                      initial_retry_delay: 0.0,
         | 
| 195 | 
            +
                      max_retry_delay: 0.0,
         | 
| 196 | 
            +
                      headers: {},
         | 
| 197 | 
            +
                      idempotency_header: nil
         | 
| 198 | 
            +
                    )
         | 
| 199 | 
            +
                      @requester = Openlayer::Internal::Transport::PooledNetRequester.new
         | 
| 200 | 
            +
                      @headers = Openlayer::Internal::Util.normalized_headers(
         | 
| 201 | 
            +
                        self.class::PLATFORM_HEADERS,
         | 
| 202 | 
            +
                        {
         | 
| 203 | 
            +
                          "accept" => "application/json",
         | 
| 204 | 
            +
                          "content-type" => "application/json"
         | 
| 205 | 
            +
                        },
         | 
| 206 | 
            +
                        headers
         | 
| 207 | 
            +
                      )
         | 
| 208 | 
            +
                      @base_url_components = Openlayer::Internal::Util.parse_uri(base_url)
         | 
| 209 | 
            +
                      @base_url = Openlayer::Internal::Util.unparse_uri(@base_url_components)
         | 
| 210 | 
            +
                      @idempotency_header = idempotency_header&.to_s&.downcase
         | 
| 211 | 
            +
                      @timeout = timeout
         | 
| 212 | 
            +
                      @max_retries = max_retries
         | 
| 213 | 
            +
                      @initial_retry_delay = initial_retry_delay
         | 
| 214 | 
            +
                      @max_retry_delay = max_retry_delay
         | 
| 215 | 
            +
                    end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                    # @api private
         | 
| 218 | 
            +
                    #
         | 
| 219 | 
            +
                    # @return [Hash{String=>String}]
         | 
| 220 | 
            +
                    private def auth_headers = {}
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                    # @api private
         | 
| 223 | 
            +
                    #
         | 
| 224 | 
            +
                    # @return [String]
         | 
| 225 | 
            +
                    private def generate_idempotency_key = "stainless-ruby-retry-#{SecureRandom.uuid}"
         | 
| 226 | 
            +
             | 
| 227 | 
            +
                    # @api private
         | 
| 228 | 
            +
                    #
         | 
| 229 | 
            +
                    # @param req [Hash{Symbol=>Object}] .
         | 
| 230 | 
            +
                    #
         | 
| 231 | 
            +
                    #   @option req [Symbol] :method
         | 
| 232 | 
            +
                    #
         | 
| 233 | 
            +
                    #   @option req [String, Array<String>] :path
         | 
| 234 | 
            +
                    #
         | 
| 235 | 
            +
                    #   @option req [Hash{String=>Array<String>, String, nil}, nil] :query
         | 
| 236 | 
            +
                    #
         | 
| 237 | 
            +
                    #   @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
         | 
| 238 | 
            +
                    #
         | 
| 239 | 
            +
                    #   @option req [Object, nil] :body
         | 
| 240 | 
            +
                    #
         | 
| 241 | 
            +
                    #   @option req [Symbol, Integer, Array<Symbol, Integer>, Proc, nil] :unwrap
         | 
| 242 | 
            +
                    #
         | 
| 243 | 
            +
                    #   @option req [Class<Openlayer::Internal::Type::BasePage>, nil] :page
         | 
| 244 | 
            +
                    #
         | 
| 245 | 
            +
                    #   @option req [Class<Openlayer::Internal::Type::BaseStream>, nil] :stream
         | 
| 246 | 
            +
                    #
         | 
| 247 | 
            +
                    #   @option req [Openlayer::Internal::Type::Converter, Class, nil] :model
         | 
| 248 | 
            +
                    #
         | 
| 249 | 
            +
                    # @param opts [Hash{Symbol=>Object}] .
         | 
| 250 | 
            +
                    #
         | 
| 251 | 
            +
                    #   @option opts [String, nil] :idempotency_key
         | 
| 252 | 
            +
                    #
         | 
| 253 | 
            +
                    #   @option opts [Hash{String=>Array<String>, String, nil}, nil] :extra_query
         | 
| 254 | 
            +
                    #
         | 
| 255 | 
            +
                    #   @option opts [Hash{String=>String, nil}, nil] :extra_headers
         | 
| 256 | 
            +
                    #
         | 
| 257 | 
            +
                    #   @option opts [Object, nil] :extra_body
         | 
| 258 | 
            +
                    #
         | 
| 259 | 
            +
                    #   @option opts [Integer, nil] :max_retries
         | 
| 260 | 
            +
                    #
         | 
| 261 | 
            +
                    #   @option opts [Float, nil] :timeout
         | 
| 262 | 
            +
                    #
         | 
| 263 | 
            +
                    # @return [Hash{Symbol=>Object}]
         | 
| 264 | 
            +
                    private def build_request(req, opts)
         | 
| 265 | 
            +
                      method, uninterpolated_path = req.fetch_values(:method, :path)
         | 
| 266 | 
            +
             | 
| 267 | 
            +
                      path = Openlayer::Internal::Util.interpolate_path(uninterpolated_path)
         | 
| 268 | 
            +
             | 
| 269 | 
            +
                      query = Openlayer::Internal::Util.deep_merge(req[:query].to_h, opts[:extra_query].to_h)
         | 
| 270 | 
            +
             | 
| 271 | 
            +
                      headers = Openlayer::Internal::Util.normalized_headers(
         | 
| 272 | 
            +
                        @headers,
         | 
| 273 | 
            +
                        auth_headers,
         | 
| 274 | 
            +
                        req[:headers].to_h,
         | 
| 275 | 
            +
                        opts[:extra_headers].to_h
         | 
| 276 | 
            +
                      )
         | 
| 277 | 
            +
             | 
| 278 | 
            +
                      if @idempotency_header &&
         | 
| 279 | 
            +
                         !headers.key?(@idempotency_header) &&
         | 
| 280 | 
            +
                         (!Net::HTTP::IDEMPOTENT_METHODS_.include?(method.to_s.upcase) || opts.key?(:idempotency_key))
         | 
| 281 | 
            +
                        headers[@idempotency_header] = opts.fetch(:idempotency_key) { generate_idempotency_key }
         | 
| 282 | 
            +
                      end
         | 
| 283 | 
            +
             | 
| 284 | 
            +
                      unless headers.key?("x-stainless-retry-count")
         | 
| 285 | 
            +
                        headers["x-stainless-retry-count"] = "0"
         | 
| 286 | 
            +
                      end
         | 
| 287 | 
            +
             | 
| 288 | 
            +
                      timeout = opts.fetch(:timeout, @timeout).to_f.clamp(0..)
         | 
| 289 | 
            +
                      unless headers.key?("x-stainless-timeout") || timeout.zero?
         | 
| 290 | 
            +
                        headers["x-stainless-timeout"] = timeout.to_s
         | 
| 291 | 
            +
                      end
         | 
| 292 | 
            +
             | 
| 293 | 
            +
                      headers.reject! { |_, v| v.to_s.empty? }
         | 
| 294 | 
            +
             | 
| 295 | 
            +
                      body =
         | 
| 296 | 
            +
                        case method
         | 
| 297 | 
            +
                        in :get | :head | :options | :trace
         | 
| 298 | 
            +
                          nil
         | 
| 299 | 
            +
                        else
         | 
| 300 | 
            +
                          Openlayer::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
         | 
| 301 | 
            +
                        end
         | 
| 302 | 
            +
             | 
| 303 | 
            +
                      url = Openlayer::Internal::Util.join_parsed_uri(
         | 
| 304 | 
            +
                        @base_url_components,
         | 
| 305 | 
            +
                        {**req, path: path, query: query}
         | 
| 306 | 
            +
                      )
         | 
| 307 | 
            +
                      headers, encoded = Openlayer::Internal::Util.encode_content(headers, body)
         | 
| 308 | 
            +
                      {
         | 
| 309 | 
            +
                        method: method,
         | 
| 310 | 
            +
                        url: url,
         | 
| 311 | 
            +
                        headers: headers,
         | 
| 312 | 
            +
                        body: encoded,
         | 
| 313 | 
            +
                        max_retries: opts.fetch(:max_retries, @max_retries),
         | 
| 314 | 
            +
                        timeout: timeout
         | 
| 315 | 
            +
                      }
         | 
| 316 | 
            +
                    end
         | 
| 317 | 
            +
             | 
| 318 | 
            +
                    # @api private
         | 
| 319 | 
            +
                    #
         | 
| 320 | 
            +
                    # @param headers [Hash{String=>String}]
         | 
| 321 | 
            +
                    # @param retry_count [Integer]
         | 
| 322 | 
            +
                    #
         | 
| 323 | 
            +
                    # @return [Float]
         | 
| 324 | 
            +
                    private def retry_delay(headers, retry_count:)
         | 
| 325 | 
            +
                      # Non-standard extension
         | 
| 326 | 
            +
                      span = Float(headers["retry-after-ms"], exception: false)&.then { _1 / 1000 }
         | 
| 327 | 
            +
                      return span if span
         | 
| 328 | 
            +
             | 
| 329 | 
            +
                      retry_header = headers["retry-after"]
         | 
| 330 | 
            +
                      return span if (span = Float(retry_header, exception: false))
         | 
| 331 | 
            +
             | 
| 332 | 
            +
                      span = retry_header&.then do
         | 
| 333 | 
            +
                        Time.httpdate(_1) - Time.now
         | 
| 334 | 
            +
                      rescue ArgumentError
         | 
| 335 | 
            +
                        nil
         | 
| 336 | 
            +
                      end
         | 
| 337 | 
            +
                      return span if span
         | 
| 338 | 
            +
             | 
| 339 | 
            +
                      scale = retry_count**2
         | 
| 340 | 
            +
                      jitter = 1 - (0.25 * rand)
         | 
| 341 | 
            +
                      (@initial_retry_delay * scale * jitter).clamp(0, @max_retry_delay)
         | 
| 342 | 
            +
                    end
         | 
| 343 | 
            +
             | 
| 344 | 
            +
                    # @api private
         | 
| 345 | 
            +
                    #
         | 
| 346 | 
            +
                    # @param request [Hash{Symbol=>Object}] .
         | 
| 347 | 
            +
                    #
         | 
| 348 | 
            +
                    #   @option request [Symbol] :method
         | 
| 349 | 
            +
                    #
         | 
| 350 | 
            +
                    #   @option request [URI::Generic] :url
         | 
| 351 | 
            +
                    #
         | 
| 352 | 
            +
                    #   @option request [Hash{String=>String}] :headers
         | 
| 353 | 
            +
                    #
         | 
| 354 | 
            +
                    #   @option request [Object] :body
         | 
| 355 | 
            +
                    #
         | 
| 356 | 
            +
                    #   @option request [Integer] :max_retries
         | 
| 357 | 
            +
                    #
         | 
| 358 | 
            +
                    #   @option request [Float] :timeout
         | 
| 359 | 
            +
                    #
         | 
| 360 | 
            +
                    # @param redirect_count [Integer]
         | 
| 361 | 
            +
                    #
         | 
| 362 | 
            +
                    # @param retry_count [Integer]
         | 
| 363 | 
            +
                    #
         | 
| 364 | 
            +
                    # @param send_retry_header [Boolean]
         | 
| 365 | 
            +
                    #
         | 
| 366 | 
            +
                    # @raise [Openlayer::Errors::APIError]
         | 
| 367 | 
            +
                    # @return [Array(Integer, Net::HTTPResponse, Enumerable<String>)]
         | 
| 368 | 
            +
                    def send_request(request, redirect_count:, retry_count:, send_retry_header:)
         | 
| 369 | 
            +
                      url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
         | 
| 370 | 
            +
                      input = {**request.except(:timeout), deadline: Openlayer::Internal::Util.monotonic_secs + timeout}
         | 
| 371 | 
            +
             | 
| 372 | 
            +
                      if send_retry_header
         | 
| 373 | 
            +
                        headers["x-stainless-retry-count"] = retry_count.to_s
         | 
| 374 | 
            +
                      end
         | 
| 375 | 
            +
             | 
| 376 | 
            +
                      begin
         | 
| 377 | 
            +
                        status, response, stream = @requester.execute(input)
         | 
| 378 | 
            +
                      rescue Openlayer::Errors::APIConnectionError => e
         | 
| 379 | 
            +
                        status = e
         | 
| 380 | 
            +
                      end
         | 
| 381 | 
            +
                      headers = Openlayer::Internal::Util.normalized_headers(response&.each_header&.to_h)
         | 
| 382 | 
            +
             | 
| 383 | 
            +
                      case status
         | 
| 384 | 
            +
                      in ..299
         | 
| 385 | 
            +
                        [status, response, stream]
         | 
| 386 | 
            +
                      in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
         | 
| 387 | 
            +
                        self.class.reap_connection!(status, stream: stream)
         | 
| 388 | 
            +
             | 
| 389 | 
            +
                        message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
         | 
| 390 | 
            +
                        raise Openlayer::Errors::APIConnectionError.new(url: url, response: response, message: message)
         | 
| 391 | 
            +
                      in 300..399
         | 
| 392 | 
            +
                        self.class.reap_connection!(status, stream: stream)
         | 
| 393 | 
            +
             | 
| 394 | 
            +
                        request = self.class.follow_redirect(request, status: status, response_headers: headers)
         | 
| 395 | 
            +
                        send_request(
         | 
| 396 | 
            +
                          request,
         | 
| 397 | 
            +
                          redirect_count: redirect_count + 1,
         | 
| 398 | 
            +
                          retry_count: retry_count,
         | 
| 399 | 
            +
                          send_retry_header: send_retry_header
         | 
| 400 | 
            +
                        )
         | 
| 401 | 
            +
                      in Openlayer::Errors::APIConnectionError if retry_count >= max_retries
         | 
| 402 | 
            +
                        raise status
         | 
| 403 | 
            +
                      in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: headers)
         | 
| 404 | 
            +
                        decoded = Kernel.then do
         | 
| 405 | 
            +
                          Openlayer::Internal::Util.decode_content(headers, stream: stream, suppress_error: true)
         | 
| 406 | 
            +
                        ensure
         | 
| 407 | 
            +
                          self.class.reap_connection!(status, stream: stream)
         | 
| 408 | 
            +
                        end
         | 
| 409 | 
            +
             | 
| 410 | 
            +
                        raise Openlayer::Errors::APIStatusError.for(
         | 
| 411 | 
            +
                          url: url,
         | 
| 412 | 
            +
                          status: status,
         | 
| 413 | 
            +
                          headers: headers,
         | 
| 414 | 
            +
                          body: decoded,
         | 
| 415 | 
            +
                          request: nil,
         | 
| 416 | 
            +
                          response: response
         | 
| 417 | 
            +
                        )
         | 
| 418 | 
            +
                      in (400..) | Openlayer::Errors::APIConnectionError
         | 
| 419 | 
            +
                        self.class.reap_connection!(status, stream: stream)
         | 
| 420 | 
            +
             | 
| 421 | 
            +
                        delay = retry_delay(response || {}, retry_count: retry_count)
         | 
| 422 | 
            +
                        sleep(delay)
         | 
| 423 | 
            +
             | 
| 424 | 
            +
                        send_request(
         | 
| 425 | 
            +
                          request,
         | 
| 426 | 
            +
                          redirect_count: redirect_count,
         | 
| 427 | 
            +
                          retry_count: retry_count + 1,
         | 
| 428 | 
            +
                          send_retry_header: send_retry_header
         | 
| 429 | 
            +
                        )
         | 
| 430 | 
            +
                      end
         | 
| 431 | 
            +
                    end
         | 
| 432 | 
            +
             | 
| 433 | 
            +
                    # Execute the request specified by `req`. This is the method that all resource
         | 
| 434 | 
            +
                    # methods call into.
         | 
| 435 | 
            +
                    #
         | 
| 436 | 
            +
                    # @overload request(method, path, query: {}, headers: {}, body: nil, unwrap: nil, page: nil, stream: nil, model: Openlayer::Internal::Type::Unknown, options: {})
         | 
| 437 | 
            +
                    #
         | 
| 438 | 
            +
                    # @param method [Symbol]
         | 
| 439 | 
            +
                    #
         | 
| 440 | 
            +
                    # @param path [String, Array<String>]
         | 
| 441 | 
            +
                    #
         | 
| 442 | 
            +
                    # @param query [Hash{String=>Array<String>, String, nil}, nil]
         | 
| 443 | 
            +
                    #
         | 
| 444 | 
            +
                    # @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil]
         | 
| 445 | 
            +
                    #
         | 
| 446 | 
            +
                    # @param body [Object, nil]
         | 
| 447 | 
            +
                    #
         | 
| 448 | 
            +
                    # @param unwrap [Symbol, Integer, Array<Symbol, Integer>, Proc, nil]
         | 
| 449 | 
            +
                    #
         | 
| 450 | 
            +
                    # @param page [Class<Openlayer::Internal::Type::BasePage>, nil]
         | 
| 451 | 
            +
                    #
         | 
| 452 | 
            +
                    # @param stream [Class<Openlayer::Internal::Type::BaseStream>, nil]
         | 
| 453 | 
            +
                    #
         | 
| 454 | 
            +
                    # @param model [Openlayer::Internal::Type::Converter, Class, nil]
         | 
| 455 | 
            +
                    #
         | 
| 456 | 
            +
                    # @param options [Openlayer::RequestOptions, Hash{Symbol=>Object}, nil] .
         | 
| 457 | 
            +
                    #
         | 
| 458 | 
            +
                    #   @option options [String, nil] :idempotency_key
         | 
| 459 | 
            +
                    #
         | 
| 460 | 
            +
                    #   @option options [Hash{String=>Array<String>, String, nil}, nil] :extra_query
         | 
| 461 | 
            +
                    #
         | 
| 462 | 
            +
                    #   @option options [Hash{String=>String, nil}, nil] :extra_headers
         | 
| 463 | 
            +
                    #
         | 
| 464 | 
            +
                    #   @option options [Object, nil] :extra_body
         | 
| 465 | 
            +
                    #
         | 
| 466 | 
            +
                    #   @option options [Integer, nil] :max_retries
         | 
| 467 | 
            +
                    #
         | 
| 468 | 
            +
                    #   @option options [Float, nil] :timeout
         | 
| 469 | 
            +
                    #
         | 
| 470 | 
            +
                    # @raise [Openlayer::Errors::APIError]
         | 
| 471 | 
            +
                    # @return [Object]
         | 
| 472 | 
            +
                    def request(req)
         | 
| 473 | 
            +
                      self.class.validate!(req)
         | 
| 474 | 
            +
                      model = req.fetch(:model) { Openlayer::Internal::Type::Unknown }
         | 
| 475 | 
            +
                      opts = req[:options].to_h
         | 
| 476 | 
            +
                      unwrap = req[:unwrap]
         | 
| 477 | 
            +
                      Openlayer::RequestOptions.validate!(opts)
         | 
| 478 | 
            +
                      request = build_request(req.except(:options), opts)
         | 
| 479 | 
            +
                      url = request.fetch(:url)
         | 
| 480 | 
            +
             | 
| 481 | 
            +
                      # Don't send the current retry count in the headers if the caller modified the header defaults.
         | 
| 482 | 
            +
                      send_retry_header = request.fetch(:headers)["x-stainless-retry-count"] == "0"
         | 
| 483 | 
            +
                      status, response, stream = send_request(
         | 
| 484 | 
            +
                        request,
         | 
| 485 | 
            +
                        redirect_count: 0,
         | 
| 486 | 
            +
                        retry_count: 0,
         | 
| 487 | 
            +
                        send_retry_header: send_retry_header
         | 
| 488 | 
            +
                      )
         | 
| 489 | 
            +
             | 
| 490 | 
            +
                      headers = Openlayer::Internal::Util.normalized_headers(response.each_header.to_h)
         | 
| 491 | 
            +
                      decoded = Openlayer::Internal::Util.decode_content(headers, stream: stream)
         | 
| 492 | 
            +
                      case req
         | 
| 493 | 
            +
                      in {stream: Class => st}
         | 
| 494 | 
            +
                        st.new(
         | 
| 495 | 
            +
                          model: model,
         | 
| 496 | 
            +
                          url: url,
         | 
| 497 | 
            +
                          status: status,
         | 
| 498 | 
            +
                          headers: headers,
         | 
| 499 | 
            +
                          response: response,
         | 
| 500 | 
            +
                          unwrap: unwrap,
         | 
| 501 | 
            +
                          stream: decoded
         | 
| 502 | 
            +
                        )
         | 
| 503 | 
            +
                      in {page: Class => page}
         | 
| 504 | 
            +
                        page.new(client: self, req: req, headers: headers, page_data: decoded)
         | 
| 505 | 
            +
                      else
         | 
| 506 | 
            +
                        unwrapped = Openlayer::Internal::Util.dig(decoded, unwrap)
         | 
| 507 | 
            +
                        Openlayer::Internal::Type::Converter.coerce(model, unwrapped)
         | 
| 508 | 
            +
                      end
         | 
| 509 | 
            +
                    end
         | 
| 510 | 
            +
             | 
| 511 | 
            +
                    # @api private
         | 
| 512 | 
            +
                    #
         | 
| 513 | 
            +
                    # @return [String]
         | 
| 514 | 
            +
                    def inspect
         | 
| 515 | 
            +
                      # rubocop:disable Layout/LineLength
         | 
| 516 | 
            +
                      "#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{@base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
         | 
| 517 | 
            +
                      # rubocop:enable Layout/LineLength
         | 
| 518 | 
            +
                    end
         | 
| 519 | 
            +
             | 
| 520 | 
            +
                    define_sorbet_constant!(:RequestComponents) do
         | 
| 521 | 
            +
                      T.type_alias do
         | 
| 522 | 
            +
                        {
         | 
| 523 | 
            +
                          method: Symbol,
         | 
| 524 | 
            +
                          path: T.any(String, T::Array[String]),
         | 
| 525 | 
            +
                          query: T.nilable(T::Hash[String, T.nilable(T.any(T::Array[String], String))]),
         | 
| 526 | 
            +
                          headers: T.nilable(
         | 
| 527 | 
            +
                            T::Hash[String,
         | 
| 528 | 
            +
                                    T.nilable(
         | 
| 529 | 
            +
                                      T.any(
         | 
| 530 | 
            +
                                        String,
         | 
| 531 | 
            +
                                        Integer,
         | 
| 532 | 
            +
                                        T::Array[T.nilable(T.any(String, Integer))]
         | 
| 533 | 
            +
                                      )
         | 
| 534 | 
            +
                                    )]
         | 
| 535 | 
            +
                          ),
         | 
| 536 | 
            +
                          body: T.nilable(T.anything),
         | 
| 537 | 
            +
                          unwrap: T.nilable(
         | 
| 538 | 
            +
                            T.any(
         | 
| 539 | 
            +
                              Symbol,
         | 
| 540 | 
            +
                              Integer,
         | 
| 541 | 
            +
                              T::Array[T.any(Symbol, Integer)],
         | 
| 542 | 
            +
                              T.proc.params(arg0: T.anything).returns(T.anything)
         | 
| 543 | 
            +
                            )
         | 
| 544 | 
            +
                          ),
         | 
| 545 | 
            +
                          page: T.nilable(T::Class[Openlayer::Internal::Type::BasePage[Openlayer::Internal::Type::BaseModel]]),
         | 
| 546 | 
            +
                          stream: T.nilable(T::Class[T.anything]),
         | 
| 547 | 
            +
                          model: T.nilable(Openlayer::Internal::Type::Converter::Input),
         | 
| 548 | 
            +
                          options: T.nilable(Openlayer::RequestOptions::OrHash)
         | 
| 549 | 
            +
                        }
         | 
| 550 | 
            +
                      end
         | 
| 551 | 
            +
                    end
         | 
| 552 | 
            +
                    define_sorbet_constant!(:RequestInput) do
         | 
| 553 | 
            +
                      T.type_alias do
         | 
| 554 | 
            +
                        {
         | 
| 555 | 
            +
                          method: Symbol,
         | 
| 556 | 
            +
                          url: URI::Generic,
         | 
| 557 | 
            +
                          headers: T::Hash[String, String],
         | 
| 558 | 
            +
                          body: T.anything,
         | 
| 559 | 
            +
                          max_retries: Integer,
         | 
| 560 | 
            +
                          timeout: Float
         | 
| 561 | 
            +
                        }
         | 
| 562 | 
            +
                      end
         | 
| 563 | 
            +
                    end
         | 
| 564 | 
            +
                  end
         | 
| 565 | 
            +
                end
         | 
| 566 | 
            +
              end
         | 
| 567 | 
            +
            end
         |