posthog-ruby 3.25.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ff857115cd53eb41945a0bad1a05768bb54770b4f5e2d8e8fda17a2bdb8a758
4
- data.tar.gz: 910d5e7ade22aa5c3d8fed8794ad4f3b72230f1c649e40de8790b2acc9fa80e9
3
+ metadata.gz: e122582ed410310c48c95e3bffbac3b3255a055ec0e527769421162b672b4b85
4
+ data.tar.gz: 4491c33e03c11dbc78c4f6e71f378ef28f4a17558e12ce48df1008d63a417fa3
5
5
  SHA512:
6
- metadata.gz: 34f457e72fb2c137e38f6188b9fb63dfb9541a21b705f373e1c4d39d4037c70ae2762f48774d9fbdfec015f3c745a6e0d6775e56c57d011b8f57bc5ee99e299c
7
- data.tar.gz: dccddee87b9b57ae401a36f31f76685bb353974eb94c390d564582ad79cf4060544ede2b28229f87de486afb68d0f740b28becd8dcd878ab96494b1b0c6958de
6
+ metadata.gz: 70c0f2c24d1528b88ccb6d79302b285b2ba01759d4cd87c5009e3d7a46ac518b79a3a365a68a92176d6b69c7ea6b129c35c6c9c0d92a71c0815d41e96a8d121c
7
+ data.tar.gz: 45c8a888745f5e873084ea828e65e2982b73391ce9ac901473f9390f600e912600754dd67553734ace2e1aa330ad1935c98ebeee3d80f989b5f4c27e45614f94
@@ -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` argument (and, with `capture_model`, `llm_model`) into
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: false)
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
- keys = ['context', ModelCapture::PARAM_NAME].reject { |param| tool_declares?(input_schema, param) }
240
- .flat_map { |param| [param.to_sym, param] }
241
- .select { |key| args.key?(key) }
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. Enabling conversation ids ' \
510
- '(PostHog::MCP.instrument(server, enable_conversation_id: true)) also anchors the session without ' \
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
 
@@ -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 false.
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 false.
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: false, enable_exception_autocapture: true, context: true,
74
- capture_model: false, identify: nil, intent_fallback: nil, before_send: nil,
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.25.0'
4
+ VERSION = '3.26.0'
5
5
  end
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.25.0
4
+ version: 3.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''