minds_sdk 1.0.1 → 1.1.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/CHANGELOG.md +4 -4
- data/lib/minds/client.rb +4 -2
- data/lib/minds/datasources.rb +3 -1
- data/lib/minds/errors.rb +4 -1
- data/lib/minds/minds.rb +5 -2
- data/lib/minds/rest_client.rb +9 -3
- data/lib/minds/validators.rb +57 -0
- data/lib/minds/version.rb +1 -1
- data/lib/minds.rb +3 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac43c5b8357b515c69241475ef036f61883fd8fc4a4e693dacf60f4fb046b284
|
4
|
+
data.tar.gz: bb9b63eaf02ab0dfb1333588771ae3f893191efe46c41f9956cf74575ba439b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 783c67217b99f88df67dadfa58eaccabaadfcce50460cdb2085701e51866a73580aae5d28a850a48fe3b2e65b1c5758a92bcd66aa655a3c8dafb3b1381586eef
|
7
|
+
data.tar.gz: 7ccb9a82511e2e57082d4c043796919c4755caedc23fa6b729d681f73b9a6027abd45a36e8c1160924387f066a84807a3a3a8663329814d01a123f6ff6cc1de7
|
data/CHANGELOG.md
CHANGED
@@ -5,22 +5,22 @@
|
|
5
5
|
### Added
|
6
6
|
- Initial release of the Minds Ruby SDK
|
7
7
|
- Implemented `Minds::Client` for configuring and initializing the SDK
|
8
|
-
- Added `Minds::
|
8
|
+
- Added `Minds::Datasources` for managing data sources:
|
9
9
|
- `create`: Create a new datasource
|
10
10
|
- `all`: List all datasources
|
11
11
|
- `find`: Get a datasource by name
|
12
12
|
- `destroy`: Delete a datasource
|
13
|
-
- Added `Minds::
|
13
|
+
- Added `Minds::Minds` for managing minds:
|
14
14
|
- `all`: List all minds
|
15
15
|
- `find`: Get a mind by name
|
16
16
|
- `create`: Create a new mind
|
17
17
|
- `destroy`: Delete a mind
|
18
|
-
- Implemented `Minds::
|
18
|
+
- Implemented `Minds::Mind` class with methods:
|
19
19
|
- `update`: Update mind properties
|
20
20
|
- `add_datasources`: Add a datasource to a mind
|
21
21
|
- `destroy_datasources`: Remove a datasource from a mind
|
22
22
|
- `completion`: Call mind completion (with streaming support)
|
23
|
-
- Added support for various datasource types through `DatabaseConfig` class
|
23
|
+
- Added support for various datasource types through `Minds::DatabaseConfig` class
|
24
24
|
- Implemented error handling with custom error classes
|
25
25
|
- Added YARD-style documentation for all public methods
|
26
26
|
|
data/lib/minds/client.rb
CHANGED
@@ -6,13 +6,15 @@ module Minds
|
|
6
6
|
|
7
7
|
SENSITIVE_ATTRIBUTES = %i[@base_url @api_key].freeze
|
8
8
|
CONFIG_KEYS = %i[base_url api_key log_errors api_version].freeze
|
9
|
-
attr_reader(*CONFIG_KEYS)
|
9
|
+
attr_reader(*CONFIG_KEYS, :faraday_middleware)
|
10
10
|
|
11
|
-
def initialize(options = {})
|
11
|
+
def initialize(options = {}, &faraday_middleware)
|
12
12
|
# if key not present. Fall back to global config
|
13
13
|
CONFIG_KEYS.each do |key|
|
14
14
|
instance_variable_set "@#{key}", options[key] || Client.config.send(key)
|
15
15
|
end
|
16
|
+
|
17
|
+
@faraday_middleware = faraday_middleware
|
16
18
|
end
|
17
19
|
|
18
20
|
class << self
|
data/lib/minds/datasources.rb
CHANGED
@@ -37,7 +37,7 @@ module Minds
|
|
37
37
|
# @option ds_config [String] :description Description of the database. Used by mind to understand what data can be retrieved from it.
|
38
38
|
# @option ds_config [Hash] :connection_data (optional) Credentials to connect to the database
|
39
39
|
# @option ds_config [Array<String>] :tables (optional) List of allowed tables
|
40
|
-
# @param update [Boolean] If true, to update
|
40
|
+
# @param update [Boolean] If true, to update datasource if exists, default is false
|
41
41
|
# @return [Datasource] The created datasource object
|
42
42
|
# @raise [ObjectNotSupported] If datasource type is not supported
|
43
43
|
#
|
@@ -57,6 +57,8 @@ module Minds
|
|
57
57
|
def create(ds_config, update = false)
|
58
58
|
name = ds_config.name
|
59
59
|
|
60
|
+
Validators.validate_datasource_name!(name)
|
61
|
+
|
60
62
|
path = "datasources"
|
61
63
|
path += "/#{name}" if update
|
62
64
|
|
data/lib/minds/errors.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minds
|
2
4
|
class Error < StandardError; end
|
3
|
-
class ValidationError < Error; end
|
4
5
|
class ObjectNotFound < Error; end
|
5
6
|
class ObjectNotSupported < Error; end
|
7
|
+
class MindNameInvalid < Error; end
|
8
|
+
class DatasourceNameInvalid < Error; end
|
6
9
|
end
|
data/lib/minds/minds.rb
CHANGED
@@ -5,7 +5,7 @@ require "uri"
|
|
5
5
|
|
6
6
|
module Minds
|
7
7
|
DEFAULT_PROMPT_TEMPLATE = "Use your database tools to answer the user's question: {{question}}"
|
8
|
-
|
8
|
+
DEFAULT_MODEL = "gpt-4o"
|
9
9
|
class Mind
|
10
10
|
attr_reader :name, :model_name, :provider, :parameters, :created_at, :updated_at, :datasources, :prompt_template
|
11
11
|
|
@@ -36,6 +36,7 @@ module Minds
|
|
36
36
|
# @param parameters [Hash, nil] Alter other parameters of the mind (optional)
|
37
37
|
# @return [void]
|
38
38
|
def update(name: nil, model_name: nil, provider: nil, prompt_template: nil, datasources: nil, parameters: nil)
|
39
|
+
Validators.validate_mind_name!(name) if !name.nil?
|
39
40
|
data = {}
|
40
41
|
ds_names = []
|
41
42
|
datasources.each do |ds|
|
@@ -210,6 +211,8 @@ module Minds
|
|
210
211
|
# )
|
211
212
|
#
|
212
213
|
def create(name:, model_name: nil, provider: nil, prompt_template: nil, datasources: nil, parameters: nil, replace: false, update: false)
|
214
|
+
Validators.validate_mind_name!(name) if !name.nil?
|
215
|
+
|
213
216
|
if replace
|
214
217
|
find(name)
|
215
218
|
destroy(name)
|
@@ -227,7 +230,7 @@ module Minds
|
|
227
230
|
parameters["prompt_template"] ||= DEFAULT_PROMPT_TEMPLATE
|
228
231
|
data = {
|
229
232
|
name: name,
|
230
|
-
model_name: model_name,
|
233
|
+
model_name: model_name || DEFAULT_MODEL,
|
231
234
|
provider: provider,
|
232
235
|
parameters: parameters,
|
233
236
|
datasources: ds_names
|
data/lib/minds/rest_client.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "uri"
|
4
|
+
|
3
5
|
module Minds
|
4
6
|
module RestClient
|
5
7
|
def get(path:)
|
@@ -26,20 +28,21 @@ module Minds
|
|
26
28
|
|
27
29
|
def delete(path:, parameters: nil)
|
28
30
|
conn.delete(uri(path: path)) do |req|
|
29
|
-
req.body = parameters.to_json
|
31
|
+
req.body = parameters.to_json unless parameters.nil?
|
30
32
|
end&.body
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
34
36
|
|
35
37
|
def uri(path:)
|
36
|
-
|
38
|
+
base_path = URI(@base_url).path
|
39
|
+
return path if base_path.split("/").include?(@api_version)
|
37
40
|
|
38
41
|
"/#{@api_version}/#{path}"
|
39
42
|
end
|
40
43
|
|
41
44
|
def conn
|
42
|
-
Faraday.new(url: @base_url) do |builder|
|
45
|
+
connection = Faraday.new(url: @base_url) do |builder|
|
43
46
|
builder.use MiddlewareErrors if @log_errors
|
44
47
|
builder.headers["Authorization"] = "Bearer #{@api_key}"
|
45
48
|
builder.headers["Content-Type"] = "application/json"
|
@@ -47,6 +50,9 @@ module Minds
|
|
47
50
|
builder.response :json
|
48
51
|
builder.response :raise_error
|
49
52
|
end
|
53
|
+
|
54
|
+
@faraday_middleware&.call(connection)
|
55
|
+
connection
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minds
|
4
|
+
module Validators
|
5
|
+
class << self
|
6
|
+
# Validates a mind name according to naming rules
|
7
|
+
#
|
8
|
+
# @param name [String] The mind name to validate
|
9
|
+
# @return [Boolean] Returns true if valid
|
10
|
+
# @raise [MindNameInvalid] If the mind name is invalid
|
11
|
+
#
|
12
|
+
# @example Valid mind names
|
13
|
+
# validate_mind_name!("my_mind_1") # => true
|
14
|
+
#
|
15
|
+
# @example Invalid mind names
|
16
|
+
# validate_mind_name!("123_mind") # raises MindNameInvalid
|
17
|
+
# validate_mind_name!("my mind") # raises MindNameInvalid
|
18
|
+
# validate_mind_name!("very_very_long_mind_name_over_32_chars") # raises MindNameInvalid
|
19
|
+
#
|
20
|
+
# @note Mind name rules:
|
21
|
+
# - Must start with a letter
|
22
|
+
# - Can contain only letters, numbers, or underscores
|
23
|
+
# - Maximum length of 32 characters
|
24
|
+
# - Cannot contain spaces
|
25
|
+
def validate_mind_name!(name)
|
26
|
+
unless name.match?(/\A[a-zA-Z][a-zA-Z0-9_]{0,31}\z/)
|
27
|
+
raise MindNameInvalid, "Mind name '#{name}' is invalid. It must start with a letter, contain only letters, numbers, or underscores, and be 32 characters or less."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Validates a datasource name according to naming rules
|
32
|
+
#
|
33
|
+
# @param name [String] The datasource name to validate
|
34
|
+
# @return [Boolean] Returns true if valid
|
35
|
+
# @raise [DatasourceNameInvalid] If the datasource name is invalid
|
36
|
+
#
|
37
|
+
# @example Valid datasource names
|
38
|
+
# validate_datasource_name!("my_database") # => true
|
39
|
+
#
|
40
|
+
# @example Invalid datasource names
|
41
|
+
# validate_datasource_name!("123_db") # raises DatasourceNameInvalid
|
42
|
+
# validate_datasource_name!("my database") # raises DatasourceNameInvalid
|
43
|
+
# validate_datasource_name!("very_very_long_database_name_over_62_characters_not_allowed") # raises DatasourceNameInvalid
|
44
|
+
#
|
45
|
+
# @note Datasource name rules:
|
46
|
+
# - Must start with a letter
|
47
|
+
# - Can contain only letters, numbers, or underscores
|
48
|
+
# - Maximum length of 62 characters
|
49
|
+
# - Cannot contain spaces
|
50
|
+
def validate_datasource_name!(name)
|
51
|
+
unless name.match?(/\A[a-zA-Z][a-zA-Z0-9_]{0,61}\z/)
|
52
|
+
raise DatasourceNameInvalid, "Datasource name '#{name}' is invalid. It must start with a letter, contain only letters, numbers, or underscores, and be 62 characters or less."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/minds/version.rb
CHANGED
data/lib/minds.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative "minds/errors"
|
|
9
9
|
require_relative "minds/config/base"
|
10
10
|
require_relative "minds/datasources"
|
11
11
|
require_relative "minds/minds"
|
12
|
+
require_relative "minds/validators"
|
12
13
|
|
13
14
|
module Minds
|
14
15
|
class MiddlewareErrors < Faraday::Middleware
|
@@ -30,10 +31,10 @@ module Minds
|
|
30
31
|
error_suffix = "\033[0m"
|
31
32
|
|
32
33
|
formatted_message = msg.split("\n").map do |line|
|
33
|
-
"#{' ' *
|
34
|
+
"#{' ' * 14}#{line}"
|
34
35
|
end.join("\n")
|
35
36
|
|
36
|
-
"#{error_prefix}
|
37
|
+
"#{error_prefix} Minds Client Error\n#{formatted_message}#{error_suffix}\n"
|
37
38
|
end
|
38
39
|
|
39
40
|
logger.error(e.response[:body])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minds_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tungnt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/minds/errors.rb
|
66
66
|
- lib/minds/minds.rb
|
67
67
|
- lib/minds/rest_client.rb
|
68
|
+
- lib/minds/validators.rb
|
68
69
|
- lib/minds/version.rb
|
69
70
|
- sig/minds.rbs
|
70
71
|
homepage: https://github.com/tungnt1203/minds_ruby_sdk
|
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
- !ruby/object:Gem::Version
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
94
|
+
rubygems_version: 3.4.1
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: Minds Ruby SDK provides an interface to interact with the Minds AI system
|