collavre_completion_api 0.2.3 → 0.2.5

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: dc50b74db9b7b24ba288392fb8c5a4b269727228829dcf91a0196236f0a5c352
4
- data.tar.gz: 5bdad75265afa2f8eae040d22069e8370cb771afd5bc2abccc380a47d2a9def5
3
+ metadata.gz: b7967de4d7b5197567a4175afefb9f1696f5d7dc2203339a1ca68f83731b88b5
4
+ data.tar.gz: 56bf1b741381a9bd39d3b991554f1519760e01d6a68a095444368ce3e4969ec3
5
5
  SHA512:
6
- metadata.gz: 2abccff570987512417cdc2d41f22a7b05177b7bf4bcdb6e44bd47f7b87560d35aa9fe8332ecf7f7abf60d9f3e9f8083605a209394cc915e7362f24188b34605
7
- data.tar.gz: 96578d0b13a218be1f72a1086d0e7ecf6fd7ce8a3fb391750b24073602fa29403e251e5c1163d2f084a866404ee8f2dc905fcb908504e43d3c2f005d4657fe86
6
+ metadata.gz: 1929b7623e35ce65f790fef3d6f852dad9be17ec851223c083e7cc65cf2963118d340db297399effc2f4ad8046ab98d511aa610d595b22ed89abb20d3dc64363
7
+ data.tar.gz: 41b6827997729da4e9ec596a980cb26badf6d869524ac540c28ba35c6b75026893aaaa4fda8c1ff53d9607185ebd7e85c53989d483315393033440b695ccb5a2
@@ -68,19 +68,15 @@ module CollavreCompletionApi
68
68
  def resolve_agent_by_model(model_param)
69
69
  return nil if model_param.blank?
70
70
 
71
- agent = if model_param.start_with?("collavre/")
71
+ candidates = Collavre::User.accessible_ai_agents_for(current_user).chat_capable
72
+ if model_param.start_with?("collavre/")
72
73
  # Legacy format: collavre/{id}
73
- Collavre::User.find_by(id: model_param.sub("collavre/", ""))
74
+ candidates.find_by(id: model_param.sub("collavre/", ""))
74
75
  else
75
76
  # Email username format — sanitize to prevent LIKE wildcard injection
76
77
  sanitized = ActiveRecord::Base.sanitize_sql_like(model_param)
77
- Collavre::User.where("email LIKE ?", "#{sanitized}@%").first
78
+ candidates.where("email LIKE ?", "#{sanitized}@%").first
78
79
  end
79
-
80
- return nil unless agent&.ai_user?
81
- return nil unless agent.created_by_id == current_user.id || agent.searchable?
82
-
83
- agent
84
80
  end
85
81
 
86
82
  def collavre_creative
@@ -37,7 +37,7 @@ module CollavreCompletionApi
37
37
  system_prompt: system_prompt,
38
38
  llm_api_key: api_key,
39
39
  gateway_url: agent.respond_to?(:gateway_url) ? agent.gateway_url : nil,
40
- context: { creative: collavre_creative, user: current_user, topic_id: collavre_topic&.id }
40
+ context: completion_context(agent)
41
41
  )
42
42
 
43
43
  model_name = params[:model] || agent_model_id(agent)
@@ -51,6 +51,11 @@ module CollavreCompletionApi
51
51
 
52
52
  private
53
53
 
54
+ def completion_context(agent)
55
+ { creative: collavre_creative, user: current_user, topic_id: collavre_topic&.id,
56
+ agent: agent, requester: current_user }
57
+ end
58
+
54
59
  def resolve_agent
55
60
  resolve_agent_by_model(params[:model].to_s)
56
61
  end
@@ -5,7 +5,7 @@ module CollavreCompletionApi
5
5
  module V1
6
6
  class ModelsController < BaseController
7
7
  def index
8
- ai_agents = Collavre::User.accessible_ai_agents_for(current_user)
8
+ ai_agents = Collavre::User.accessible_ai_agents_for(current_user).chat_capable
9
9
 
10
10
  models = ai_agents.map do |agent|
11
11
  {
@@ -1,3 +1,3 @@
1
1
  module CollavreCompletionApi
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collavre_completion_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collavre
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.6.7
91
+ rubygems_version: 3.6.9
92
92
  specification_version: 4
93
93
  summary: OpenAI-compatible chat completions API for Collavre
94
94
  test_files: []