typesafe-sdk-ruby 0.6.0.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,22 @@ module Typesafe
13
13
  end
14
14
  end
15
15
 
16
- # Token usage for a request.
16
+ # An answer, keeping every field the API returned, including fields not modeled here.
17
+ class Answer
18
+ attr_reader :type
19
+
20
+ def initialize(data)
21
+ @data = data
22
+ @type = data["type"]
23
+ end
24
+
25
+ # The answer as the API returned it, with string keys.
26
+ def to_h
27
+ @data.dup
28
+ end
29
+ end
30
+
31
+ # Token usage for a request. Each count is `nil` when the API did not report it.
17
32
  class Usage
18
33
  attr_reader :input_tokens, :output_tokens
19
34
 
@@ -24,21 +39,21 @@ module Typesafe
24
39
  end
25
40
 
26
41
  # A yes/no answer.
27
- class NoulResponse
28
- attr_reader :type, :noul
42
+ class NoulResponse < Answer
43
+ attr_reader :noul
29
44
 
30
45
  def initialize(data)
31
- @type = data["type"]
46
+ super
32
47
  @noul = data["noul"]
33
48
  end
34
49
  end
35
50
 
36
51
  # A selected label with its probabilities.
37
- class ChoiceResponse
38
- attr_reader :type, :choice, :confidence, :probabilities
52
+ class ChoiceResponse < Answer
53
+ attr_reader :choice, :confidence, :probabilities
39
54
 
40
55
  def initialize(data)
41
- @type = data["type"]
56
+ super
42
57
  @choice = data["choice"]
43
58
  @confidence = data["confidence"]
44
59
  @probabilities = data["probabilities"]
@@ -46,11 +61,11 @@ module Typesafe
46
61
  end
47
62
 
48
63
  # An expected score with its rubric and probabilities.
49
- class ScoreResponse
50
- attr_reader :type, :score, :confidence, :legend, :probabilities
64
+ class ScoreResponse < Answer
65
+ attr_reader :score, :confidence, :legend, :probabilities
51
66
 
52
67
  def initialize(data)
53
- @type = data["type"]
68
+ super
54
69
  @score = data["score"]
55
70
  @confidence = data["confidence"]
56
71
  @legend = data["legend"]
@@ -58,12 +73,44 @@ module Typesafe
58
73
  end
59
74
  end
60
75
 
76
+ # A box's edges as fractions of the image's height (`top`, `bottom`) and width
77
+ # (`left`, `right`), each from zero to one.
78
+ class BoxCoordinates
79
+ attr_reader :top, :bottom, :left, :right
80
+
81
+ def initialize(data)
82
+ @top = data["top"]
83
+ @bottom = data["bottom"]
84
+ @left = data["left"]
85
+ @right = data["right"]
86
+ end
87
+
88
+ def to_h
89
+ { "top" => top, "bottom" => bottom, "left" => left, "right" => right }
90
+ end
91
+ end
92
+
93
+ # The answer to a box question.
94
+ class BoxResponse < Answer
95
+ # Where the instructions' subject is in the image, or `nil` when absent.
96
+ attr_reader :box
97
+ # Confidence in the box, from zero to one, or `nil` when the API didn't report it.
98
+ attr_reader :confidence
99
+
100
+ def initialize(data)
101
+ super
102
+ @box = data["box"].is_a?(Hash) ? BoxCoordinates.new(data["box"]) : nil
103
+ @confidence = data["confidence"]
104
+ end
105
+ end
106
+
61
107
  # Builds the answer object matching the question type.
62
108
  module ResponseFactory
63
109
  CLASSES = {
64
110
  "noul" => NoulResponse,
65
111
  "choice" => ChoiceResponse,
66
- "score" => ScoreResponse
112
+ "score" => ScoreResponse,
113
+ "box" => BoxResponse
67
114
  }.freeze
68
115
 
69
116
  module_function
@@ -3,7 +3,7 @@
3
3
  module Typesafe
4
4
  module SDK
5
5
  # Ruby-only fixes use a fourth numeric component; the first three track upstream.
6
- VERSION = "0.6.0.1"
7
- UPSTREAM_VERSION = "0.6.0"
6
+ VERSION = "0.7.0"
7
+ UPSTREAM_VERSION = "0.7.0"
8
8
  end
9
9
  end
@@ -5,6 +5,8 @@ require_relative "typesafe/sdk/env"
5
5
  require_relative "typesafe/sdk/logging"
6
6
  require_relative "typesafe/sdk/retry"
7
7
  require_relative "typesafe/sdk/errors"
8
+ require_relative "typesafe/sdk/assets"
9
+ require_relative "typesafe/sdk/compression"
8
10
  require_relative "typesafe/sdk/questions"
9
11
  require_relative "typesafe/sdk/http"
10
12
  require_relative "typesafe/sdk/types"
@@ -36,5 +38,33 @@ module Typesafe
36
38
  def choice(instructions, criteria)
37
39
  Questions.choice(instructions, criteria)
38
40
  end
41
+
42
+ # Create a box question. @see Questions.box
43
+ def box(instructions = nil)
44
+ Questions.box(instructions)
45
+ end
46
+
47
+ # Create a PNG or JPEG image asset from file bytes, a Pathname, or an IO.
48
+ # Use {Image.from_base64} for base64 text. @see Image#initialize
49
+ def image(data)
50
+ Image.new(data)
51
+ end
52
+
53
+ # Join text and images into text that carries its images, like JavaScript's `withAssets`
54
+ # tagged template. Other values are converted with `to_s`, as string interpolation does.
55
+ #
56
+ # @example
57
+ # Typesafe::SDK.with_assets("Does ", photo, " show the product in ", listing, "?")
58
+ # @return [TextWithAssets]
59
+ def with_assets(*parts)
60
+ TextWithAssets.build(*parts)
61
+ end
62
+
63
+ # Join `values` with `separator` (default `","`, as in JavaScript's `withAssets.join`) into
64
+ # text that carries the images among them.
65
+ # @return [TextWithAssets]
66
+ def join_assets(values, separator = ",")
67
+ TextWithAssets.join(values, separator)
68
+ end
39
69
  end
40
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typesafe-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TypeSafe Ruby SDK Contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-21 00:00:00.000000000 Z
11
+ date: 2026-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -32,8 +32,9 @@ dependencies:
32
32
  version: '3'
33
33
  description: |-
34
34
  Unofficial Ruby SDK for the TypeSafe AI API (Jev model). Ask named questions about
35
- text or structured state and get typed answers: yes/no (noul), choice, and score
36
- questions, with retries, timeouts, structured logging, and typed errors.
35
+ text, structured state, or images and get typed answers: yes/no (noul), choice, score,
36
+ and box questions, with retries, timeouts, request compression, structured logging, and
37
+ typed errors.
37
38
  email:
38
39
  executables: []
39
40
  extensions: []
@@ -46,7 +47,9 @@ files:
46
47
  - docs/RELEASING.md
47
48
  - docs/UPSTREAM_ISSUES.md
48
49
  - lib/typesafe-sdk-ruby.rb
50
+ - lib/typesafe/sdk/assets.rb
49
51
  - lib/typesafe/sdk/client.rb
52
+ - lib/typesafe/sdk/compression.rb
50
53
  - lib/typesafe/sdk/env.rb
51
54
  - lib/typesafe/sdk/errors.rb
52
55
  - lib/typesafe/sdk/http.rb