posthog-ruby 3.30.2 → 3.31.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: 5e9b528f52ec8be662de48423ee322c07af2a2137925a3a2cbe48aafb2128fe4
4
- data.tar.gz: fdea7fd2b0d7c93eaa8c6958dcbe7cf3cdfa8d982d4c22e2d18e228109cd1a48
3
+ metadata.gz: 17dd1c0dd4366b9b1018da6f923584ee57875cb44d6c97deb03d571c0ed77371
4
+ data.tar.gz: 7320b9e00d455587755572270f759421a387a8b6e62cbc1f883a977b57ed06b2
5
5
  SHA512:
6
- metadata.gz: 9d1d0653335ee982e41fae66489ea5babe664441aa4b6a3998d2f0ff1ba6d5e06ccd4ce4e5a113e610e8efa15cadb34ea167c25590b5c1bc4faebdd91eafd5b7
7
- data.tar.gz: 63db4e21269110666718d6ebcb1794e24f03526faf32a3de313e3f845a8d8a9d9464cf63f3da839228a5cadbbe630ff0c6fb5ad240309e6bb5f0135668876e92
6
+ metadata.gz: 39b65b798aeb533c62b83fdadceaa48a22777ba0a66f1c1a79c38c86d3c699e7f2d676a195b4cda58833f6b9470a2a0fb04d85f4460623dfe2f3eebf732218fb
7
+ data.tar.gz: 55a4cb6aeb975b4da0f12dc24c0aa29ec071e9af6a57abfd187b33031bec1f9afd183f46f3c53f16fe603bf05edbb4cba34f1cdfeecdffe38bd894a20bfb02d4
@@ -16,13 +16,9 @@ module PostHog
16
16
 
17
17
  # Description of the injected `context` argument.
18
18
  DEFAULT_CONTEXT_PARAMETER_DESCRIPTION =
19
- 'Explain in 15-25 words, in third person, why this tool is called and how it supports ' \
20
- "the user's goal. For analytics only. You MUST describe only the abstract purpose of the " \
21
- 'tool call. NEVER include, repeat, paraphrase, or infer personal, sensitive, or identifying ' \
22
- 'information from the user request or tool results, including names, emails, phone numbers, ' \
23
- 'IPs, IDs, or credentials. You MUST generalize specific entities into roles such as "a user", ' \
24
- '"the customer", or "an account". Example: "Retrieving a customer\'s recent orders to ' \
25
- 'investigate a billing issue and help support determine the appropriate resolution."'
19
+ "A few words on why you are calling this tool, for the server developer's analytics. " \
20
+ 'Describe people and things by role, such as "a customer". Do not quote the user or include ' \
21
+ 'names, emails, or other personal details.'
26
22
 
27
23
  # Description of the injected `llm_model` argument.
28
24
  DEFAULT_MODEL_PARAMETER_DESCRIPTION =
@@ -249,7 +249,7 @@ module PostHog
249
249
  yield
250
250
  rescue StandardError => e
251
251
  safely do
252
- session_id = prepare_request(@request, skip_initialize: true)
252
+ session_id = prepare_request(@request)
253
253
  record_initialize(session_id, client_name, client_version, requested_version, error: e)
254
254
  end
255
255
  raise
@@ -258,7 +258,7 @@ module PostHog
258
258
  safely do
259
259
  negotiated = (result.is_a?(Hash) ? fetch(result, :protocolVersion) : nil) || requested_version
260
260
  minted = mint_session_token(client_name, client_version, negotiated, requested_version)
261
- session_id = prepare_request(@request, skip_initialize: true, token: minted)
261
+ session_id = prepare_request(@request, token: minted)
262
262
  record_initialize(session_id, client_name, client_version, negotiated, response: result)
263
263
  end
264
264
  result
@@ -360,7 +360,6 @@ module PostHog
360
360
  end
361
361
 
362
362
  def record_initialize(session_id, client_name, client_version, protocol_version, response: nil, error: nil)
363
- @data.mark_session_initialized(session_id)
364
363
  event = base_event(EventType::MCP_INITIALIZE, session_id, @request)
365
364
  event['client_name'] = client_name
366
365
  event['client_version'] = client_version
@@ -442,8 +441,8 @@ module PostHog
442
441
  @scope[:session_id] = session_id if @scope.is_a?(Hash)
443
442
  end
444
443
 
445
- # Resolve the session id, run identify, then lazily emit initialize.
446
- def prepare_request(request, conversation_id: nil, skip_initialize: false, token: nil)
444
+ # Resolve the session id and run identify.
445
+ def prepare_request(request, conversation_id: nil, token: nil)
447
446
  token ||= @token
448
447
  session_id, source = Session.resolve(@data, mcp_session_id(token), token: token,
449
448
  conversation_id: conversation_id)
@@ -463,30 +462,9 @@ module PostHog
463
462
  @scope[:actor] = actor if @scope.is_a?(Hash)
464
463
  self.class.capture_event(@data, identify_event, actor: actor) if identify_event
465
464
  end
466
- maybe_emit_initialize(session_id, request) unless skip_initialize
467
465
  session_id
468
466
  end
469
467
 
470
- def maybe_emit_initialize(session_id, request)
471
- # Claiming is atomic: two threads opening the same session concurrently
472
- # must not both get past the check and emit an initialize each.
473
- return unless @data.claim_session_initialized(session_id)
474
-
475
- name, version = client_identity(request)
476
- event = {
477
- 'event_type' => EventType::MCP_INITIALIZE,
478
- 'session_id' => session_id,
479
- 'client_name' => name,
480
- 'client_version' => version,
481
- 'protocol_version' => protocol_version,
482
- 'timestamp' => Time.now.utc
483
- }
484
- props = resolve_event_properties({ method: 'initialize', params: {} })
485
- event['properties'] = props unless props.nil?
486
- TransportIdentity.stamp(event, @headers)
487
- self.class.capture_event(@data, event, actor: actor_for(session_id))
488
- end
489
-
490
468
  # Era is decided by the version the client *asked for*:
491
469
  # a client declaring the 2026-07-28 revision or later must not be answered
492
470
  # with an `Mcp-Session-Id`, even though this gem counter-offers a legacy version.
@@ -120,7 +120,7 @@ module PostHog
120
120
  tool_name: tool_name, required: false, options: options, label: 'conversation_id')
121
121
  end
122
122
 
123
- def add_model_parameter(schema, tool_name:, description: nil, required: true, options: nil)
123
+ def add_model_parameter(schema, tool_name:, description: nil, required: false, options: nil)
124
124
  add_parameter(schema, ModelCapture::PARAM_NAME, description || DEFAULT_MODEL_PARAMETER_DESCRIPTION,
125
125
  tool_name: tool_name, required: required, options: options, label: 'llm_model')
126
126
  end
@@ -43,11 +43,10 @@ module PostHog
43
43
  required: ['context']
44
44
  },
45
45
  annotations: {
46
- title: 'Get More Tools',
47
- readOnlyHint: true,
48
- openWorldHint: true,
49
- idempotentHint: true,
50
- destructiveHint: false
46
+ readOnlyHint: false,
47
+ destructiveHint: false,
48
+ idempotentHint: false,
49
+ openWorldHint: false
51
50
  }
52
51
  }
53
52
  return spec unless options.respond_to?(:capture_model_enabled?) && options.capture_model_enabled?
@@ -7,8 +7,6 @@ module PostHog
7
7
  #
8
8
  # @api private
9
9
  class TrackingData
10
- MAX_INITIALIZED_SESSIONS = 1000
11
-
12
10
  attr_reader :options, :sink, :server_name, :server_version, :identified_sessions,
13
11
  :tool_descriptions, :tool_categories, :tool_output_instructions, :tool_owned_params
14
12
  attr_accessor :session_id, :session_source, :last_mcp_session_id, :last_activity, :warned_no_stateless_session,
@@ -40,7 +38,6 @@ module PostHog
40
38
  # Which injected argument names the analytics layer owns per tool (i.e.
41
39
  # the tool does not declare them itself).
42
40
  @tool_owned_params = {}
43
- @initialized_sessions = {}
44
41
  end
45
42
 
46
43
  def synchronize(&block)
@@ -51,31 +48,6 @@ module PostHog
51
48
  end
52
49
  end
53
50
 
54
- def mark_session_initialized(session_id)
55
- synchronize do
56
- @initialized_sessions.delete(session_id)
57
- @initialized_sessions[session_id] = true
58
- @initialized_sessions.shift while @initialized_sessions.length > MAX_INITIALIZED_SESSIONS
59
- end
60
- end
61
-
62
- def session_initialized?(session_id)
63
- synchronize { @initialized_sessions.key?(session_id) }
64
- end
65
-
66
- # Claim the one lazy initialize event a session gets. Check and mark are a
67
- # single critical section, so when concurrent first requests race only the
68
- # caller that inserted the key sees `true` and emits `$mcp_initialize`.
69
- def claim_session_initialized(session_id)
70
- synchronize do
71
- next false if @initialized_sessions.key?(session_id)
72
-
73
- @initialized_sessions[session_id] = true
74
- @initialized_sessions.shift while @initialized_sessions.length > MAX_INITIALIZED_SESSIONS
75
- true
76
- end
77
- end
78
-
79
51
  def remember_tool(name, description: nil, category: nil, owned_params: nil, output_instructions: nil)
80
52
  synchronize do
81
53
  @tool_descriptions[name] = description if description.is_a?(String) && !description.empty?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.30.2'
4
+ VERSION = '3.31.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.30.2
4
+ version: 3.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''