coolhand 0.2.0 → 0.3.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 +4 -4
- data/.rubocop.yml +12 -0
- data/CHANGELOG.md +53 -1
- data/CLAUDE.md +34 -0
- data/README.md +147 -27
- data/coolhand-ruby.gemspec +46 -0
- data/docs/anthropic.md +11 -11
- data/docs/elevenlabs.md +6 -4
- data/lib/coolhand/api_service.rb +264 -0
- data/lib/coolhand/base_interceptor.rb +213 -0
- data/lib/coolhand/collector.rb +19 -0
- data/lib/coolhand/configuration.rb +84 -0
- data/lib/coolhand/default_exclude_api_patterns.yml +9 -0
- data/lib/coolhand/default_intercept_addresses.yml +15 -0
- data/lib/coolhand/feedback_service.rb +15 -0
- data/lib/coolhand/logger_service.rb +112 -0
- data/lib/coolhand/net_http_interceptor.rb +163 -0
- data/lib/coolhand/open_ai/batch_result_processor.rb +139 -0
- data/lib/coolhand/open_ai/webhook_validator.rb +127 -0
- data/lib/coolhand/{ruby/version.rb → version.rb} +1 -3
- data/lib/coolhand/vertex/batch_result_processor.rb +84 -0
- data/lib/coolhand/webhook_interceptor.rb +39 -0
- data/lib/coolhand.rb +109 -2
- metadata +35 -18
- data/lib/coolhand/ruby/anthropic_interceptor.rb +0 -300
- data/lib/coolhand/ruby/api_service.rb +0 -226
- data/lib/coolhand/ruby/base_interceptor.rb +0 -148
- data/lib/coolhand/ruby/collector.rb +0 -21
- data/lib/coolhand/ruby/configuration.rb +0 -38
- data/lib/coolhand/ruby/faraday_interceptor.rb +0 -129
- data/lib/coolhand/ruby/feedback_service.rb +0 -17
- data/lib/coolhand/ruby/logger_service.rb +0 -114
- data/lib/coolhand/ruby.rb +0 -121
data/lib/coolhand/ruby.rb
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "net/http"
|
|
4
|
-
require "uri"
|
|
5
|
-
require "faraday"
|
|
6
|
-
require "securerandom"
|
|
7
|
-
|
|
8
|
-
require_relative "ruby/version"
|
|
9
|
-
require_relative "ruby/configuration"
|
|
10
|
-
require_relative "ruby/collector"
|
|
11
|
-
require_relative "ruby/faraday_interceptor"
|
|
12
|
-
require_relative "ruby/anthropic_interceptor"
|
|
13
|
-
require_relative "ruby/api_service"
|
|
14
|
-
require_relative "ruby/logger_service"
|
|
15
|
-
require_relative "ruby/feedback_service"
|
|
16
|
-
|
|
17
|
-
# The main module for the Coolhand gem.
|
|
18
|
-
# It provides the configuration interface and initializes the patching.
|
|
19
|
-
module Coolhand
|
|
20
|
-
class Error < StandardError; end
|
|
21
|
-
|
|
22
|
-
# Class-level instance variables to hold the configuration
|
|
23
|
-
@configuration = Configuration.new
|
|
24
|
-
|
|
25
|
-
class << self
|
|
26
|
-
attr_reader :configuration
|
|
27
|
-
|
|
28
|
-
# Reset configuration to defaults (mainly for testing)
|
|
29
|
-
def reset_configuration!
|
|
30
|
-
@configuration = Configuration.new
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Provides a block to configure the gem.
|
|
34
|
-
#
|
|
35
|
-
# Example:
|
|
36
|
-
# Coolhand.configure do |config|
|
|
37
|
-
# config.environment = 'development'
|
|
38
|
-
# config.silent = false
|
|
39
|
-
# config.api_key = "xxx-yyy-zzz"
|
|
40
|
-
# config.intercept_addresses = ["openai.com"]
|
|
41
|
-
# end
|
|
42
|
-
def configure
|
|
43
|
-
yield(configuration)
|
|
44
|
-
|
|
45
|
-
configuration.validate!
|
|
46
|
-
|
|
47
|
-
# Apply the Faraday patch (needed for ruby-anthropic and other Faraday-based gems)
|
|
48
|
-
Ruby::FaradayInterceptor.patch!
|
|
49
|
-
|
|
50
|
-
# Conditionally patch the official Anthropic gem if it's loaded
|
|
51
|
-
if anthropic_gem_loaded?
|
|
52
|
-
if defined?(Anthropic::Internal)
|
|
53
|
-
# Official anthropic gem - patch the AnthropicInterceptor for Net::HTTP requests
|
|
54
|
-
Ruby::AnthropicInterceptor.patch!
|
|
55
|
-
log "✅ Coolhand ready - will log OpenAI and Anthropic (official gem) calls"
|
|
56
|
-
else
|
|
57
|
-
# ruby-anthropic gem uses Faraday, so FaradayInterceptor is sufficient
|
|
58
|
-
log "✅ Coolhand ready - will log OpenAI and Anthropic (ruby-anthropic via Faraday) calls"
|
|
59
|
-
end
|
|
60
|
-
else
|
|
61
|
-
log "✅ Coolhand ready - will log OpenAI calls"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def capture
|
|
66
|
-
unless block_given?
|
|
67
|
-
log "❌ Coolhand Error: Method .capture requires block."
|
|
68
|
-
return
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
Ruby::FaradayInterceptor.patch!
|
|
72
|
-
|
|
73
|
-
# Only patch AnthropicInterceptor for official anthropic gem
|
|
74
|
-
anthropic_patched = false
|
|
75
|
-
if anthropic_gem_loaded? && defined?(Anthropic::Internal)
|
|
76
|
-
Ruby::AnthropicInterceptor.patch!
|
|
77
|
-
anthropic_patched = true
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
yield
|
|
81
|
-
ensure
|
|
82
|
-
Ruby::FaradayInterceptor.unpatch!
|
|
83
|
-
Ruby::AnthropicInterceptor.unpatch! if anthropic_patched
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# A simple logger that respects the 'silent' configuration option.
|
|
87
|
-
def log(message)
|
|
88
|
-
return if configuration.silent
|
|
89
|
-
|
|
90
|
-
puts "COOLHAND: #{message}"
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Creates a new FeedbackService instance
|
|
94
|
-
def feedback_service
|
|
95
|
-
Ruby::FeedbackService.new
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# Creates a new LoggerService instance
|
|
99
|
-
def logger_service
|
|
100
|
-
Ruby::LoggerService.new
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def required_field?(value)
|
|
104
|
-
return false if value.nil?
|
|
105
|
-
return false if value.respond_to?(:empty?) && value.empty?
|
|
106
|
-
return false if value.to_s.strip.empty?
|
|
107
|
-
|
|
108
|
-
true
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def current_request_id
|
|
112
|
-
Thread.current[:coolhand_current_request_id]
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
private
|
|
116
|
-
|
|
117
|
-
def anthropic_gem_loaded?
|
|
118
|
-
defined?(Anthropic::Client)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|