jev-feels 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb1c944edfc8044a07d64239c6452cf8717eee7a2878777b010ce06c7e328794
4
+ data.tar.gz: 4c4092c5de15890bb9897934dffe82c515a236e441444caf016e282d20046060
5
+ SHA512:
6
+ metadata.gz: c01170a2578338e6d8359399873593357c7896a2fa536eca538edd82830925d597e0bf6a6b5ffddb2fce804e9c974be6fe9a7eb7b62109d4078987f53743de75
7
+ data.tar.gz: 41919c36db8eb4497f57acac8ee0c02bcca2f8cb5e7a5bf7b347dadda62253e80a7b5a20274f5db199ea5642e5eb98c82909ac8b9546920a336bc9e5c54d2e8e
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maxim Veysgeym
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # jev-feels
2
+
3
+ Semantic checks as ordinary Ruby conditions.
4
+
5
+ ```ruby
6
+ # Gemfile
7
+ gem "jev-feels"
8
+
9
+ require "feels"
10
+
11
+ Jev.configure do |config|
12
+ config.api_key = ENV.fetch("JEV_API_KEY")
13
+ end
14
+
15
+ Jev.define :urgent, "Requires immediate attention or action"
16
+
17
+ email = <<~EMAIL
18
+ Our production server has stopped responding.
19
+ Customers cannot access their accounts.
20
+ Please investigate immediately.
21
+ EMAIL
22
+
23
+ if Jev.feels?(email, :urgent)
24
+ puts "URGENT"
25
+ end
26
+ ```
27
+
28
+ ## String sugar
29
+
30
+ `require "feels"` does not change `String`. Opt in with a refinement:
31
+
32
+ ```ruby
33
+ using Jev::Feels
34
+
35
+ email.feels?(:urgent)
36
+ ```
37
+
38
+ Or, if you really want a global patch:
39
+
40
+ ```ruby
41
+ require "feels/string"
42
+
43
+ email.feels?(:urgent)
44
+ ```
45
+
46
+ ## Probability vs predicate
47
+
48
+ ```ruby
49
+ email.feels(:urgent)
50
+ # => 0.94
51
+
52
+ email.feels?(:urgent)
53
+ # => true
54
+ ```
55
+
56
+ `feels` is the calibrated probability that the predicate holds (a Jev [Noul](https://docs.typesafe.ai/primitives/noul.md), `0.0..1.0`).
57
+ `feels?` is `feels >= threshold`. The default threshold is `0.5`.
58
+
59
+ ```ruby
60
+ email.feels?(:urgent, threshold: 0.8)
61
+ ```
62
+
63
+ ## Ad-hoc predicates
64
+
65
+ A `String` predicate is used as-is and is **not** registered:
66
+
67
+ ```ruby
68
+ email.feels?("sounds like the sender is about to cancel their subscription")
69
+ ```
70
+
71
+ A `Symbol` must already have a definition or you get `Jev::UndefinedDefinition`.
72
+
73
+ ## Definitions
74
+
75
+ ```ruby
76
+ Jev.define :urgent, "Requires immediate attention or action"
77
+ Jev.define :spam, "Unsolicited or unwanted promotional content"
78
+ Jev.define :angry, "Expresses anger or hostility"
79
+
80
+ Jev.definition(:urgent)
81
+ Jev.definitions
82
+ ```
83
+
84
+ `define` replaces an existing name. `definitions` returns a frozen copy of the registry.
85
+
86
+ ## Configuration
87
+
88
+ ```ruby
89
+ Jev.configure do |config|
90
+ config.api_key = ENV["JEV_API_KEY"]
91
+ config.base_url = "https://api.typesafe.ai"
92
+ config.timeout = 10
93
+ config.threshold = 0.5
94
+ end
95
+ ```
96
+
97
+ For tests, inject a transport and skip the network:
98
+
99
+ ```ruby
100
+ Jev.configure do |config|
101
+ config.transport = ->(_payload) {
102
+ { "answers" => { "feels" => { "type" => "noul", "noul" => 0.9 } } }
103
+ }
104
+ end
105
+ ```
106
+
107
+ ```ruby
108
+ Jev.reset_configuration!
109
+ Jev.reset_definitions!
110
+ ```
111
+
112
+ ## Errors
113
+
114
+ All errors inherit from `Jev::Error`. HTTP failures are wrapped; the original exception is available as `cause`. API keys are redacted from messages.
115
+
116
+ | Error | When |
117
+ | --- | --- |
118
+ | `Jev::ConfigurationError` | Missing API key |
119
+ | `Jev::UndefinedDefinition` | Unknown symbol predicate |
120
+ | `Jev::AuthenticationError` | HTTP 401 |
121
+ | `Jev::RateLimitError` | HTTP 429 |
122
+ | `Jev::InvalidResponseError` | Unparseable or shapeless body |
123
+ | `Jev::RequestError` | Timeouts, network errors, other HTTP failures |
124
+
125
+ ## What this talks to
126
+
127
+ [Jev](https://docs.typesafe.ai/introduction.md) / TypeSafe System One. `POST https://api.typesafe.ai/v1/systemone` with a Noul question. That is an implementation detail of `feels`; the public API is just `Jev.feels` / `Jev.feels?`.
data/context7.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://context7.com/schema/context7.json",
3
+ "projectTitle": "jev-feels",
4
+ "description": "Ruby-like semantic text predicates via Jev. Jev.feels?(:urgent) is an ordinary condition, not an SDK session.",
5
+ "excludeFolders": ["spec"]
6
+ }
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "feels"
4
+
5
+ class String
6
+ def feels(...)
7
+ Jev.feels(self, ...)
8
+ end
9
+
10
+ def feels?(...)
11
+ Jev.feels?(self, ...)
12
+ end
13
+ end
data/lib/feels.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jev"
data/lib/jev/client.rb ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jev
4
+ class Client
5
+ QUESTION_ID = "feels"
6
+ MODEL = "jev-latest"
7
+
8
+ def initialize(configuration)
9
+ @configuration = configuration
10
+ end
11
+
12
+ def probability(text, instructions)
13
+ extract_noul(transport.call(payload(text, instructions)))
14
+ end
15
+
16
+ private
17
+
18
+ def transport
19
+ @configuration.transport || Transport.new(@configuration)
20
+ end
21
+
22
+ def payload(text, instructions)
23
+ {
24
+ "model" => MODEL,
25
+ "state" => text,
26
+ "questions" => {
27
+ QUESTION_ID => {
28
+ "type" => "noul",
29
+ "instructions" => instructions
30
+ }
31
+ }
32
+ }
33
+ end
34
+
35
+ def extract_noul(body)
36
+ raise InvalidResponseError, "Jev response is not a JSON object" unless body.is_a?(Hash)
37
+
38
+ answers = body["answers"]
39
+ raise InvalidResponseError, "Jev response is missing answers" unless answers.is_a?(Hash)
40
+
41
+ answer = answers[QUESTION_ID]
42
+ raise InvalidResponseError, "Jev response is missing the feels answer" unless answer.is_a?(Hash)
43
+
44
+ noul = answer["noul"]
45
+ raise InvalidResponseError, "Jev response is missing a noul probability" unless noul.is_a?(Numeric)
46
+
47
+ noul = Float(noul)
48
+ raise InvalidResponseError, "Jev noul probability is not finite" unless noul.finite?
49
+
50
+ # ponytail: clamp out-of-range noul; raise if Jev starts returning uncalibrated values
51
+ noul.clamp(0.0, 1.0)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jev
4
+ class Configuration
5
+ DEFAULT_BASE_URL = "https://api.typesafe.ai"
6
+ DEFAULT_TIMEOUT = 10.0
7
+ DEFAULT_THRESHOLD = 0.5
8
+
9
+ attr_accessor :api_key, :transport
10
+ attr_reader :base_url, :timeout, :threshold
11
+
12
+ def initialize
13
+ @api_key = nil
14
+ @base_url = DEFAULT_BASE_URL
15
+ @timeout = DEFAULT_TIMEOUT
16
+ @threshold = DEFAULT_THRESHOLD
17
+ @transport = nil
18
+ end
19
+
20
+ def base_url=(value)
21
+ raise ArgumentError, "base_url must be a non-empty String" unless value.is_a?(String) && !value.empty?
22
+
23
+ @base_url = value
24
+ end
25
+
26
+ def timeout=(value)
27
+ raise ArgumentError, "timeout must be a positive number" unless value.is_a?(Numeric) && value.to_f.positive?
28
+
29
+ @timeout = value.to_f
30
+ end
31
+
32
+ def threshold=(value)
33
+ @threshold = Jev.normalize_threshold(value)
34
+ end
35
+ end
36
+ end
data/lib/jev/errors.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jev
4
+ class Error < StandardError; end
5
+ class ConfigurationError < Error; end
6
+ class UndefinedDefinition < Error; end
7
+ class RequestError < Error; end
8
+ class AuthenticationError < RequestError; end
9
+ class RateLimitError < RequestError; end
10
+ class InvalidResponseError < Error; end
11
+ end
data/lib/jev/feels.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jev
4
+ module Feels
5
+ refine String do
6
+ def feels(...)
7
+ Jev.feels(self, ...)
8
+ end
9
+
10
+ def feels?(...)
11
+ Jev.feels?(self, ...)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jev
4
+ class Registry
5
+ def initialize
6
+ @mutex = Mutex.new
7
+ @definitions = {}
8
+ end
9
+
10
+ def define(name, description)
11
+ key = name.to_sym
12
+ value = description.to_s.dup.freeze
13
+ @mutex.synchronize { @definitions[key] = value }
14
+ value
15
+ end
16
+
17
+ def fetch(name)
18
+ @mutex.synchronize { @definitions[name.to_sym] }
19
+ end
20
+
21
+ def all
22
+ @mutex.synchronize { @definitions.dup.freeze }
23
+ end
24
+
25
+ def reset!
26
+ @mutex.synchronize { @definitions.clear }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "openssl"
6
+ require "uri"
7
+
8
+ module Jev
9
+ class Transport
10
+ PATH = "v1/systemone"
11
+
12
+ def initialize(configuration)
13
+ @configuration = configuration
14
+ end
15
+
16
+ def call(payload)
17
+ handle_response(post(payload))
18
+ rescue Error
19
+ raise
20
+ rescue Timeout::Error
21
+ raise RequestError, "Jev request timed out"
22
+ rescue SystemCallError, SocketError, IOError, OpenSSL::SSL::SSLError => e
23
+ raise RequestError, redact("Jev request failed: #{e.message}")
24
+ end
25
+
26
+ private
27
+
28
+ def post(payload)
29
+ uri = endpoint
30
+ http = Net::HTTP.new(uri.host, uri.port)
31
+ http.use_ssl = uri.scheme == "https"
32
+ apply_timeouts(http)
33
+ http.request(build_request(uri, payload))
34
+ end
35
+
36
+ def apply_timeouts(http)
37
+ timeout = @configuration.timeout
38
+ http.open_timeout = timeout
39
+ http.read_timeout = timeout
40
+ http.write_timeout = timeout if http.respond_to?(:write_timeout=)
41
+ end
42
+
43
+ def build_request(uri, payload)
44
+ request = Net::HTTP::Post.new(uri.request_uri)
45
+ request["Authorization"] = "Bearer #{api_key}"
46
+ request["Content-Type"] = "application/json"
47
+ request["Accept"] = "application/json"
48
+ request["User-Agent"] = "jev-feels/#{VERSION}"
49
+ request.body = JSON.generate(payload)
50
+ request
51
+ end
52
+
53
+ def api_key
54
+ key = @configuration.api_key
55
+ raise ConfigurationError, "Jev API key is missing" if key.nil? || key.empty?
56
+
57
+ key
58
+ end
59
+
60
+ def endpoint
61
+ base = @configuration.base_url
62
+ base = "#{base}/" unless base.end_with?("/")
63
+ URI.join(base, PATH)
64
+ end
65
+
66
+ def handle_response(response)
67
+ code = response.code.to_i
68
+ raw = response.body.to_s
69
+ return parse_success(raw) if code == 200
70
+
71
+ raise_http_error(code, raw)
72
+ end
73
+
74
+ def parse_success(raw)
75
+ body = JSON.parse(raw)
76
+ raise InvalidResponseError, "Jev response is not a JSON object" unless body.is_a?(Hash)
77
+
78
+ body
79
+ rescue JSON::ParserError
80
+ raise InvalidResponseError, "Jev response is not valid JSON"
81
+ end
82
+
83
+ def raise_http_error(code, raw)
84
+ detail = error_detail(raw)
85
+ case code
86
+ when 401
87
+ raise AuthenticationError, "Jev authentication failed"
88
+ when 429
89
+ raise RateLimitError, join_detail("Jev rate limit exceeded", detail)
90
+ else
91
+ raise RequestError, join_detail("Jev request failed with HTTP #{code}", detail)
92
+ end
93
+ end
94
+
95
+ def error_detail(raw)
96
+ text = extract_error_message(raw)
97
+ return if text.nil? || text.empty?
98
+
99
+ redact(text)
100
+ end
101
+
102
+ def extract_error_message(raw)
103
+ parsed = JSON.parse(raw)
104
+ message = parsed.values_at("error", "message", "detail").compact.first
105
+ message = message["message"] if message.is_a?(Hash)
106
+ message.to_s
107
+ rescue JSON::ParserError
108
+ raw.strip[0, 200]
109
+ end
110
+
111
+ def join_detail(prefix, detail)
112
+ detail ? "#{prefix}: #{detail}" : prefix
113
+ end
114
+
115
+ def redact(text)
116
+ key = @configuration.api_key
117
+ return text.to_s if key.nil? || key.empty?
118
+
119
+ text.to_s.gsub(key, "[FILTERED]")
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jev
4
+ VERSION = "0.1.0"
5
+ end
data/lib/jev-feels.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "feels"
data/lib/jev.rb ADDED
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jev/version"
4
+ require_relative "jev/errors"
5
+ require_relative "jev/configuration"
6
+ require_relative "jev/registry"
7
+ require_relative "jev/transport"
8
+ require_relative "jev/client"
9
+ require_relative "jev/feels"
10
+
11
+ module Jev
12
+ class << self
13
+ attr_reader :configuration
14
+
15
+ def configure
16
+ yield configuration
17
+ configuration
18
+ end
19
+
20
+ def reset_configuration!
21
+ @configuration = Configuration.new
22
+ end
23
+
24
+ def define(name, description)
25
+ registry.define(name, description)
26
+ end
27
+
28
+ def definition(name)
29
+ registry.fetch(name)
30
+ end
31
+
32
+ def definitions
33
+ registry.all
34
+ end
35
+
36
+ def reset_definitions!
37
+ registry.reset!
38
+ end
39
+
40
+ def feels(text, predicate)
41
+ Client.new(configuration).probability(coerce_text(text), resolve(predicate))
42
+ end
43
+
44
+ def feels?(text, predicate, threshold: configuration.threshold)
45
+ feels(text, predicate) >= normalize_threshold(threshold)
46
+ end
47
+
48
+ def normalize_threshold(value)
49
+ raise ArgumentError, "threshold must be a Float between 0.0 and 1.0" unless value.is_a?(Numeric)
50
+
51
+ value = Float(value)
52
+ unless value.finite? && value.between?(0.0, 1.0)
53
+ raise ArgumentError, "threshold must be a Float between 0.0 and 1.0"
54
+ end
55
+
56
+ value
57
+ end
58
+
59
+ private
60
+
61
+ attr_reader :registry
62
+
63
+ def coerce_text(text)
64
+ text = text.to_str if !text.is_a?(String) && text.respond_to?(:to_str)
65
+ raise ArgumentError, "text must be a String" unless text.is_a?(String)
66
+
67
+ text
68
+ end
69
+
70
+ def resolve(predicate)
71
+ case predicate
72
+ when Symbol
73
+ definition(predicate) ||
74
+ raise(UndefinedDefinition, "Undefined Jev definition: #{predicate.inspect}")
75
+ when String
76
+ predicate
77
+ else
78
+ raise ArgumentError, "predicate must be a Symbol or String"
79
+ end
80
+ end
81
+ end
82
+
83
+ reset_configuration!
84
+ @registry = Registry.new
85
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jev-feels
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Veysgeym
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-09-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Tiny Ruby API for semantic text checks. Jev.feels?(:urgent) is an ordinary
15
+ condition, not an SDK session. Jev stays an implementation detail.
16
+ email:
17
+ - Qew7@users.noreply.github.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - context7.json
25
+ - lib/feels.rb
26
+ - lib/feels/string.rb
27
+ - lib/jev-feels.rb
28
+ - lib/jev.rb
29
+ - lib/jev/client.rb
30
+ - lib/jev/configuration.rb
31
+ - lib/jev/errors.rb
32
+ - lib/jev/feels.rb
33
+ - lib/jev/registry.rb
34
+ - lib/jev/transport.rb
35
+ - lib/jev/version.rb
36
+ homepage: https://github.com/Qew7/jev-feels
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/Qew7/jev-feels
41
+ source_code_uri: https://github.com/Qew7/jev-feels
42
+ changelog_uri: https://github.com/Qew7/jev-feels/blob/main/README.md
43
+ allowed_push_host: https://rubygems.org
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.2.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.4.19
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Ruby-like semantic predicates via Jev
63
+ test_files: []