sveda-ruby-sdk 0.4.0 → 0.5.1

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: 2e9c79a05787a6a6af99f8b7bed30c9e8499e67d0452b0f42edc3c9eef452889
4
- data.tar.gz: 1c6052da2b8651166262cb980affa9801e66e886466ad05aa7a6dd5edeb0cc3e
3
+ metadata.gz: 1754fc122354ff157ef4516100f284a86bc448d98201d3dcf3f3419c14e709a9
4
+ data.tar.gz: c09981f5be6f3329a1e8f92838de1836fea928ca2b5560aa7cff4bf94cdf4fec
5
5
  SHA512:
6
- metadata.gz: 890fa72b61e9703b7b009b600279ed27a3166594c02efc4277850545f5c904c7508f25f3f28407f1e56a739bc18a0c3fbe05a7ec255442cc88390b9dfd441eb6
7
- data.tar.gz: 63966c0d81e55939675d58a5013e2167b5c43e2edbb2372d6b1668b137515cb2e88d7eb42f7b9f2ac199dd182fc74e026cb2ed59209358ba7e07bd9e6b0cb79a
6
+ metadata.gz: 6760c72e6f547bd8bfe4aff3a1bbab7e71bc88130cd5f4ced49e27f71300fc5c69ea1d38076ba350af4c5647cb440b7fb247672c5f22f3e0aec2c8222876c271
7
+ data.tar.gz: 7d24e0cdce04ab2844a1950d83ee46b3f6116785865f6338bcfab13590476c4ef87654654357f29fade1bce31f5b15ca34b50d0e75a8391ef51308df2369e760
data/README.md CHANGED
@@ -72,6 +72,15 @@ session = Sveda::Client.start_host_session(
72
72
  )
73
73
  ```
74
74
 
75
+ ## Agent introspection
76
+
77
+ ```ruby
78
+ manifest = server.describe(current_user)
79
+ puts JSON.pretty_generate(manifest)
80
+ ```
81
+
82
+ In Rails apps that assign `config.x.sveda_host`, run `bin/rails sveda:tools` (optional `USER=email@example.com`). Playground apps also expose `GET /sveda/tools` when logged in.
83
+
75
84
  ## License
76
85
 
77
86
  GNU Affero General Public License v3.0. See [LICENSE](LICENSE).
@@ -60,20 +60,7 @@ module Sveda
60
60
  end
61
61
 
62
62
  def list_tools(user)
63
- @server.tools(user).map do |tool|
64
- meta = {
65
- domain: tool.domain,
66
- mode: tool.mode
67
- }
68
- meta[:confirmation] = "required" if tool.respond_to?(:confirmation) && tool.confirmation == "required"
69
- {
70
- name: tool.name,
71
- title: tool.name,
72
- description: tool.description,
73
- inputSchema: tool.input_schema,
74
- _meta: meta
75
- }
76
- end
63
+ @server.mcp_tools(user)
77
64
  end
78
65
 
79
66
  def call_tool(params, user)
@@ -26,6 +26,7 @@ module Sveda
26
26
  @policy_using = nil
27
27
  @tools = []
28
28
  @mint_token = ->(user = nil) { @token_store.mint(user_id: user_id_for(user)) }
29
+ @mint_token_custom = false
29
30
  @authenticate = ->(token) { @token_store.lookup(token) }
30
31
  @authorize = nil
31
32
  @after_authenticate = nil
@@ -46,6 +47,7 @@ module Sveda
46
47
 
47
48
  def mint_token_using(&block)
48
49
  @mint_token = block
50
+ @mint_token_custom = true
49
51
  end
50
52
 
51
53
  def authenticate_using(&block)
@@ -132,6 +134,48 @@ module Sveda
132
134
  McpRackHandler.new(self)
133
135
  end
134
136
 
137
+ def mcp_tools(user = nil)
138
+ tools(user).map do |tool|
139
+ meta = {
140
+ domain: tool.domain,
141
+ mode: tool.mode
142
+ }
143
+ meta[:confirmation] = "required" if tool.respond_to?(:confirmation) && tool.confirmation == "required"
144
+ entry = {
145
+ name: tool.name,
146
+ title: tool.name,
147
+ description: tool.description,
148
+ inputSchema: tool.input_schema,
149
+ _meta: meta
150
+ }
151
+ entry
152
+ end
153
+ end
154
+
155
+ def registered_hooks
156
+ {
157
+ resolve_tools: !@resolve_tools.nil?,
158
+ policy: !@policy_using.nil?,
159
+ authorize: !@authorize.nil?,
160
+ visitor_id: false,
161
+ mint_token: @mint_token_custom
162
+ }
163
+ end
164
+
165
+ def describe(user = nil)
166
+ authenticated = !user.nil?
167
+ {
168
+ schema: "sveda.host/v1",
169
+ sdk: { language: "ruby", version: Sveda::VERSION },
170
+ subject: {
171
+ authenticated: authenticated,
172
+ policy: authenticated ? policy_for(user) : nil
173
+ },
174
+ hooks: registered_hooks,
175
+ tools: mcp_tools(user)
176
+ }
177
+ end
178
+
135
179
  private
136
180
 
137
181
  def invoke_resolve_tools(user)
data/lib/sveda/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sveda
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.1"
5
5
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :sveda do
4
+ desc "Print the Sveda host tool manifest as JSON"
5
+ task tools: :environment do
6
+ host = Rails.application.config.x.sveda_host
7
+ unless host
8
+ warn "Sveda host is not configured (config.x.sveda_host)"
9
+ exit 1
10
+ end
11
+
12
+ user = ENV["USER"] || ENV["SVEDA_USER"]
13
+ subject = user ? host.describe(user) : host.describe
14
+ puts JSON.pretty_generate(subject)
15
+ end
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sveda-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neresson
@@ -52,6 +52,7 @@ files:
52
52
  - lib/sveda/stream_event.rb
53
53
  - lib/sveda/stream_parser.rb
54
54
  - lib/sveda/version.rb
55
+ - lib/tasks/sveda.rake
55
56
  homepage: https://sveda.dev/docs/hosts/ruby
56
57
  licenses:
57
58
  - AGPL-3.0-only