swarm_sdk 2.4.3 → 2.4.4
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/lib/swarm_sdk/config.rb +2 -1
- data/lib/swarm_sdk/configuration/parser.rb +22 -2
- data/lib/swarm_sdk/configuration.rb +13 -4
- data/lib/swarm_sdk/version.rb +1 -1
- data/lib/swarm_sdk.rb +20 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2357a0a9317288666f8e26f001e2d3b42402870d0e7e03560b6ff14109b36f56
|
|
4
|
+
data.tar.gz: 0c11addc8f0578cfd796cda4795dfb51f2f4b134280eab2601e600b0b90670c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '029817745549dfcd04234c2b4e9f809e139fc222cf717f366d09c5cca6d7b7e2ae50a6f2c52058380a2a1e860e86526618ca06de464589f1d10eb21bebe1bb04'
|
|
7
|
+
data.tar.gz: 2455fab120ec48edeb80adfa0bfa5ede016f09a49eb4ab2dc2e48490432d4b282255999f5540cb494267d4fe46c8d2f72e94ea7fcc37059db58f533ebd0bd834
|
data/lib/swarm_sdk/config.rb
CHANGED
|
@@ -91,6 +91,7 @@ module SwarmSDK
|
|
|
91
91
|
webfetch_base_url: ["SWARM_SDK_WEBFETCH_BASE_URL", nil],
|
|
92
92
|
webfetch_max_tokens: ["SWARM_SDK_WEBFETCH_MAX_TOKENS", 4096],
|
|
93
93
|
allow_filesystem_tools: ["SWARM_SDK_ALLOW_FILESYSTEM_TOOLS", true],
|
|
94
|
+
env_interpolation: ["SWARM_SDK_ENV_INTERPOLATION", true],
|
|
94
95
|
}.freeze
|
|
95
96
|
|
|
96
97
|
class << self
|
|
@@ -279,7 +280,7 @@ module SwarmSDK
|
|
|
279
280
|
# @return [Integer, Float, Boolean, String] The parsed value
|
|
280
281
|
def parse_env_value(value, key)
|
|
281
282
|
case key
|
|
282
|
-
when :allow_filesystem_tools
|
|
283
|
+
when :allow_filesystem_tools, :env_interpolation
|
|
283
284
|
# Convert string to boolean
|
|
284
285
|
case value.to_s.downcase
|
|
285
286
|
when "true", "yes", "1", "on", "enabled"
|
|
@@ -30,9 +30,18 @@ module SwarmSDK
|
|
|
30
30
|
:nodes,
|
|
31
31
|
:external_swarms
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
# Initialize parser with YAML content and options
|
|
34
|
+
#
|
|
35
|
+
# @param yaml_content [String] YAML configuration content
|
|
36
|
+
# @param base_dir [String, Pathname] Base directory for resolving paths
|
|
37
|
+
# @param env_interpolation [Boolean, nil] Whether to interpolate environment variables.
|
|
38
|
+
# When nil, uses the global SwarmSDK.config.env_interpolation setting.
|
|
39
|
+
# When true, interpolates ${VAR} and ${VAR:=default} patterns.
|
|
40
|
+
# When false, skips interpolation entirely.
|
|
41
|
+
def initialize(yaml_content, base_dir:, env_interpolation: nil)
|
|
34
42
|
@yaml_content = yaml_content
|
|
35
43
|
@base_dir = Pathname.new(base_dir).expand_path
|
|
44
|
+
@env_interpolation = env_interpolation
|
|
36
45
|
@config_type = nil
|
|
37
46
|
@swarm_id = nil
|
|
38
47
|
@swarm_name = nil
|
|
@@ -55,7 +64,7 @@ module SwarmSDK
|
|
|
55
64
|
end
|
|
56
65
|
|
|
57
66
|
@config = Utils.symbolize_keys(@config)
|
|
58
|
-
interpolate_env_vars!(@config)
|
|
67
|
+
interpolate_env_vars!(@config) if env_interpolation_enabled?
|
|
59
68
|
|
|
60
69
|
validate_version
|
|
61
70
|
detect_and_validate_type
|
|
@@ -86,6 +95,17 @@ module SwarmSDK
|
|
|
86
95
|
|
|
87
96
|
private
|
|
88
97
|
|
|
98
|
+
# Check if environment variable interpolation is enabled
|
|
99
|
+
#
|
|
100
|
+
# Uses the local setting if explicitly set, otherwise falls back to global config.
|
|
101
|
+
#
|
|
102
|
+
# @return [Boolean] true if interpolation should be performed
|
|
103
|
+
def env_interpolation_enabled?
|
|
104
|
+
return @env_interpolation unless @env_interpolation.nil?
|
|
105
|
+
|
|
106
|
+
SwarmSDK.config.env_interpolation
|
|
107
|
+
end
|
|
108
|
+
|
|
89
109
|
def validate_version
|
|
90
110
|
version = @config[:version]
|
|
91
111
|
raise ConfigurationError, "Missing 'version' field in configuration" unless version
|
|
@@ -38,9 +38,13 @@ module SwarmSDK
|
|
|
38
38
|
# Load configuration from YAML file
|
|
39
39
|
#
|
|
40
40
|
# @param path [String, Pathname] Path to YAML configuration file
|
|
41
|
+
# @param env_interpolation [Boolean, nil] Whether to interpolate environment variables.
|
|
42
|
+
# When nil, uses the global SwarmSDK.config.env_interpolation setting.
|
|
43
|
+
# When true, interpolates ${VAR} and ${VAR:=default} patterns.
|
|
44
|
+
# When false, skips interpolation entirely.
|
|
41
45
|
# @return [Configuration] Validated configuration instance
|
|
42
46
|
# @raise [ConfigurationError] If file not found or invalid
|
|
43
|
-
def load_file(path)
|
|
47
|
+
def load_file(path, env_interpolation: nil)
|
|
44
48
|
path = Pathname.new(path).expand_path
|
|
45
49
|
|
|
46
50
|
unless path.exist?
|
|
@@ -50,7 +54,7 @@ module SwarmSDK
|
|
|
50
54
|
yaml_content = File.read(path)
|
|
51
55
|
base_dir = path.dirname
|
|
52
56
|
|
|
53
|
-
new(yaml_content, base_dir: base_dir).tap(&:load_and_validate)
|
|
57
|
+
new(yaml_content, base_dir: base_dir, env_interpolation: env_interpolation).tap(&:load_and_validate)
|
|
54
58
|
rescue Errno::ENOENT
|
|
55
59
|
raise ConfigurationError, "Configuration file not found: #{path}"
|
|
56
60
|
end
|
|
@@ -60,12 +64,17 @@ module SwarmSDK
|
|
|
60
64
|
#
|
|
61
65
|
# @param yaml_content [String] YAML configuration content
|
|
62
66
|
# @param base_dir [String, Pathname] Base directory for resolving agent file paths (default: Dir.pwd)
|
|
63
|
-
|
|
67
|
+
# @param env_interpolation [Boolean, nil] Whether to interpolate environment variables.
|
|
68
|
+
# When nil, uses the global SwarmSDK.config.env_interpolation setting.
|
|
69
|
+
# When true, interpolates ${VAR} and ${VAR:=default} patterns.
|
|
70
|
+
# When false, skips interpolation entirely.
|
|
71
|
+
def initialize(yaml_content, base_dir: Dir.pwd, env_interpolation: nil)
|
|
64
72
|
raise ArgumentError, "yaml_content cannot be nil" if yaml_content.nil?
|
|
65
73
|
raise ArgumentError, "base_dir cannot be nil" if base_dir.nil?
|
|
66
74
|
|
|
67
75
|
@yaml_content = yaml_content
|
|
68
76
|
@base_dir = Pathname.new(base_dir).expand_path
|
|
77
|
+
@env_interpolation = env_interpolation
|
|
69
78
|
@parser = nil
|
|
70
79
|
@translator = nil
|
|
71
80
|
end
|
|
@@ -77,7 +86,7 @@ module SwarmSDK
|
|
|
77
86
|
#
|
|
78
87
|
# @return [self]
|
|
79
88
|
def load_and_validate
|
|
80
|
-
@parser = Parser.new(@yaml_content, base_dir: @base_dir)
|
|
89
|
+
@parser = Parser.new(@yaml_content, base_dir: @base_dir, env_interpolation: @env_interpolation)
|
|
81
90
|
@parser.parse
|
|
82
91
|
|
|
83
92
|
# Sync parsed data to instance variables for backward compatibility
|
data/lib/swarm_sdk/version.rb
CHANGED
data/lib/swarm_sdk.rb
CHANGED
|
@@ -275,6 +275,11 @@ module SwarmSDK
|
|
|
275
275
|
#
|
|
276
276
|
# @param yaml_content [String] YAML configuration content
|
|
277
277
|
# @param base_dir [String, Pathname] Base directory for resolving agent file paths (default: Dir.pwd)
|
|
278
|
+
# @param allow_filesystem_tools [Boolean, nil] Whether to allow filesystem tools (nil uses global setting)
|
|
279
|
+
# @param env_interpolation [Boolean, nil] Whether to interpolate environment variables.
|
|
280
|
+
# When nil, uses the global SwarmSDK.config.env_interpolation setting.
|
|
281
|
+
# When true, interpolates ${VAR} and ${VAR:=default} patterns.
|
|
282
|
+
# When false, skips interpolation entirely.
|
|
278
283
|
# @return [Swarm, Workflow] Configured swarm or workflow instance
|
|
279
284
|
# @raise [ConfigurationError] If YAML is invalid or configuration is incorrect
|
|
280
285
|
#
|
|
@@ -297,8 +302,11 @@ module SwarmSDK
|
|
|
297
302
|
# @example Load with default base_dir (Dir.pwd)
|
|
298
303
|
# yaml = File.read("config.yml")
|
|
299
304
|
# swarm = SwarmSDK.load(yaml) # base_dir defaults to Dir.pwd
|
|
300
|
-
|
|
301
|
-
|
|
305
|
+
#
|
|
306
|
+
# @example Load without environment variable interpolation
|
|
307
|
+
# swarm = SwarmSDK.load(yaml, env_interpolation: false)
|
|
308
|
+
def load(yaml_content, base_dir: Dir.pwd, allow_filesystem_tools: nil, env_interpolation: nil)
|
|
309
|
+
config = Configuration.new(yaml_content, base_dir: base_dir, env_interpolation: env_interpolation)
|
|
302
310
|
config.load_and_validate
|
|
303
311
|
swarm = config.to_swarm(allow_filesystem_tools: allow_filesystem_tools)
|
|
304
312
|
|
|
@@ -320,6 +328,11 @@ module SwarmSDK
|
|
|
320
328
|
# loading swarms from configuration files.
|
|
321
329
|
#
|
|
322
330
|
# @param path [String, Pathname] Path to YAML configuration file
|
|
331
|
+
# @param allow_filesystem_tools [Boolean, nil] Whether to allow filesystem tools (nil uses global setting)
|
|
332
|
+
# @param env_interpolation [Boolean, nil] Whether to interpolate environment variables.
|
|
333
|
+
# When nil, uses the global SwarmSDK.config.env_interpolation setting.
|
|
334
|
+
# When true, interpolates ${VAR} and ${VAR:=default} patterns.
|
|
335
|
+
# When false, skips interpolation entirely.
|
|
323
336
|
# @return [Swarm, Workflow] Configured swarm or workflow instance
|
|
324
337
|
# @raise [ConfigurationError] If file not found or configuration invalid
|
|
325
338
|
#
|
|
@@ -329,8 +342,11 @@ module SwarmSDK
|
|
|
329
342
|
#
|
|
330
343
|
# @example With absolute path
|
|
331
344
|
# swarm = SwarmSDK.load_file("/absolute/path/config.yml")
|
|
332
|
-
|
|
333
|
-
|
|
345
|
+
#
|
|
346
|
+
# @example Load without environment variable interpolation
|
|
347
|
+
# swarm = SwarmSDK.load_file("config.yml", env_interpolation: false)
|
|
348
|
+
def load_file(path, allow_filesystem_tools: nil, env_interpolation: nil)
|
|
349
|
+
config = Configuration.load_file(path, env_interpolation: env_interpolation)
|
|
334
350
|
swarm = config.to_swarm(allow_filesystem_tools: allow_filesystem_tools)
|
|
335
351
|
|
|
336
352
|
# Apply hooks if any are configured (YAML-only feature)
|