diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 75ec52fc..b44b2870 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.3.0" + ".": "2.4.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 1ba53488..7cfdbbab 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c90f13e3cf4b9ae6a1d8f22c0e7285ab12d412d3a659a51a247a97adc7f08121.yml -openapi_spec_hash: bf7879be38ebf3397a939c80b261a47a +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-fb56935a194e69348fecd985f7cf8b249795b46af2fb32f6c5c8ef648cf10c15.yml +openapi_spec_hash: 7260a560474283b7ad6ac5d426058ac9 config_hash: daabb160675d86b354711da1e77e5129 diff --git a/CHANGELOG.md b/CHANGELOG.md index e97d8f56..da98ff0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 2.4.0 (2026-07-12) + +Full Changelog: [v2.3.0...v2.4.0](https://github.com/context-dot-dev/context-ruby-sdk/compare/v2.3.0...v2.4.0) + +### Features + +* **api:** api update ([426deb1](https://github.com/context-dot-dev/context-ruby-sdk/commit/426deb18249b214c3ccaa44c1e654e75ef666dd2)) + ## 2.3.0 (2026-07-12) Full Changelog: [v2.2.0...v2.3.0](https://github.com/context-dot-dev/context-ruby-sdk/compare/v2.2.0...v2.3.0) diff --git a/Gemfile.lock b/Gemfile.lock index c76e641d..3825ad29 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT PATH remote: . specs: - context.dev (2.3.0) + context.dev (2.4.0) cgi connection_pool diff --git a/README.md b/README.md index a54389e3..97485332 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ To use this gem, install via Bundler by adding the following to your application ```ruby -gem "context.dev", "~> 2.3.0" +gem "context.dev", "~> 2.4.0" ``` @@ -213,25 +213,25 @@ context_dev.brand.retrieve(**params) Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime: ```ruby -# :light -puts(ContextDev::WebExtractStyleguideParams::ColorScheme::LIGHT) +# :txt +puts(ContextDev::ParseHandleParams::Extension::TXT) -# Revealed type: `T.all(ContextDev::WebExtractStyleguideParams::ColorScheme, Symbol)` -T.reveal_type(ContextDev::WebExtractStyleguideParams::ColorScheme::LIGHT) +# Revealed type: `T.all(ContextDev::ParseHandleParams::Extension, Symbol)` +T.reveal_type(ContextDev::ParseHandleParams::Extension::TXT) ``` Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value: ```ruby # Using the enum constants preserves the tagged type information: -context_dev.web.extract_styleguide( - color_scheme: ContextDev::WebExtractStyleguideParams::ColorScheme::LIGHT, +context_dev.parse.handle( + extension: ContextDev::ParseHandleParams::Extension::TXT, # … ) # Literal values are also permissible: -context_dev.web.extract_styleguide( - color_scheme: :light, +context_dev.parse.handle( + extension: :txt, # … ) ``` diff --git a/lib/context_dev/models/parse_handle_params.rb b/lib/context_dev/models/parse_handle_params.rb index 12ccdf50..462218dc 100644 --- a/lib/context_dev/models/parse_handle_params.rb +++ b/lib/context_dev/models/parse_handle_params.rb @@ -12,25 +12,12 @@ class ParseHandleParams < ContextDev::Internal::Type::BaseModel # @return [Pathname, StringIO, IO, String, ContextDev::FilePart] required :body, ContextDev::Internal::Type::FileInput - # @!attribute base_url - # Optional HTTP(S) source document URL used to resolve relative links and image - # references. Relative references remain relative when omitted. - # - # @return [String, nil] - optional :base_url, String - # @!attribute extension - # Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, - # md, py, rtf, jpg, png, or txt. - # - # @return [String, nil] - optional :extension, String - - # @!attribute filename - # Optional filename hint used to infer the extension when extension is omitted. + # Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. + # ".pdf"). # - # @return [String, nil] - optional :filename, String + # @return [Symbol, ContextDev::Models::ParseHandleParams::Extension, nil] + optional :extension, enum: -> { ContextDev::ParseHandleParams::Extension } # @!attribute include_images # Include image references in Markdown output @@ -45,26 +32,23 @@ class ParseHandleParams < ContextDev::Internal::Type::BaseModel optional :include_links, ContextDev::Internal::Type::Boolean # @!attribute ocr - # When true for PDF inputs, detect and OCR images embedded in the selected pages, - # inserting recognized text at each image's position in page reading order while - # preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. - # This is separate from automatic scanned-PDF OCR fallback. + # Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted + # at each image's position in page reading order, preserving the text layer; + # pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get + # full-document OCR, and raster images get their visible text transcribed. When + # false, no OCR runs: scanned PDFs may yield no content and images return only + # format/dimension metadata. Calls where OCR actually runs cost 5 credits instead + # of 1. # # @return [Boolean, nil] optional :ocr, ContextDev::Internal::Type::Boolean - # @!attribute pdf_end - # Last 1-based PDF page to parse. When omitted, parsing ends at the last page. - # Must be greater than or equal to pdfStart when both are provided. + # @!attribute pdf + # PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) + # to an inclusive 1-based page range. # - # @return [Integer, nil] - optional :pdf_end, Integer - - # @!attribute pdf_start - # First 1-based PDF page to parse. When omitted, parsing starts at the first page. - # - # @return [Integer, nil] - optional :pdf_start, Integer + # @return [ContextDev::Models::ParseHandleParams::Pdf, nil] + optional :pdf, -> { ContextDev::ParseHandleParams::Pdf } # @!attribute shorten_base64_images # Shorten base64-encoded image data in the Markdown output @@ -78,33 +62,133 @@ class ParseHandleParams < ContextDev::Internal::Type::BaseModel # @return [Boolean, nil] optional :use_main_content_only, ContextDev::Internal::Type::Boolean - # @!method initialize(body:, base_url: nil, extension: nil, filename: nil, include_images: nil, include_links: nil, ocr: nil, pdf_end: nil, pdf_start: nil, shorten_base64_images: nil, use_main_content_only: nil, request_options: {}) + # @!method initialize(body:, extension: nil, include_images: nil, include_links: nil, ocr: nil, pdf: nil, shorten_base64_images: nil, use_main_content_only: nil, request_options: {}) # Some parameter documentations has been truncated, see # {ContextDev::Models::ParseHandleParams} for more details. # # @param body [Pathname, StringIO, IO, String, ContextDev::FilePart] # - # @param base_url [String] Optional HTTP(S) source document URL used to resolve relative links and image re - # - # @param extension [String] Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, md - # - # @param filename [String] Optional filename hint used to infer the extension when extension is omitted. + # @param extension [Symbol, ContextDev::Models::ParseHandleParams::Extension] Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. # # @param include_images [Boolean] Include image references in Markdown output # # @param include_links [Boolean] Preserve hyperlinks in Markdown output # - # @param ocr [Boolean] When true for PDF inputs, detect and OCR images embedded in the selected pages, + # @param ocr [Boolean] Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted # - # @param pdf_end [Integer] Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Mus - # - # @param pdf_start [Integer] First 1-based PDF page to parse. When omitted, parsing starts at the first page. + # @param pdf [ContextDev::Models::ParseHandleParams::Pdf] PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) # # @param shorten_base64_images [Boolean] Shorten base64-encoded image data in the Markdown output # # @param use_main_content_only [Boolean] Extract only the main content from HTML-like inputs # # @param request_options [ContextDev::RequestOptions, Hash{Symbol=>Object}] + + # Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. + # ".pdf"). + module Extension + extend ContextDev::Internal::Type::Enum + + TXT = :txt + TEXT = :text + MD = :md + MARKDOWN = :markdown + HTML = :html + HTM = :htm + XHTML = :xhtml + XML = :xml + RSS = :rss + ATOM = :atom + CSV = :csv + TSV = :tsv + YAML = :yaml + YML = :yml + PY = :py + JAVA = :java + JS = :js + JSX = :jsx + MJS = :mjs + CJS = :cjs + JSON = :json + JSONL = :jsonl + NDJSON = :ndjson + PHP = :php + SH = :sh + BASH = :bash + ZSH = :zsh + FISH = :fish + RB = :rb + TS = :ts + TSX = :tsx + RTF = :rtf + SRT = :srt + CSS = :css + SCSS = :scss + LESS = :less + STYL = :styl + SASS = :sass + SVG = :svg + PDF = :pdf + DOCX = :docx + DOC = :doc + XLSX = :xlsx + XLSM = :xlsm + XLSB = :xlsb + XLTX = :xltx + XLTM = :xltm + XLS = :xls + PPTX = :pptx + PPTM = :pptm + PPSX = :ppsx + PPSM = :ppsm + POTX = :potx + POTM = :potm + PPT = :ppt + PPS = :pps + POT = :pot + JPG = :jpg + JPEG = :jpeg + JPE = :jpe + PNG = :png + GIF = :gif + BMP = :bmp + TIFF = :tiff + TIF = :tif + WEBP = :webp + PPM = :ppm + PBM = :pbm + PGM = :pgm + PNM = :pnm + + # @!method self.values + # @return [Array] + end + + class Pdf < ContextDev::Internal::Type::BaseModel + # @!attribute end_ + # Last 1-based PDF page to parse. When omitted, parsing ends at the last page. + # Must be greater than or equal to start when both are provided. + # + # @return [Integer, nil] + optional :end_, Integer, api_name: :end + + # @!attribute start + # First 1-based PDF page to parse. When omitted, parsing starts at the first page. + # + # @return [Integer, nil] + optional :start, Integer + + # @!method initialize(end_: nil, start: nil) + # Some parameter documentations has been truncated, see + # {ContextDev::Models::ParseHandleParams::Pdf} for more details. + # + # PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) + # to an inclusive 1-based page range. + # + # @param end_ [Integer] Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Mus + # + # @param start [Integer] First 1-based PDF page to parse. When omitted, parsing starts at the first page. + end end end end diff --git a/lib/context_dev/resources/parse.rb b/lib/context_dev/resources/parse.rb index 0e998fe7..6ffd13f7 100644 --- a/lib/context_dev/resources/parse.rb +++ b/lib/context_dev/resources/parse.rb @@ -7,27 +7,23 @@ class Parse # {ContextDev::Models::ParseHandleParams} for more details. # # Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes - # into LLM-usable Markdown. + # into LLM-usable Markdown. The base request costs 1 credit. When OCR runs + # (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no + # OCR ends up running still cost 1 credit. # - # @overload handle(body:, base_url: nil, extension: nil, filename: nil, include_images: nil, include_links: nil, ocr: nil, pdf_end: nil, pdf_start: nil, shorten_base64_images: nil, use_main_content_only: nil, request_options: {}) + # @overload handle(body:, extension: nil, include_images: nil, include_links: nil, ocr: nil, pdf: nil, shorten_base64_images: nil, use_main_content_only: nil, request_options: {}) # # @param body [Pathname, StringIO, IO, String, ContextDev::FilePart] Body param # - # @param base_url [String] Query param: Optional HTTP(S) source document URL used to resolve relative links - # - # @param extension [String] Query param: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, - # - # @param filename [String] Query param: Optional filename hint used to infer the extension when extension i + # @param extension [Symbol, ContextDev::Models::ParseHandleParams::Extension] Query param: Optional file extension hint. Case-insensitive; a leading dot is ac # # @param include_images [Boolean] Query param: Include image references in Markdown output # # @param include_links [Boolean] Query param: Preserve hyperlinks in Markdown output # - # @param ocr [Boolean] Query param: When true for PDF inputs, detect and OCR images embedded in the sel - # - # @param pdf_end [Integer] Query param: Last 1-based PDF page to parse. When omitted, parsing ends at the l + # @param ocr [Boolean] Query param: Gates all OCR. When true, PDFs get embedded-image OCR (recognized t # - # @param pdf_start [Integer] Query param: First 1-based PDF page to parse. When omitted, parsing starts at th + # @param pdf [ContextDev::Models::ParseHandleParams::Pdf] Query param: PDF page-range controls. Use start/end to limit parsing (and OCR wh # # @param shorten_base64_images [Boolean] Query param: Shorten base64-encoded image data in the Markdown output # diff --git a/lib/context_dev/version.rb b/lib/context_dev/version.rb index 59db45d2..56391e07 100644 --- a/lib/context_dev/version.rb +++ b/lib/context_dev/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ContextDev - VERSION = "2.3.0" + VERSION = "2.4.0" end diff --git a/rbi/context_dev/models/parse_handle_params.rbi b/rbi/context_dev/models/parse_handle_params.rbi index 507d3579..23698860 100644 --- a/rbi/context_dev/models/parse_handle_params.rbi +++ b/rbi/context_dev/models/parse_handle_params.rbi @@ -14,29 +14,20 @@ module ContextDev sig { returns(ContextDev::Internal::FileInput) } attr_accessor :body - # Optional HTTP(S) source document URL used to resolve relative links and image - # references. Relative references remain relative when omitted. - sig { returns(T.nilable(String)) } - attr_reader :base_url - - sig { params(base_url: String).void } - attr_writer :base_url - - # Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, - # md, py, rtf, jpg, png, or txt. - sig { returns(T.nilable(String)) } + # Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. + # ".pdf"). + sig do + returns(T.nilable(ContextDev::ParseHandleParams::Extension::OrSymbol)) + end attr_reader :extension - sig { params(extension: String).void } + sig do + params( + extension: ContextDev::ParseHandleParams::Extension::OrSymbol + ).void + end attr_writer :extension - # Optional filename hint used to infer the extension when extension is omitted. - sig { returns(T.nilable(String)) } - attr_reader :filename - - sig { params(filename: String).void } - attr_writer :filename - # Include image references in Markdown output sig { returns(T.nilable(T::Boolean)) } attr_reader :include_images @@ -51,30 +42,26 @@ module ContextDev sig { params(include_links: T::Boolean).void } attr_writer :include_links - # When true for PDF inputs, detect and OCR images embedded in the selected pages, - # inserting recognized text at each image's position in page reading order while - # preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. - # This is separate from automatic scanned-PDF OCR fallback. + # Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted + # at each image's position in page reading order, preserving the text layer; + # pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get + # full-document OCR, and raster images get their visible text transcribed. When + # false, no OCR runs: scanned PDFs may yield no content and images return only + # format/dimension metadata. Calls where OCR actually runs cost 5 credits instead + # of 1. sig { returns(T.nilable(T::Boolean)) } attr_reader :ocr sig { params(ocr: T::Boolean).void } attr_writer :ocr - # Last 1-based PDF page to parse. When omitted, parsing ends at the last page. - # Must be greater than or equal to pdfStart when both are provided. - sig { returns(T.nilable(Integer)) } - attr_reader :pdf_end + # PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) + # to an inclusive 1-based page range. + sig { returns(T.nilable(ContextDev::ParseHandleParams::Pdf)) } + attr_reader :pdf - sig { params(pdf_end: Integer).void } - attr_writer :pdf_end - - # First 1-based PDF page to parse. When omitted, parsing starts at the first page. - sig { returns(T.nilable(Integer)) } - attr_reader :pdf_start - - sig { params(pdf_start: Integer).void } - attr_writer :pdf_start + sig { params(pdf: ContextDev::ParseHandleParams::Pdf::OrHash).void } + attr_writer :pdf # Shorten base64-encoded image data in the Markdown output sig { returns(T.nilable(T::Boolean)) } @@ -93,14 +80,11 @@ module ContextDev sig do params( body: ContextDev::Internal::FileInput, - base_url: String, - extension: String, - filename: String, + extension: ContextDev::ParseHandleParams::Extension::OrSymbol, include_images: T::Boolean, include_links: T::Boolean, ocr: T::Boolean, - pdf_end: Integer, - pdf_start: Integer, + pdf: ContextDev::ParseHandleParams::Pdf::OrHash, shorten_base64_images: T::Boolean, use_main_content_only: T::Boolean, request_options: ContextDev::RequestOptions::OrHash @@ -108,28 +92,24 @@ module ContextDev end def self.new( body:, - # Optional HTTP(S) source document URL used to resolve relative links and image - # references. Relative references remain relative when omitted. - base_url: nil, - # Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, - # md, py, rtf, jpg, png, or txt. + # Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. + # ".pdf"). extension: nil, - # Optional filename hint used to infer the extension when extension is omitted. - filename: nil, # Include image references in Markdown output include_images: nil, # Preserve hyperlinks in Markdown output include_links: nil, - # When true for PDF inputs, detect and OCR images embedded in the selected pages, - # inserting recognized text at each image's position in page reading order while - # preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. - # This is separate from automatic scanned-PDF OCR fallback. + # Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted + # at each image's position in page reading order, preserving the text layer; + # pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get + # full-document OCR, and raster images get their visible text transcribed. When + # false, no OCR runs: scanned PDFs may yield no content and images return only + # format/dimension metadata. Calls where OCR actually runs cost 5 credits instead + # of 1. ocr: nil, - # Last 1-based PDF page to parse. When omitted, parsing ends at the last page. - # Must be greater than or equal to pdfStart when both are provided. - pdf_end: nil, - # First 1-based PDF page to parse. When omitted, parsing starts at the first page. - pdf_start: nil, + # PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) + # to an inclusive 1-based page range. + pdf: nil, # Shorten base64-encoded image data in the Markdown output shorten_base64_images: nil, # Extract only the main content from HTML-like inputs @@ -142,14 +122,11 @@ module ContextDev override.returns( { body: ContextDev::Internal::FileInput, - base_url: String, - extension: String, - filename: String, + extension: ContextDev::ParseHandleParams::Extension::OrSymbol, include_images: T::Boolean, include_links: T::Boolean, ocr: T::Boolean, - pdf_end: Integer, - pdf_start: Integer, + pdf: ContextDev::ParseHandleParams::Pdf, shorten_base64_images: T::Boolean, use_main_content_only: T::Boolean, request_options: ContextDev::RequestOptions @@ -158,6 +135,205 @@ module ContextDev end def to_hash end + + # Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. + # ".pdf"). + module Extension + extend ContextDev::Internal::Type::Enum + + TaggedSymbol = + T.type_alias do + T.all(Symbol, ContextDev::ParseHandleParams::Extension) + end + OrSymbol = T.type_alias { T.any(Symbol, String) } + + TXT = + T.let(:txt, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + TEXT = + T.let(:text, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + MD = T.let(:md, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + MARKDOWN = + T.let( + :markdown, + ContextDev::ParseHandleParams::Extension::TaggedSymbol + ) + HTML = + T.let(:html, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + HTM = + T.let(:htm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XHTML = + T.let(:xhtml, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XML = + T.let(:xml, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + RSS = + T.let(:rss, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + ATOM = + T.let(:atom, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + CSV = + T.let(:csv, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + TSV = + T.let(:tsv, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + YAML = + T.let(:yaml, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + YML = + T.let(:yml, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PY = T.let(:py, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JAVA = + T.let(:java, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JS = T.let(:js, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JSX = + T.let(:jsx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + MJS = + T.let(:mjs, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + CJS = + T.let(:cjs, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JSON = + T.let(:json, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JSONL = + T.let(:jsonl, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + NDJSON = + T.let(:ndjson, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PHP = + T.let(:php, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + SH = T.let(:sh, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + BASH = + T.let(:bash, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + ZSH = + T.let(:zsh, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + FISH = + T.let(:fish, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + RB = T.let(:rb, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + TS = T.let(:ts, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + TSX = + T.let(:tsx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + RTF = + T.let(:rtf, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + SRT = + T.let(:srt, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + CSS = + T.let(:css, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + SCSS = + T.let(:scss, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + LESS = + T.let(:less, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + STYL = + T.let(:styl, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + SASS = + T.let(:sass, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + SVG = + T.let(:svg, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PDF = + T.let(:pdf, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + DOCX = + T.let(:docx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + DOC = + T.let(:doc, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XLSX = + T.let(:xlsx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XLSM = + T.let(:xlsm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XLSB = + T.let(:xlsb, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XLTX = + T.let(:xltx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XLTM = + T.let(:xltm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + XLS = + T.let(:xls, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PPTX = + T.let(:pptx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PPTM = + T.let(:pptm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PPSX = + T.let(:ppsx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PPSM = + T.let(:ppsm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + POTX = + T.let(:potx, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + POTM = + T.let(:potm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PPT = + T.let(:ppt, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PPS = + T.let(:pps, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + POT = + T.let(:pot, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JPG = + T.let(:jpg, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JPEG = + T.let(:jpeg, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + JPE = + T.let(:jpe, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PNG = + T.let(:png, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + GIF = + T.let(:gif, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + BMP = + T.let(:bmp, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + TIFF = + T.let(:tiff, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + TIF = + T.let(:tif, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + WEBP = + T.let(:webp, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PPM = + T.let(:ppm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PBM = + T.let(:pbm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PGM = + T.let(:pgm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + PNM = + T.let(:pnm, ContextDev::ParseHandleParams::Extension::TaggedSymbol) + + sig do + override.returns( + T::Array[ContextDev::ParseHandleParams::Extension::TaggedSymbol] + ) + end + def self.values + end + end + + class Pdf < ContextDev::Internal::Type::BaseModel + OrHash = + T.type_alias do + T.any( + ContextDev::ParseHandleParams::Pdf, + ContextDev::Internal::AnyHash + ) + end + + # Last 1-based PDF page to parse. When omitted, parsing ends at the last page. + # Must be greater than or equal to start when both are provided. + sig { returns(T.nilable(Integer)) } + attr_reader :end_ + + sig { params(end_: Integer).void } + attr_writer :end_ + + # First 1-based PDF page to parse. When omitted, parsing starts at the first page. + sig { returns(T.nilable(Integer)) } + attr_reader :start + + sig { params(start: Integer).void } + attr_writer :start + + # PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) + # to an inclusive 1-based page range. + sig { params(end_: Integer, start: Integer).returns(T.attached_class) } + def self.new( + # Last 1-based PDF page to parse. When omitted, parsing ends at the last page. + # Must be greater than or equal to start when both are provided. + end_: nil, + # First 1-based PDF page to parse. When omitted, parsing starts at the first page. + start: nil + ) + end + + sig { override.returns({ end_: Integer, start: Integer }) } + def to_hash + end + end end end end diff --git a/rbi/context_dev/resources/parse.rbi b/rbi/context_dev/resources/parse.rbi index 47a64342..983b26a0 100644 --- a/rbi/context_dev/resources/parse.rbi +++ b/rbi/context_dev/resources/parse.rbi @@ -4,18 +4,17 @@ module ContextDev module Resources class Parse # Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes - # into LLM-usable Markdown. + # into LLM-usable Markdown. The base request costs 1 credit. When OCR runs + # (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no + # OCR ends up running still cost 1 credit. sig do params( body: ContextDev::Internal::FileInput, - base_url: String, - extension: String, - filename: String, + extension: ContextDev::ParseHandleParams::Extension::OrSymbol, include_images: T::Boolean, include_links: T::Boolean, ocr: T::Boolean, - pdf_end: Integer, - pdf_start: Integer, + pdf: ContextDev::ParseHandleParams::Pdf::OrHash, shorten_base64_images: T::Boolean, use_main_content_only: T::Boolean, request_options: ContextDev::RequestOptions::OrHash @@ -24,30 +23,24 @@ module ContextDev def handle( # Body param body:, - # Query param: Optional HTTP(S) source document URL used to resolve relative links - # and image references. Relative references remain relative when omitted. - base_url: nil, - # Query param: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, - # json, csv, md, py, rtf, jpg, png, or txt. + # Query param: Optional file extension hint. Case-insensitive; a leading dot is + # accepted (e.g. ".pdf"). extension: nil, - # Query param: Optional filename hint used to infer the extension when extension - # is omitted. - filename: nil, # Query param: Include image references in Markdown output include_images: nil, # Query param: Preserve hyperlinks in Markdown output include_links: nil, - # Query param: When true for PDF inputs, detect and OCR images embedded in the - # selected pages, inserting recognized text at each image's position in page - # reading order while preserving the PDF text layer. pdfStart/pdfEnd limit the - # inclusive page range. This is separate from automatic scanned-PDF OCR fallback. + # Query param: Gates all OCR. When true, PDFs get embedded-image OCR (recognized + # text inserted at each image's position in page reading order, preserving the + # text layer; pdf.start/pdf.end limit the page range), scanned PDFs with no text + # layer get full-document OCR, and raster images get their visible text + # transcribed. When false, no OCR runs: scanned PDFs may yield no content and + # images return only format/dimension metadata. Calls where OCR actually runs cost + # 5 credits instead of 1. ocr: nil, - # Query param: Last 1-based PDF page to parse. When omitted, parsing ends at the - # last page. Must be greater than or equal to pdfStart when both are provided. - pdf_end: nil, - # Query param: First 1-based PDF page to parse. When omitted, parsing starts at - # the first page. - pdf_start: nil, + # Query param: PDF page-range controls. Use start/end to limit parsing (and OCR + # when ocr=true) to an inclusive 1-based page range. + pdf: nil, # Query param: Shorten base64-encoded image data in the Markdown output shorten_base64_images: nil, # Query param: Extract only the main content from HTML-like inputs diff --git a/sig/context_dev/models/parse_handle_params.rbs b/sig/context_dev/models/parse_handle_params.rbs index 41a06635..6e3272f7 100644 --- a/sig/context_dev/models/parse_handle_params.rbs +++ b/sig/context_dev/models/parse_handle_params.rbs @@ -3,14 +3,11 @@ module ContextDev type parse_handle_params = { body: ContextDev::Internal::file_input, - base_url: String, - extension: String, - filename: String, + extension: ContextDev::Models::ParseHandleParams::extension, include_images: bool, include_links: bool, ocr: bool, - pdf_end: Integer, - pdf_start: Integer, + pdf: ContextDev::ParseHandleParams::Pdf, :shorten_base64_images => bool, use_main_content_only: bool } @@ -22,17 +19,11 @@ module ContextDev attr_accessor body: ContextDev::Internal::file_input - attr_reader base_url: String? + attr_reader extension: ContextDev::Models::ParseHandleParams::extension? - def base_url=: (String) -> String - - attr_reader extension: String? - - def extension=: (String) -> String - - attr_reader filename: String? - - def filename=: (String) -> String + def extension=: ( + ContextDev::Models::ParseHandleParams::extension + ) -> ContextDev::Models::ParseHandleParams::extension attr_reader include_images: bool? @@ -46,13 +37,11 @@ module ContextDev def ocr=: (bool) -> bool - attr_reader pdf_end: Integer? + attr_reader pdf: ContextDev::ParseHandleParams::Pdf? - def pdf_end=: (Integer) -> Integer - - attr_reader pdf_start: Integer? - - def pdf_start=: (Integer) -> Integer + def pdf=: ( + ContextDev::ParseHandleParams::Pdf + ) -> ContextDev::ParseHandleParams::Pdf attr_reader shorten_base64_images: bool? @@ -64,14 +53,11 @@ module ContextDev def initialize: ( body: ContextDev::Internal::file_input, - ?base_url: String, - ?extension: String, - ?filename: String, + ?extension: ContextDev::Models::ParseHandleParams::extension, ?include_images: bool, ?include_links: bool, ?ocr: bool, - ?pdf_end: Integer, - ?pdf_start: Integer, + ?pdf: ContextDev::ParseHandleParams::Pdf, ?shorten_base64_images: bool, ?use_main_content_only: bool, ?request_options: ContextDev::request_opts @@ -79,18 +65,180 @@ module ContextDev def to_hash: -> { body: ContextDev::Internal::file_input, - base_url: String, - extension: String, - filename: String, + extension: ContextDev::Models::ParseHandleParams::extension, include_images: bool, include_links: bool, ocr: bool, - pdf_end: Integer, - pdf_start: Integer, + pdf: ContextDev::ParseHandleParams::Pdf, :shorten_base64_images => bool, use_main_content_only: bool, request_options: ContextDev::RequestOptions } + + type extension = + :txt + | :text + | :md + | :markdown + | :html + | :htm + | :xhtml + | :xml + | :rss + | :atom + | :csv + | :tsv + | :yaml + | :yml + | :py + | :java + | :js + | :jsx + | :mjs + | :cjs + | :json + | :jsonl + | :ndjson + | :php + | :sh + | :bash + | :zsh + | :fish + | :rb + | :ts + | :tsx + | :rtf + | :srt + | :css + | :scss + | :less + | :styl + | :sass + | :svg + | :pdf + | :docx + | :doc + | :xlsx + | :xlsm + | :xlsb + | :xltx + | :xltm + | :xls + | :pptx + | :pptm + | :ppsx + | :ppsm + | :potx + | :potm + | :ppt + | :pps + | :pot + | :jpg + | :jpeg + | :jpe + | :png + | :gif + | :bmp + | :tiff + | :tif + | :webp + | :ppm + | :pbm + | :pgm + | :pnm + + module Extension + extend ContextDev::Internal::Type::Enum + + TXT: :txt + TEXT: :text + MD: :md + MARKDOWN: :markdown + HTML: :html + HTM: :htm + XHTML: :xhtml + XML: :xml + RSS: :rss + ATOM: :atom + CSV: :csv + TSV: :tsv + YAML: :yaml + YML: :yml + PY: :py + JAVA: :java + JS: :js + JSX: :jsx + MJS: :mjs + CJS: :cjs + JSON: :json + JSONL: :jsonl + NDJSON: :ndjson + PHP: :php + SH: :sh + BASH: :bash + ZSH: :zsh + FISH: :fish + RB: :rb + TS: :ts + TSX: :tsx + RTF: :rtf + SRT: :srt + CSS: :css + SCSS: :scss + LESS: :less + STYL: :styl + SASS: :sass + SVG: :svg + PDF: :pdf + DOCX: :docx + DOC: :doc + XLSX: :xlsx + XLSM: :xlsm + XLSB: :xlsb + XLTX: :xltx + XLTM: :xltm + XLS: :xls + PPTX: :pptx + PPTM: :pptm + PPSX: :ppsx + PPSM: :ppsm + POTX: :potx + POTM: :potm + PPT: :ppt + PPS: :pps + POT: :pot + JPG: :jpg + JPEG: :jpeg + JPE: :jpe + PNG: :png + GIF: :gif + BMP: :bmp + TIFF: :tiff + TIF: :tif + WEBP: :webp + PPM: :ppm + PBM: :pbm + PGM: :pgm + PNM: :pnm + + def self?.values: -> ::Array[ContextDev::Models::ParseHandleParams::extension] + end + + type pdf = { end_: Integer, start: Integer } + + class Pdf < ContextDev::Internal::Type::BaseModel + attr_reader end_: Integer? + + def end_=: (Integer) -> Integer + + attr_reader start: Integer? + + def start=: (Integer) -> Integer + + def initialize: (?end_: Integer, ?start: Integer) -> void + + def to_hash: -> { end_: Integer, start: Integer } + end end end end diff --git a/sig/context_dev/resources/parse.rbs b/sig/context_dev/resources/parse.rbs index f22b9fa6..b2ff7061 100644 --- a/sig/context_dev/resources/parse.rbs +++ b/sig/context_dev/resources/parse.rbs @@ -3,14 +3,11 @@ module ContextDev class Parse def handle: ( body: ContextDev::Internal::file_input, - ?base_url: String, - ?extension: String, - ?filename: String, + ?extension: ContextDev::Models::ParseHandleParams::extension, ?include_images: bool, ?include_links: bool, ?ocr: bool, - ?pdf_end: Integer, - ?pdf_start: Integer, + ?pdf: ContextDev::ParseHandleParams::Pdf, ?shorten_base64_images: bool, ?use_main_content_only: bool, ?request_options: ContextDev::request_opts