posthog-ruby 3.24.0 → 3.26.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/lib/posthog/client.rb +21 -0
- data/lib/posthog/mcp/client.rb +18 -7
- data/lib/posthog/mcp/instrumentation.rb +2 -3
- data/lib/posthog/mcp/options.rb +4 -4
- data/lib/posthog/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e122582ed410310c48c95e3bffbac3b3255a055ec0e527769421162b672b4b85
|
|
4
|
+
data.tar.gz: 4491c33e03c11dbc78c4f6e71f378ef28f4a17558e12ce48df1008d63a417fa3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70c0f2c24d1528b88ccb6d79302b285b2ba01759d4cd87c5009e3d7a46ac518b79a3a365a68a92176d6b69c7ea6b129c35c6c9c0d92a71c0815d41e96a8d121c
|
|
7
|
+
data.tar.gz: 45c8a888745f5e873084ea828e65e2982b73391ce9ac901473f9390f600e912600754dd67553734ace2e1aa330ad1935c98ebeee3d80f989b5f4c27e45614f94
|
data/lib/posthog/client.rb
CHANGED
|
@@ -44,9 +44,16 @@ module PostHog
|
|
|
44
44
|
$is_server
|
|
45
45
|
$lib
|
|
46
46
|
$lib_version
|
|
47
|
+
$release_id
|
|
47
48
|
].flat_map { |key| [key, key.to_sym] }.freeze
|
|
48
49
|
private_constant :MINIMAL_FLAG_CALLED_EVENT_PROPERTIES
|
|
49
50
|
|
|
51
|
+
# Holds the id that `posthog-cli release resolve` prints. Error tracking
|
|
52
|
+
# links an exception to its release by this id, because a Ruby app has no
|
|
53
|
+
# build step that could inject it.
|
|
54
|
+
RELEASE_ID_ENV_VAR = 'POSTHOG_RELEASE_ID'
|
|
55
|
+
private_constant :RELEASE_ID_ENV_VAR
|
|
56
|
+
|
|
50
57
|
# Thread-safe tracking of client instances per API key for singleton warnings
|
|
51
58
|
@instances_by_api_key = {}
|
|
52
59
|
@instances_mutex = Mutex.new
|
|
@@ -217,6 +224,7 @@ module PostHog
|
|
|
217
224
|
|
|
218
225
|
@before_send = opts[:before_send]
|
|
219
226
|
@is_server = opts.fetch(:is_server, true) != false
|
|
227
|
+
@release_id = normalize_string_option(ENV.fetch(RELEASE_ID_ENV_VAR, nil), blank_as_nil: true)
|
|
220
228
|
@deprecation_emitted_for = Concurrent::Set.new
|
|
221
229
|
end
|
|
222
230
|
|
|
@@ -1137,6 +1145,8 @@ module PostHog
|
|
|
1137
1145
|
def enqueue(action)
|
|
1138
1146
|
return false if @disabled || shutdown?
|
|
1139
1147
|
|
|
1148
|
+
# Every event type passes through here, and before_send still sees the id.
|
|
1149
|
+
action = add_release_id(action)
|
|
1140
1150
|
action = process_before_send(action)
|
|
1141
1151
|
return false if action.nil? || action.empty?
|
|
1142
1152
|
|
|
@@ -1168,6 +1178,17 @@ module PostHog
|
|
|
1168
1178
|
end
|
|
1169
1179
|
end
|
|
1170
1180
|
|
|
1181
|
+
# A `$release_id` the caller or the request context already set wins.
|
|
1182
|
+
def add_release_id(action)
|
|
1183
|
+
return action if @release_id.nil?
|
|
1184
|
+
|
|
1185
|
+
properties = action[:properties]
|
|
1186
|
+
return action unless properties.is_a?(Hash)
|
|
1187
|
+
return action if properties.key?('$release_id') || properties.key?(:$release_id)
|
|
1188
|
+
|
|
1189
|
+
action.merge(properties: properties.merge('$release_id' => @release_id))
|
|
1190
|
+
end
|
|
1191
|
+
|
|
1171
1192
|
def normalize_string_option(value, blank_as_nil: false)
|
|
1172
1193
|
return value unless value.is_a?(String)
|
|
1173
1194
|
|
data/lib/posthog/mcp/client.rb
CHANGED
|
@@ -17,10 +17,13 @@ module PostHog
|
|
|
17
17
|
# @param opts [Hash] {PostHog::Client} options plus:
|
|
18
18
|
# @option opts [String] :missing_capability_tool_name name of the virtual tool (default `get_more_tools`)
|
|
19
19
|
# @option opts [Boolean] :mcp_exception_autocapture emit a sibling `$exception` for failed calls (default true)
|
|
20
|
+
# @option opts [Boolean, ModelOptions] :capture_model capture the calling model (default true)
|
|
20
21
|
def initialize(opts = {})
|
|
21
22
|
opts = opts.transform_keys(&:to_sym)
|
|
22
23
|
@missing_capability_tool_name = opts.delete(:missing_capability_tool_name) || Tools::GET_MORE_TOOLS_NAME
|
|
23
24
|
@mcp_exception_autocapture = opts.delete(:mcp_exception_autocapture) != false
|
|
25
|
+
capture_model = opts.key?(:capture_model) ? opts.delete(:capture_model) : true
|
|
26
|
+
@capture_model_option = Options.new(capture_model: capture_model).capture_model
|
|
24
27
|
super
|
|
25
28
|
@mcp_sink = Sink.new(self)
|
|
26
29
|
@mcp_options = Options.new(
|
|
@@ -113,16 +116,20 @@ module PostHog
|
|
|
113
116
|
emit(event)
|
|
114
117
|
end
|
|
115
118
|
|
|
116
|
-
# Inject the `context`
|
|
119
|
+
# Inject the `context` and `llm_model` arguments into
|
|
117
120
|
# every tool descriptor (Hash with `inputSchema`) so agents state their intent,
|
|
118
121
|
# and optionally append the `get_more_tools` virtual tool. Returns a new Array
|
|
119
122
|
# of new Hashes. A tool whose schema is composed (oneOf/allOf/anyOf) or a
|
|
120
|
-
# `$ref` is passed through untouched.
|
|
123
|
+
# `$ref` is passed through untouched. Pass `capture_model: false` here or
|
|
124
|
+
# to {#initialize} to disable model capture for this client, including
|
|
125
|
+
# extraction from later tool calls.
|
|
121
126
|
#
|
|
122
127
|
# @param tools [Array<Hash>] `tools/list` entries
|
|
123
128
|
# @return [Array<Hash>]
|
|
124
|
-
def prepare_tool_list(tools, context: true, report_missing: false, capture_model:
|
|
129
|
+
def prepare_tool_list(tools, context: true, report_missing: false, capture_model: @capture_model_option)
|
|
125
130
|
options = Options.new(context: context, capture_model: capture_model)
|
|
131
|
+
@capture_model_option = false unless options.capture_model_enabled?
|
|
132
|
+
options = Options.new(context: context, capture_model: false) if @capture_model_option == false
|
|
126
133
|
prepared = tools.map do |tool|
|
|
127
134
|
next tool unless tool.is_a?(Hash) && (options.context_enabled? || options.capture_model_enabled?)
|
|
128
135
|
|
|
@@ -165,7 +172,7 @@ module PostHog
|
|
|
165
172
|
# @return [PreparedToolCall]
|
|
166
173
|
def prepare_tool_call(name, args = nil, input_schema: nil)
|
|
167
174
|
intent = tool_declares?(input_schema, 'context') ? nil : Intent.normalize(argument(args, 'context'))
|
|
168
|
-
model = if tool_declares?(input_schema, ModelCapture::PARAM_NAME)
|
|
175
|
+
model = if @capture_model_option == false || tool_declares?(input_schema, ModelCapture::PARAM_NAME)
|
|
169
176
|
nil
|
|
170
177
|
else
|
|
171
178
|
ModelCapture.normalize(argument(args, ModelCapture::PARAM_NAME))
|
|
@@ -199,6 +206,8 @@ module PostHog
|
|
|
199
206
|
end
|
|
200
207
|
|
|
201
208
|
def apply_model(event, llm_model, source)
|
|
209
|
+
return if @capture_model_option == false
|
|
210
|
+
|
|
202
211
|
model = ModelCapture.normalize(llm_model)
|
|
203
212
|
return unless model
|
|
204
213
|
|
|
@@ -236,9 +245,11 @@ module PostHog
|
|
|
236
245
|
def strip_injected(args, input_schema)
|
|
237
246
|
return args unless args.is_a?(Hash)
|
|
238
247
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
248
|
+
params = ['context']
|
|
249
|
+
params << ModelCapture::PARAM_NAME unless @capture_model_option == false
|
|
250
|
+
keys = params.reject { |param| tool_declares?(input_schema, param) }
|
|
251
|
+
.flat_map { |param| [param.to_sym, param] }
|
|
252
|
+
.select { |key| args.key?(key) }
|
|
242
253
|
keys.empty? ? args : args.except(*keys)
|
|
243
254
|
end
|
|
244
255
|
end
|
|
@@ -506,9 +506,8 @@ module PostHog
|
|
|
506
506
|
'Warning: an MCP request arrived over streamable HTTP with no session id, so PostHog generated a ' \
|
|
507
507
|
'per-process $session_id that will fragment across requests and pods. In stateless mode the ' \
|
|
508
508
|
'client must replay the Mcp-Session-Id header PostHog::MCP mints at initialize; for a custom Rack ' \
|
|
509
|
-
'stack add PostHog::MCP::RackMiddleware.
|
|
510
|
-
'
|
|
511
|
-
'any middleware. See https://posthog.com/docs/mcp-analytics/installation#ruby.'
|
|
509
|
+
'stack add PostHog::MCP::RackMiddleware. Conversation ids, which are enabled by default, also anchor ' \
|
|
510
|
+
'the session without any middleware. See https://posthog.com/docs/mcp-analytics/installation#ruby.'
|
|
512
511
|
)
|
|
513
512
|
end
|
|
514
513
|
|
data/lib/posthog/mcp/options.rb
CHANGED
|
@@ -52,13 +52,13 @@ module PostHog
|
|
|
52
52
|
attr_reader :report_missing
|
|
53
53
|
# @return [String] Name of the virtual tool. Default `get_more_tools`.
|
|
54
54
|
attr_reader :missing_capability_tool_name
|
|
55
|
-
# @return [Boolean] Inject `conversation_id` and anchor `$session_id` on it. Default
|
|
55
|
+
# @return [Boolean] Inject `conversation_id` and anchor `$session_id` on it. Default true.
|
|
56
56
|
attr_reader :enable_conversation_id
|
|
57
57
|
# @return [Boolean] Emit a sibling `$exception` event for failed calls. Default true.
|
|
58
58
|
attr_reader :enable_exception_autocapture
|
|
59
59
|
# @return [Boolean, ContextOptions] Inject the required `context` argument. Default true.
|
|
60
60
|
attr_reader :context
|
|
61
|
-
# @return [Boolean, ModelOptions] Capture `$mcp_llm_model`. Default
|
|
61
|
+
# @return [Boolean, ModelOptions] Capture `$mcp_llm_model`. Default true.
|
|
62
62
|
attr_reader :capture_model
|
|
63
63
|
# @return [#call, UserIdentity, Hash, nil] `(request, extra) -> UserIdentity | Hash | nil`, or a static identity.
|
|
64
64
|
attr_reader :identify
|
|
@@ -70,8 +70,8 @@ module PostHog
|
|
|
70
70
|
attr_reader :event_properties
|
|
71
71
|
|
|
72
72
|
def initialize(logger: nil, report_missing: false, missing_capability_tool_name: nil,
|
|
73
|
-
enable_conversation_id:
|
|
74
|
-
capture_model:
|
|
73
|
+
enable_conversation_id: true, enable_exception_autocapture: true, context: true,
|
|
74
|
+
capture_model: true, identify: nil, intent_fallback: nil, before_send: nil,
|
|
75
75
|
event_properties: nil)
|
|
76
76
|
@logger = logger
|
|
77
77
|
@report_missing = report_missing == true
|
data/lib/posthog/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: posthog-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.26.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ''
|
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
100
100
|
- !ruby/object:Gem::Version
|
|
101
101
|
version: '0'
|
|
102
102
|
requirements: []
|
|
103
|
-
rubygems_version: 4.0.
|
|
103
|
+
rubygems_version: 4.0.20
|
|
104
104
|
specification_version: 4
|
|
105
105
|
summary: PostHog library
|
|
106
106
|
test_files: []
|