swarm_sdk 2.7.5 → 2.7.6
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5806264bb99cea0a71727c89c5839ff3027c17cd725e4261244e14ae9079f513
|
|
4
|
+
data.tar.gz: f3d489dd1d6045dec6b97b499b2d6e27d78440d1b2289a19c2f3bedb27440c8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a37edf046435540ba32aa47b5552ef48e1c599c69a0bf0540ccfa2199a01947006ffe98eb8df1848175e11b673bebbf787156815dc4e5ea9403ab0db984997bd
|
|
7
|
+
data.tar.gz: 2ca616d67f41b19fe596d86fdd36aa6255cb314480c34253aacb7d8276196fd2e2bbd4fb3057b42faec5b000474754df7cce56cddbeb26fcc3301e6fa2a89fcb
|
|
@@ -45,17 +45,23 @@ module SwarmSDK
|
|
|
45
45
|
Swarm.apply_mcp_logging_configuration
|
|
46
46
|
|
|
47
47
|
mcp_server_configs.each do |server_config|
|
|
48
|
+
tools_config = server_config[:tools]
|
|
49
|
+
mode = tools_config.nil? ? :discovery : :optimized
|
|
50
|
+
|
|
51
|
+
# Emit event before initialization
|
|
52
|
+
emit_mcp_init_start(agent_name, server_config, mode)
|
|
53
|
+
|
|
48
54
|
client = initialize_mcp_client(server_config)
|
|
49
55
|
|
|
50
56
|
# Store client for cleanup
|
|
51
57
|
@mcp_clients[agent_name] << client
|
|
52
58
|
|
|
53
|
-
tools_config = server_config[:tools]
|
|
54
|
-
|
|
55
59
|
if tools_config.nil?
|
|
56
60
|
# Discovery mode: Fetch all tools from server (calls tools/list)
|
|
57
61
|
# client.tools returns RubyLLM::Tool instances (already wrapped by internal Coordinator)
|
|
58
62
|
all_tools = client.tools
|
|
63
|
+
tool_names = all_tools.map { |t| t.respond_to?(:name) ? t.name : t.to_s }
|
|
64
|
+
|
|
59
65
|
all_tools.each do |tool|
|
|
60
66
|
chat.tool_registry.register(
|
|
61
67
|
tool,
|
|
@@ -63,10 +69,15 @@ module SwarmSDK
|
|
|
63
69
|
metadata: { server_name: server_config[:name] },
|
|
64
70
|
)
|
|
65
71
|
end
|
|
72
|
+
|
|
73
|
+
# Emit completion event for discovery mode
|
|
74
|
+
emit_mcp_init_complete(agent_name, server_config, mode, all_tools.size, tool_names)
|
|
66
75
|
RubyLLM.logger.debug("SwarmSDK: Discovered and registered #{all_tools.size} tools from MCP server '#{server_config[:name]}'")
|
|
67
76
|
else
|
|
68
77
|
# Optimized mode: Create tool stubs without tools/list RPC (Plan 025)
|
|
69
78
|
# Use client directly (it has internal coordinator)
|
|
79
|
+
tool_names = tools_config.map(&:to_s)
|
|
80
|
+
|
|
70
81
|
tools_config.each do |tool_name|
|
|
71
82
|
stub = Tools::McpToolStub.new(
|
|
72
83
|
client: client,
|
|
@@ -78,6 +89,9 @@ module SwarmSDK
|
|
|
78
89
|
metadata: { server_name: server_config[:name] },
|
|
79
90
|
)
|
|
80
91
|
end
|
|
92
|
+
|
|
93
|
+
# Emit completion event for optimized mode
|
|
94
|
+
emit_mcp_init_complete(agent_name, server_config, mode, tools_config.size, tool_names)
|
|
81
95
|
RubyLLM.logger.debug("SwarmSDK: Registered #{tools_config.size} tool stubs from MCP server '#{server_config[:name]}' (lazy schema)")
|
|
82
96
|
end
|
|
83
97
|
rescue StandardError => e
|
|
@@ -187,6 +201,42 @@ module SwarmSDK
|
|
|
187
201
|
|
|
188
202
|
streamable_config
|
|
189
203
|
end
|
|
204
|
+
|
|
205
|
+
# Emit MCP server initialization start event
|
|
206
|
+
#
|
|
207
|
+
# @param agent_name [Symbol] Agent name
|
|
208
|
+
# @param server_config [Hash] MCP server configuration
|
|
209
|
+
# @param mode [Symbol] Initialization mode (:discovery or :optimized)
|
|
210
|
+
# @return [void]
|
|
211
|
+
def emit_mcp_init_start(agent_name, server_config, mode)
|
|
212
|
+
LogStream.emit(
|
|
213
|
+
type: "mcp_server_init_start",
|
|
214
|
+
agent: agent_name,
|
|
215
|
+
server_name: server_config[:name],
|
|
216
|
+
transport_type: server_config[:type],
|
|
217
|
+
mode: mode,
|
|
218
|
+
)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Emit MCP server initialization complete event
|
|
222
|
+
#
|
|
223
|
+
# @param agent_name [Symbol] Agent name
|
|
224
|
+
# @param server_config [Hash] MCP server configuration
|
|
225
|
+
# @param mode [Symbol] Initialization mode (:discovery or :optimized)
|
|
226
|
+
# @param tool_count [Integer] Number of tools registered
|
|
227
|
+
# @param tool_names [Array<String>] Names of registered tools
|
|
228
|
+
# @return [void]
|
|
229
|
+
def emit_mcp_init_complete(agent_name, server_config, mode, tool_count, tool_names)
|
|
230
|
+
LogStream.emit(
|
|
231
|
+
type: "mcp_server_init_complete",
|
|
232
|
+
agent: agent_name,
|
|
233
|
+
server_name: server_config[:name],
|
|
234
|
+
transport_type: server_config[:type],
|
|
235
|
+
mode: mode,
|
|
236
|
+
tool_count: tool_count,
|
|
237
|
+
tools: tool_names,
|
|
238
|
+
)
|
|
239
|
+
end
|
|
190
240
|
end
|
|
191
241
|
end
|
|
192
242
|
end
|
|
@@ -4,8 +4,10 @@ module SwarmSDK
|
|
|
4
4
|
module Tools
|
|
5
5
|
module ImageExtractors
|
|
6
6
|
# Extracts images from PDF documents
|
|
7
|
-
#
|
|
8
|
-
#
|
|
7
|
+
# Only extracts JPEG images (DCTDecode format) which are LLM API compatible
|
|
8
|
+
# Non-JPEG images (FlateDecode, LZWDecode) are skipped because they would
|
|
9
|
+
# require TIFF format which is not supported by LLM APIs
|
|
10
|
+
# Supported LLM image formats: ['png', 'jpeg', 'gif', 'webp']
|
|
9
11
|
class PdfImageExtractor
|
|
10
12
|
class << self
|
|
11
13
|
# Extract all images from a PDF document
|
|
@@ -65,11 +67,13 @@ module SwarmSDK
|
|
|
65
67
|
|
|
66
68
|
case filter
|
|
67
69
|
when :DCTDecode
|
|
68
|
-
# JPEG images can be saved directly
|
|
70
|
+
# JPEG images can be saved directly - LLM API compatible
|
|
69
71
|
save_jpeg(stream, page_number, name, temp_dir)
|
|
70
72
|
when :FlateDecode, :LZWDecode, nil
|
|
71
|
-
#
|
|
72
|
-
|
|
73
|
+
# Skip non-JPEG images to avoid TIFF format (not supported by LLM APIs)
|
|
74
|
+
# LLM APIs only support: ['png', 'jpeg', 'gif', 'webp']
|
|
75
|
+
# These images would require TIFF conversion which causes API errors
|
|
76
|
+
nil
|
|
73
77
|
end
|
|
74
78
|
# Unsupported formats return nil
|
|
75
79
|
rescue StandardError
|
data/lib/swarm_sdk/version.rb
CHANGED